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
| Task | Who | Inputs | Outputs |
|---|---|---|---|
| 1. Extract text | KB tool CLIKB CLI | Book | Whole text |
| 2. List chapters | Main session | Whole text | Chapter list |
| 3. Split verbatim | Split script + KB tool CLIsplit script + KB CLI | Whole text, Refers to Chapter list | Chapter texts |
| 4. Write cards | Card writersHaiku subagent | Chapter texts, Refers to Card spec | Card drafts |
| 5. Check anchors | Anchor checkercheck_cards.py | Card drafts | Anchor check |
| 6. Strict check | Card loader + KB tool CLIwrite_card.py + KB CLI | Anchor check | Strict check |
| 7. Register | Register script + Smoke testregister.py + smoke_mcp.py | Strict check | KB MCP server |
| 8. Expert agent | Agent generatorgen_agent.py | KB MCP server | Expert agent |
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
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
| Inputs | Book |
| Outputs | Whole text |
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
| Inputs | Whole text |
| Outputs | Chapter list |
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
| Inputs | Whole text |
| Outputs | Chapter texts |
| Refers to | Chapter list |
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
| Inputs | Chapter texts |
| Outputs | Card drafts |
| Refers to | Card spec |
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
| Inputs | Card drafts |
| Outputs | Anchor 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
| Inputs | Anchor check |
| Outputs | Strict check |
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
| Inputs | Strict check |
| Outputs | KB MCP server |
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
| Inputs | KB MCP server |
| Outputs | Expert 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.