Rainman Translate Book

An Agent Skill for Claude Code, Codex, Cursor, OpenClaw and other Agent Skills–compatible agents that translates entire books (PDF/DOCX/EPUB) into any language using parallel subagents.
Inspired by claude_translater. The original project uses shell scripts as its entry point, coordinating the Claude CLI with multiple step scripts to perform chunked translation. This project restructures the workflow as an Agent Skill for Claude Code, Codex, Cursor, OpenClaw, and other compatible agents, using subagents to translate chunks in parallel, with manifest-driven integrity checks, resumable runs, and multi-format output unified into a single pipeline. As the project structure and implementation differ significantly from the original, this is an independent project rather than a fork.
How It Works
Input (PDF/DOCX/EPUB)
│
▼
Calibre ebook-convert → HTMLZ → HTML → Markdown
(or Markdown from a layout-aware PDF parser, skipping Calibre)
│
▼
Split into chunks (chunk0001.md, chunk0002.md, ...)
│ manifest.json tracks chunk hashes
▼
Parallel subagents (8 concurrent by default)
│ each subagent: read 1 chunk → translate → write output_chunk*.md
│ batched to respect API rate limits
▼
Validate (manifest hash check, 1:1 source↔output match)
│
▼
Merge → Pandoc → HTML (with TOC) → Calibre → DOCX / EPUB / PDF
Each chunk gets its own independent subagent with a fresh context window. This prevents context accumulation and output truncation that happen when translating a full book in a single session.
Features
- Parallel subagents — 8 concurrent translators per batch, each with isolated context
- Resumable + selective re-translation — chunk-level resume, with
run_state.json tracking glossary-sensitive re-translation
- Neighbor context — each chunk can see short read-only excerpts from adjacent chunks for pronoun and entity resolution
- Manifest validation — SHA-256 hash tracking prevents stale or corrupt outputs from being merged
- Multi-format output — HTML (with floating TOC), DOCX, EPUB, PDF
- Optional output controls — explicit EPUB cover, custom temp root, and user-facing export aliases
- Shell-safe commands — the skill's commands hold only fixed text; the book's path, title and other book text reach the scripts through files, so a file named like
$(rm -rf ~).epub cannot run anything
- Multi-language — any language code, e.g. zh, en, ja, ko, fr, de, es, it (Italian), or one with a region such as zh-TW or pt-BR
- PDF/DOCX/EPUB/Markdown input — Calibre handles the conversion heavy lifting; formula- and table-heavy PDFs can be pre-extracted to Markdown with a layout-aware parser (see Step 1)
Prerequisites
- macOS or Linux — native Windows is not supported, and the scripts stop as soon as they start there. On Windows, run your agent inside WSL (Windows Subsystem for Linux)
- Agent runtime — any agent that supports Agent Skills and can launch sub-agents from a skill (see Compatibility)
- Calibre —
ebook-convert command must be available (download)
- Pandoc — for HTML↔Markdown conversion (download)
- Python 3 with:
pypandoc — optional (pip install pypandoc); without it the pandoc binary is called directly
beautifulsoup4 — optional, for better TOC generation (pip install beautifulsoup4)
- A layout-aware PDF parser — optional, only to pre-extract formula- and table-heavy PDFs to Markdown; supported parsers are listed in Step 1
Quick Start
1. Install the skill
Any Agent Skills–compatible agent
npx skills add deusyu/translate-book
The command asks which agents to install the skill for. To install it globally for one agent, pass -a <agent> -g, for example npx skills add deusyu/translate-book -a cursor -g: