Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
Add Amp skill compatibility
zuwasie0729494c21b
diff --git a/SKILL.md b/SKILL.mdindex aa31260..79ca3c2 100644--- a/SKILL.md+++ b/SKILL.md@@ -1,23 +1,23 @@---name: book-to-skill-description: Converts a technical book (PDF or EPUB) into a structured Claude Code skill — extracting frameworks, mental models, principles, techniques, and anti-patterns the author crystallized. Use when the user wants to study a book through Claude, apply an author's frameworks while working, or build a reusable knowledge base from any PDF or EPUB.-when_to_use: Trigger phrases — "turn this book into a skill", "create a skill from this PDF", "create a skill from this EPUB", "I want to study X book", "add this book to my skills", "convert PDF to skill", "convert EPUB to skill", "analyze this book", "extract frameworks from this book". Accepts a path to a PDF or EPUB and optional skill name slug.-disable-model-invocation: true-context: fork-agent: general-purpose-allowed-tools: Bash(python3 *) Bash(pdftotext *) Bash(mkdir *) Bash(cp *) Bash(find *) Bash(wc *) Bash(echo *) Bash(cat *) Bash(date *) Read Write Glob Grep+description: "Converts a technical book (PDF or EPUB) into a structured agent skill, extracting frameworks, mental models, principles, techniques, and anti-patterns. Use when the user wants to study a book through Amp or Claude Code, apply an author's frameworks while working, or build a reusable knowledge base from any PDF or EPUB."+compatibility: "Amp skill directories (.agents/skills, ~/.config/agents/skills, ~/.config/amp/skills) and Claude Code skill directories (~/.claude/skills)."+allowed-tools:+ - shell_command+ - Read+ - Write+ - Glob+ - Grepargument-hint: <path-to-pdf-or-epub> [skill-name-slug]-arguments: [book_path, skill_name]-effort: high---# Book-to-Skill Converter-Transform written knowledge into actionable Claude Code skills by extracting structure — not producing summaries.+Transform written knowledge into actionable agent skills by extracting structure — not producing summaries.## Philosophy-Books contain crystallized expertise: frameworks, principles, and techniques that took years to develop. This skill extracts that knowledge into a format Claude can leverage repeatedly.+Books contain crystallized expertise: frameworks, principles, and techniques that took years to develop. This skill extracts that knowledge into a format Amp, Claude Code, or another compatible agent can leverage repeatedly.**Extract structure, not summaries.** A skill isn't a book report. It's a toolkit of:- Named frameworks (mental models with clear application)@@ -53,18 +53,33 @@ Three paths available. Route based on what the user asks:---+## Skill Locations++This converter can run from multiple skill systems. When looking for this converter's helper script or writing the generated book skill, prefer these locations in order:++1. Amp project-local skills: `.agents/skills/`+2. Amp global skills: `~/.config/agents/skills/`+3. Amp legacy global skills: `~/.config/amp/skills/`+4. Claude Code skills: `~/.claude/skills/`++Generated skills should default to `~/.config/agents/skills/` for Amp unless the user asks for project-local or Claude Code output.++---+## Step 0 — Out-of-scope checkIf the argument is NOT a path to a PDF or EPUB file, stop and respond:-> "book-to-skill requires a PDF or EPUB path. Usage: `/book-to-skill /path/to/book.pdf [skill-name]` or `/book-to-skill /path/to/book.epub [skill-name]`"+> "book-to-skill requires a PDF or EPUB path. Usage: `book-to-skill /path/to/book.pdf [skill-name]` or `book-to-skill /path/to/book.epub [skill-name]`"++Throughout the workflow, treat the first argument as `BOOK_PATH` and the optional second argument as `SKILL_NAME`.---## Step 1 — Validate input```bash-test -f "$0" && echo "FILE_OK" || echo "FILE_NOT_FOUND: $0"-file "$0" | grep -iE "pdf|epub|zip" && echo "FORMAT_OK" || echo "FORMAT_UNKNOWN"+test -f "$BOOK_PATH" && echo "FILE_OK" || echo "FILE_NOT_FOUND: $BOOK_PATH"+file "$BOOK_PATH" | grep -iE "pdf|epub|zip" && echo "FORMAT_OK" || echo "FORMAT_UNKNOWN"```Check the file extension (`.pdf` or `.epub`) or magic bytes (`%PDF` or `PK` zip header).@@ -101,23 +116,46 @@ Store the answer as `BOOK_TYPE`:Run the extraction script, passing the book type:```bash-python3 ~/.claude/skills/book-to-skill/scripts/extract.py "$0" --mode <BOOK_TYPE>+SCRIPT_PATH=""+for candidate in \+ ".agents/skills/book-to-skill/scripts/extract.py" \+ "$HOME/.config/agents/skills/book-to-skill/scripts/extract.py" \+ "$HOME/.config/amp/skills/book-to-skill/scripts/extract.py" \+ "$HOME/.claude/skills/book-to-skill/scripts/extract.py"+do+ if [ -f "$candidate" ]; then+ SCRIPT_PATH="$candidate"+ break+ fi+done++if [ -z "$SCRIPT_PATH" ]; then+ echo "Could not find scripts/extract.py for book-to-skill" >&2+ exit 1+fi++PYTHON_BIN="${PYTHON_BIN:-python3}"+if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then+ PYTHON_BIN="python"+fi++"$PYTHON_BIN" "$SCRIPT_PATH" "$BOOK_PATH" --mode <BOOK_TYPE>```- `--mode technical` → uses Docling (layout-aware, preserves tables and code blocks as markdown)- `--mode text` → uses pdftotext → PyPDF2 → pdfminer fallback chain (fast, plain text)This creates:-- `/tmp/book_skill_work/full_text.txt` — full extracted text-- `/tmp/book_skill_work/metadata.json` — title, estimated pages, token count, size, extraction_mode+- `<tempdir>/book_skill_work/full_text.txt` — full extracted text+- `<tempdir>/book_skill_work/metadata.json` — title, estimated pages, token count, size, extraction_mode-Read `/tmp/book_skill_work/metadata.json` to understand what was extracted.+Read the `output_text` path in `<tempdir>/book_skill_work/metadata.json` to understand what was extracted. The extractor uses the platform temp directory by default and supports `BOOK_SKILL_WORKDIR` if an explicit work directory is needed.---## Step 2.5 — Pre-flight cost estimate-Read `/tmp/book_skill_work/metadata.json` and present the user with an estimate **before doing any generation**:+Read `<tempdir>/book_skill_work/metadata.json` and present the user with an estimate **before doing any generation**:```📖 Book detected: <filename> (<format: PDF or EPUB>)@@ -151,7 +189,7 @@ Wait for the user to confirm before proceeding. If they say "analyze only", swit## Step 3 — Analyze book structure-Read the first 8,000 characters of `/tmp/book_skill_work/full_text.txt` to identify:+Read the first 8,000 characters of the extracted `full_text.txt` to identify:- Book **title** and **author(s)**- **Chapter structure** (look for "Chapter N", "PART I", numbered headings, table of contents)- **Core themes** and subject domain@@ -200,14 +238,20 @@ Use the answer to weight what gets highlighted in the SKILL.md Core section.## Step 5 — Determine skill name-If `$1` was provided, use it as the skill slug.+If `SKILL_NAME` was provided, use it as the skill slug.Otherwise, propose two options and let the user choose:- **By author-concept**: `{author-lastname}-{core-concept}` (e.g. `cialdini-influence`, `meadows-systems`)- **By title**: lowercase hyphens from book title (e.g. `designing-data-intensive-apps`)Default to author-concept format if the book has a strong methodological identity.-Check that `~/.claude/skills/<skill_name>/` does NOT already exist.+Choose the destination skill root:+- **Amp default**: `~/.config/agents/skills`+- **Amp project-local**: `.agents/skills` when the user explicitly wants the generated book skill scoped to the current workspace+- **Amp legacy**: `~/.config/amp/skills` if that is the user's existing global skill location+- **Claude Code**: `~/.claude/skills` if the user explicitly asks for Claude Code output++Set `SKILLS_HOME` to the selected root and check that `$SKILLS_HOME/<skill_name>/` does NOT already exist.If it does, append `-2` or ask the user before overwriting.---@@ -215,7 +259,7 @@ If it does, append `-2` or ask the user before overwriting.## Step 6 — Create skill directory structure```bash-mkdir -p ~/.claude/skills/<skill_name>/chapters+mkdir -p "$SKILLS_HOME/<skill_name>/chapters"```---@@ -228,9 +272,9 @@ mkdir -p ~/.claude/skills/<skill_name>/chaptersFor EACH chapter/major section identified in Step 3:-Read the corresponding section of `/tmp/book_skill_work/full_text.txt` (use character offsets or grep for chapter headings).+Read the corresponding section of the extracted `full_text.txt` (use character offsets or grep for chapter headings).-Create `~/.claude/skills/<skill_name>/chapters/ch<NN>-<slug>.md` using the structure below.+Create `$SKILLS_HOME/<skill_name>/chapters/ch<NN>-<slug>.md` using the structure below.**Adapt emphasis based on `BOOK_TYPE`:**- `technical` → prioritize "Code Examples", "Reference Tables", and "Commands & APIs" sections; preserve exact syntax@@ -283,19 +327,19 @@ Create `~/.claude/skills/<skill_name>/chapters/ch<NN>-<slug>.md` using the struc## Step 8 — Generate supporting files### glossary.md-Create `~/.claude/skills/<skill_name>/glossary.md`:+Create `$SKILLS_HOME/<skill_name>/glossary.md`:- Every significant term from the book, alphabetically sorted- Format: `**Term** — definition (Ch N)`- Max 1,500 tokens### patterns.md-Create `~/.claude/skills/<skill_name>/patterns.md`:+Create `$SKILLS_HOME/<skill_name>/patterns.md`:- All concrete techniques, design patterns, algorithms from the book- Format: `## Pattern Name\n**When to use**: ...\n**How**: ...\n**Trade-offs**: ...`- Max 2,000 tokens### cheatsheet.md-Create `~/.claude/skills/<skill_name>/cheatsheet.md`:+Create `$SKILLS_HOME/<skill_name>/cheatsheet.md`:- Decision tables, comparison matrices, quick-reference rules- The content you'd want on a single printed page- Max 1,000 tokens@@ -307,14 +351,15 @@ Create `~/.claude/skills/<skill_name>/cheatsheet.md`:**CRITICAL TOKEN BUDGET: Keep SKILL.md body under 4,000 tokens.**Compaction truncates from the END — put the most important content FIRST.-Create `~/.claude/skills/<skill_name>/SKILL.md`:+Create `$SKILLS_HOME/<skill_name>/SKILL.md`:```markdown---name: <skill_name>-description: Knowledge base from "<Full Title>" by <Author(s)>. Use when applying <author>'s frameworks for <key topics, 3–6 terms>.-when_to_use: <10–15 trigger phrases based on book topics and terms. Comma-separated.>-allowed-tools: Read Grep+description: "Knowledge base from \"<Full Title>\" by <Author(s)>. Use when applying <author>'s frameworks for <key topics, 3–6 terms>, studying the book, or referencing its concepts."+allowed-tools:+ - Read+ - Grepargument-hint: [topic, framework name, or chapter number]---@@ -323,9 +368,9 @@ argument-hint: [topic, framework name, or chapter number]## How to Use This Skill-- **Without arguments** — `/skill-name` loads core frameworks for reference-- **With a topic** — `/skill-name replication` → I find and read the relevant chapter-- **With chapter** — `/skill-name ch05` → I load that specific chapter+- **Without arguments** — load core frameworks for reference+- **With a topic** — ask about `replication`, `pricing`, or another indexed topic; I find and read the relevant chapter+- **With chapter** — ask for `ch05`; I load that specific chapter- **Browse** — ask "what chapters do you have?" to see the full indexWhen you ask about a topic not covered in Core Frameworks below, I will read@@ -368,7 +413,7 @@ the relevant chapter file before answering.This skill covers the book content only. For hands-on implementation in your codebase,combine with project-specific tools. For topics beyond this book, check related skills-or ask Claude directly.+or ask the agent directly.```---@@ -376,13 +421,27 @@ or ask Claude directly.## Step 10 — Cleanup and report```bash-rm -rf /tmp/book_skill_work+PYTHON_BIN="${PYTHON_BIN:-python3}"+if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then+ PYTHON_BIN="python"+fi++"$PYTHON_BIN" - <<'PY'+import os+import shutil+import tempfile+from pathlib import Path+shutil.rmtree(+ os.environ.get("BOOK_SKILL_WORKDIR", Path(tempfile.gettempdir()) / "book_skill_work"),+ ignore_errors=True,+)+PY```Then report to the user:```-✅ Skill created: ~/.claude/skills/<skill_name>/+✅ Skill created: $SKILLS_HOME/<skill_name>/📚 Book: <Full Title> — <Author>📄 Pages: ~<N> | Chapters: <N>@@ -396,12 +455,12 @@ Files generated:─────────────────────────────────────────────────────Total skill size: ~X tokens (loaded on-demand, not all at once)-💡 Tip: run /cost in Claude Code to see the actual token usage for this session.+💡 Tip: check your agent's session cost/usage command to see actual token usage.Usage:- /<skill_name> → load core frameworks- /<skill_name> <topic> → find and explain a topic- /<skill_name> ch<N> → dive into a specific chapter+ Ask for <skill_name> → load core frameworks+ Ask <skill_name> about <topic> → find and explain a topic+ Ask <skill_name> for ch<N> → dive into a specific chapter```---@@ -415,4 +474,4 @@ Usage:5. **Front-load SKILL.md** — compaction keeps the first 5,000 tokens; most important content comes first6. **Chapter files are on-demand** — they don't count against skill budget until loaded7. **Never copy raw book text** — always synthesize, summarize, extract signal-8. **Topic index is critical** — it's how Claude navigates to the right chapter file+8. **Topic index is critical** — it's how the agent navigates to the right chapter filediff --git a/scripts/extract.py b/scripts/extract.pyindex b27ef47..56e114f 100644--- a/scripts/extract.py+++ b/scripts/extract.py@@ -12,8 +12,10 @@ EPUB extraction tries methods in order:2. zipfile + html.parser — stdlib fallback (no extra deps)Outputs:- /tmp/book_skill_work/full_text.txt — full extracted text- /tmp/book_skill_work/metadata.json — stats and metadata+ <tempdir>/book_skill_work/full_text.txt — full extracted text+ <tempdir>/book_skill_work/metadata.json — stats and metadata++Set BOOK_SKILL_WORKDIR to override the output directory."""import html@@ -24,10 +26,16 @@ import reimport shutilimport subprocessimport sys+import tempfileimport zipfilefrom pathlib import Path-OUTPUT_DIR = Path("/tmp/book_skill_work")+OUTPUT_DIR = Path(+ os.environ.get(+ "BOOK_SKILL_WORKDIR",+ str(Path(tempfile.gettempdir()) / "book_skill_work"),+ )+)OUTPUT_TEXT = OUTPUT_DIR / "full_text.txt"OUTPUT_META = OUTPUT_DIR / "metadata.json"