TRANSLATE-BOOK — AGENT SKILL · A ONE-PAGE GUIDE

Translate a whole book, in parallel

An Agent Skill for Claude Code, Codex, Cursor, OpenClaw & more. It splits a PDF, DOCX or EPUB into chunks, hands them to batches of sub-agents that each start with a fresh context, checks every result against a manifest, and binds the book back together as HTML, DOCX, EPUB and PDF.

§ 01The idea in one line

ONE CHUNK, ONE FRESH CONTEXT
ONE BIG SESSION The whole book in one session→ Context piles up→ Output gets cut off
TRANSLATE-BOOK ~6,000-character chunks→ 1 chunk = 1 sub-agent→ Manifest check, then merge

The core move: every chunk is translated by a sub-agent with a fresh context window, so the run never suffers the context build-up and truncated output of pushing a whole book through one session. Consistency across chunks doesn't rely on memory. It comes from a glossary, excerpts of the neighboring chunks, and state files that let any run resume.

§ 02Six moving parts

ONE CARD, ONE SCRIPT · scripts/

SKILL.md does the orchestrating; anything deterministic is left to the Python in scripts/. Each card links to a script on the main branch.

01CONVERT & SPLIT From book to chunks Calibre turns the book into HTMLZ, which becomes Markdown split into chunk0001.md, and so on. Footnotes become Pandoc footnotes, numbered continuously across the book. Markdown input (MinerU or Marker output) skips Calibre entirely, and math blocks are never cut in half. scripts/convert.py→ 02SHA-256 MANIFEST Checks before the merge Records the SHA-256 of every source chunk. Before merging, it confirms that sources and outputs pair up 1:1, no source changed after the split, no output is empty or blank, and not a single footnote marker went missing. source_fingerprint.json stops a new source file from reusing stale chunks. scripts/manifest.py→ 03TERM CONSISTENCY A glossary every chunk obeys Samples 5 chunks to build glossary.json (v2 schema with aliases, gender and confidence) and counts term frequencies across the book. Before a chunk is translated, it gets a three-column table (source | aliases | translation) as a hard constraint. scripts/glossary.py→ 04NEIGHBOR CONTEXT A glance at the neighbors Each sub-agent also sees read-only excerpts of about 300 characters: the end of the previous chunk and the start of the next. They are there only to resolve pronouns, gender and entities, and are never translated or copied into the output. No new state files. scripts/chunk_context.py→ 05FEEDBACK MERGE Observations flow back Alongside its translation, each sub-agent writes output_chunkNNNN.meta.json (schema in meta.py): new entities, alias guesses, attributes, conflicts. After every batch, merge_meta.py folds them into the glossary conservatively and leaves the judgment calls to the main agent. scripts/meta.py · merge_meta.py→ 06SELECTIVE RE-TRANSLATE Redo only what changed run_state.json records, per chunk, the glossary version, entities and hashes it was translated with. Change the glossary or the source, and plan picks out only the chunks that are really affected. Rerun after an interruption, and outputs that are still valid are skipped. scripts/run_state.py→

Also in the box: merge_and_build.py (merge chunks → Pandoc HTML → DOCX / EPUB / PDF via Calibre), calibre_html_publish.py (a wrapper around Calibre's converter), two HTML templates, and figure_text.py (transcribes the text inside images into sidecar files and injects it into the chunks, so it goes through the same translation. The script is on main, but SKILL.md doesn't call it yet).

§ 03The pipeline, step by step

SKILL.md · WORKFLOW STEPS

The numbers on the left are the step numbers in SKILL.md. The main agent works its way down this ledger; the small print under each row is the script that step calls or the files it produces.

1 Collect parametersThe input file (required), the target language (default zh) and the sub-agents per batch (default 8), plus an optional temp directory, EPUB cover, export file name and custom instructions.file_path · target_lang · concurrency PARAMS 2 Convert to Markdown chunksCreates {book}_temp/ with the chunks, the manifest, the source fingerprint and config.txt. For PDFs dense with formulas and tables, convert them to Markdown with MinerU or Marker first.convert.py → chunk*.md · manifest.json · source_fingerprint.json CONVERT 3.5 Build the glossaryOnce Step 3 has found all the source chunks, sample them for proper nouns and domain terms and count how often each appears. An existing glossary.json is never overwritten, so manual edits survive.glossary.py count-frequencies GLOSSARY 3.7 Plan which chunks to translateSorts the chunks into “translate”, “record only” and “nothing to do”. The first group is this run's work queue.run_state.py plan PLAN 4 Translate with parallel sub-agentsUp to 8 sub-agents per batch. Each reads one chunk with its own glossary table and neighbor excerpts, and writes a translation plus a meta file. A batch is done when its files are on disk, and only then does the next one go out.output_chunkNNNN.md · output_chunkNNNN.meta.json TRANSLATE 4.5 Merge observations after each batchFirst record the batch's output, then merge the sub-agents' observations into the glossary. Conflict-free ones apply automatically; aliases and conflicts go to the main agent to decide.run_state.py record · merge_meta.py prepare-merge / apply-merge MERGE META 5 Verify and retryMissing chunks get one retry. Then it checks the heading levels across the book (they become the ebook's table of contents) and front or back matter carried over from the original edition, and prints snapshots of the meta files and run state.merge_and_build.py --headings · merge_meta.py status · run_state.py status VERIFY 6 Translate the titleReads the original title from config.txt. If the book has a published translated title, that is used as is, with no quotes or brackets around it.config.txt · original_title TITLE 7 Merge and buildOnce validation passes, the chunks are merged into output.md; Pandoc renders HTML with a table of contents, and Calibre produces DOCX, EPUB and PDF. Intermediate files are kept by default.merge_and_build.py --title … --export-name … BUILD 8–9 Report and spot-fixReports what was built and what failed. If a passage turns out wrong later, edit its output_chunkNNNN.md or delete it to have it re-translated, then rerun the build. No need to redo the whole book.run_state.py plan / record · merge_and_build.py FIX

