Quote-anchored knowledge base workflow

Turns a book into a knowledge base in which every claim traces back to a line of the original.

#knowledge base#verbatim quotes#parallel agents#low-cost models#quality gate
Quote-anchored knowledge base builder

WorkflowQuote-anchored knowledge base builder

Knowledge bases Claude Code (skills + agents)

A procedure for turning books and documents into a knowledge base Claude can answer from by quoting the source verbatim. Tools and scripts cut the text without changing a character; models only write explanations with pointers to the original lines, and every pointer is checked by machine.

Challenge

  • Ask an AI about a book and you get plausible wording and numbers that are not in it, with no way to tell what to trust
  • Summarising a book chapter by chapter costs time and money, and nobody notices when a summary drifts from the source

Approach

  • An extraction tool and a chapter-splitting script cut the text verbatim, and an automatic check confirms that the pieces join back into the original
  • One low-cost card-writer agent per chapter runs in parallel, and every claim on a card must carry a quoted line from the source as its anchor

Outcome

  • Only cards whose anchors appear verbatim, and exactly once, in the source get through, so every answer can be checked against the original
  • The finished knowledge base is registered as an MCP server and can also be consulted through an expert agent for that book

The author keeps the books and course material they read in a form Claude can be asked about later. Summaries alone cannot show whether the book really said that, so an open-source knowledge-base tool is used to keep a quoted line from the source behind every point.

What this page shows is the build procedure the author wrapped around that tool. Books with a text layer go through extraction, chapter splitting, card writing, two checks and registration. Scanned paper is first read by several OCR engines, compared, and confirmed by a person before joining the same flow.

The full workflow

TaskWhoInputsOutputs
1. Extract textKB tool CLIKB CLIBookWhole text
2. List chaptersMain sessionWhole textChapter list
3. Split verbatimSplit script + KB tool CLIsplit script + KB CLIWhole text, Refers to Chapter listChapter texts
4. Write cardsCard writersHaiku subagentChapter texts, Refers to Card specCard drafts
5. Check anchorsAnchor checkercheck_cards.pyCard draftsAnchor check
6. Strict checkCard loader + KB tool CLIwrite_card.py + KB CLIAnchor checkStrict check
7. RegisterRegister script + Smoke testregister.py + smoke_mcp.pyStrict checkKB MCP server
8. Expert agentAgent generatorgen_agent.pyKB MCP serverExpert agent
Quote-anchored knowledge base builder

8 steps · 1 role · 7 tools · 2 loops · 29 knowledge bases registered

Tools and scripts cut the text verbatim, cheap models write only anchored cards, and only what passes two machine gates is registered.

  • Steps 1–3 prepare the source: extract → chapter list → verbatim split. Up to here no model writes a character of the text
  • Step 4 is the only model work: one agent per chapter, six to eight low-cost agents in parallel
  • Steps 5–6 are machine gates: each anchor is matched, then the whole knowledge base is checked strictly
  • Steps 7–8 register it as an MCP server and finish with an expert agent for that book
  • No person appears above the steps: once asked, Claude Code and the skill carry it through to the end

Project folders involved (5)

This workflow does not live in one folder: it runs across projects.

~/.claude/skills (build skill + 11 scripts)
The procedure and the scripts for splitting, checking, loading, registering, testing and generating
~/.claude/agents (card writer)
The card-writer agent: a low-cost model with a narrow set of tools
(private) reading-notes folder
The first knowledge base (three books in one) and the evaluation comparing cheap-model and top-model cards
(private) project folders
Each knowledge base lives in the project that uses it, together with its expert agent
~/.claude.json + KB registry
Where it is registered, so any project folder can query it through the MCP or the command line
Extract text

Step 1 · KB tool CLI

Extract textingest

Turn the whole book into text.

  • Input is a book with a text layer: EPUB, PDF with text, md or txt
  • Each extraction leaves one provenance line (source fingerprint, word count), so the origin can always be traced
  • Scans without a text layer do not enter here; a separate flow reads them with several OCR engines