§ 04As an agent harness

SKILL.md ORCHESTRATES, SCRIPTS KEEP THE BOOKS

Orchestration lives in Markdown; scripts keep the books.

PLATFORM-NEUTRAL ORCHESTRATION One SKILL.md, many hosts The same orchestration serves any agent that can spawn sub-agents from a Skill; Cursor and Codex have passed the minimal test. Script paths always go through {baseDir}, sub-agent instructions never name a platform-specific tool, and every frontmatter field stays on one line.
SINGLE WRITER One writer for shared state Only the main agent writes glossary.json and run_state.json. Sub-agents only read shared state and each writes its own meta file, so nothing needs a lock.
SCRIPTS BOOKKEEP · LLM MERGES Scripts keep records, the model makes the calls State, schema validation, deduplication, hashing and IO are deterministic Python. Naming, gender, alias matching and conflict resolution go to the model. Merges are conservative: a new entity needs evidence, and a conflict is never silently overwritten.
556lines in SKILL.md
10Python scripts in scripts/
11unit test files
337test cases (def test_)
3baseline books in the repo

Mechanical guardrails: on every push to main and every PR, GitHub Actions runs compileall and the full unit test suite on Python 3.12. The unit tests need nothing beyond the standard library, because every third-party import is guarded. The full pipeline runs on the books in tests/baselines/ (standard-alice, for one), with output under tests/.artifacts/. Figures counted at main @ fac5755 (2026-11-23).

§ 05Where to start

GETTING STARTED · 5 PHASES
1 PHASE 1 · PREREQUISITES Set up the environment An agent that supports Agent Skills and can spawn sub-agents from a Skill (Claude Code, Codex, Cursor, OpenClaw & more), plus Calibre (ebook-convert), Pandoc and Python 3. pypandoc and beautifulsoup4 are optional; MinerU or Marker is only needed for PDFs heavy on formulas and tables.
2 PHASE 2 · INSTALL THE SKILL Add it to your agent ANY AGENT
npx skills add deusyu/translate-book
CLAUDE CODE PLUGIN
/plugin marketplace add deusyu/translate-book
/plugin install translate-book@translate-book
OPENCLAW
openclaw skills install @deusyu/translate-book
The command asks which agents to install it for. To install globally for just one agent, add -a <agent> -g, e.g. -a cursor -g. You can also git clone the repo into ~/.agents/skills/translate-book (shared by Codex, Cursor and others), or into ~/.claude/skills/translate-book for Claude Code. Pick the plugin or the skills directory, not both: with both in place, both get loaded. If a freshly installed Skill doesn't show up, restart the agent. Other install options are in the README.
3 PHASE 3 · ONE PROMPT Translate a book CURSOR · CLAUDE CODE
/translate-book translate /path/to/book.pdf to Japanese
CODEX
$translate-book Translate /path/to/book.pdf into Chinese.
OPENCLAW
translate /path/to/book.pdf to Chinese
With the Claude Code plugin, the command is /translate-book:translate-book. All of these agents also take a request in plain language. The Skill then runs conversion, splitting, parallel translation, verification, merging and multi-format output on its own. If a run gets interrupted, start it again and it picks up where it left off.
4 PHASE 4 · {book_name}_temp/ Collect the books, revise as needed output.mdbook.htmlbook.docxbook.epubbook.pdf The web version comes with a floating table of contents. To fix a passage, edit the matching output_chunkNNNN.md (not output.md) and rerun merge_and_build.py. --cleanup deletes the intermediate files for good, so save it for when the whole book is final.
5 PHASE 5 · TESTS & FEEDBACK Run the tests, open an issue UNIT TESTS
python3 -m unittest discover -s tests -p 'test_*.py' -v
The project would rather get a detailed GitHub issue (what happened, what you expected, your environment, a minimal repro) than a pull request out of the blue. Changes have to be weighed together with the orchestration rules, the chunk / manifest contract and the release process the maintainer looks after.