Claude CodeAn open-source knowledge-base tool handles the text; Claude Code only runs the command

InputsBook
OutputsWhole text
List chapters

Step 2 · Main session

List chaptersscan + manifest

Write down the line where each chapter starts.

  • A script lists lines that look like chapter headings, and Claude Code picks the real ones for the list
  • Chapter names also appear once in the table of contents, so the second occurrence, in the body, is used
  • Front and back matter become sections too, so every line of the book lands in some piece

Common misconceptionCount line numbers in the extracted file: extraction drops repeated short lines, so the original manuscript no longer matches

InputsWhole text
OutputsChapter list
Split verbatim

Step 3 · Split script + KB tool CLI

Split verbatimsplit --apply

Cut verbatim by the list, and prove the pieces rejoin into the original.

  • A dry run shows the cut first; the real cut follows only after checking it
  • An automatic check confirms that the N pieces joined together equal the whole original text
  • Each chapter gets an empty card skeleton and an index entry, so cards equal chapters in number
InputsWhole text
OutputsChapter texts
Refers toChapter list
Write cards

Step 4 · Card writers

Write cardsper chapter

Send one low-cost writer per chapter, in parallel.

  • A writer reads the chapter and writes explanations, aliases, a summary and a source anchor for every claim
  • The default is a low-cost model; only very dense textbooks get a mid-tier model
  • The first knowledge base, three books in one, ended with 49 cards and 1,176 anchors

Claude CodeEach writer is a subagent limited to reading, writing and the check script

Common misconceptionCheap does not mean worse: on the same books, a retrieval test scored these cards the same as cards written by a top model

InputsChapter texts
OutputsCard drafts
Refers toCard spec
Check anchors

Step 5 · Anchor checker

Check anchorscheck_cards

Machine-check that each anchor appears verbatim, and only once, in the source.

  • An anchor must be at least 15 characters, appear verbatim and appear only once
  • Quote marks and dashes are first normalised automatically to the forms used in the source
  • A failing card goes back with the problem quoted, and only that chapter is rewritten
InputsCard drafts
OutputsAnchor check
Strict check

Step 6 · Card loader + KB tool CLI

Strict checkcheck --strict

Load the cards and check the whole knowledge base down to zero errors and zero warnings.

  • There are two checks, on the card drafts and on the loaded knowledge base, always in that order
  • If a source file changes, a staleness warning appears, so fingerprints are re-stamped before passing
  • Nothing moves on to registration until it shows zero errors and zero warnings
InputsAnchor check
OutputsStrict check
Register

Step 7 · Register script + Smoke test

RegisterMCP + smoke

Register it as an MCP server and test that real quotes come back.

  • It is registered both in the knowledge-base registry and in Claude Code's settings, so any folder can use it
  • The smoke test has five checks, ending with a real line from the source being verified as found
  • No expert agent is made until the smoke test passes
InputsStrict check
OutputsKB MCP server
Expert agent

Step 8 · Agent generator

Expert agentgen_agent

Create an expert agent for the book.

  • The agent answers by querying the knowledge base and quoting only verified source lines
  • After generation, Claude Code adds three or four example questions
  • The new agent becomes available the next time Claude Code starts
InputsKB MCP server
OutputsExpert agent

Loops and rework

  • Anchor check fails → step 4: The writer for that card is sent again with the problem quoted; the usual cause is an anchor that crosses a line break in the source
  • Strict check warns → step 4: For example a phrase that occurs more than once in a chapter; the card is fixed and both checks run again

Key points

Never let the model write the source. Extracting and splitting the text is the job of tools and scripts; the model does not touch a single character. It writes only the explanations and the pointers saying which line of the source supports each point.

Cheap models in parallel, checks by machine. Cards are written one agent per chapter, six to eight low-cost agents at a time. Each anchor must be at least 15 characters, appear verbatim in the source and appear only once; a card that fails is rewritten for that chapter only.

Register only what passes both gates. Beyond the card check, a strict check of the whole knowledge base must report zero errors and zero warnings before it is registered as an MCP server, and a smoke test then confirms that real quotes come back.