| name | ocr-clean |
| description | Clean raw OCR output into the most accurate, faithful text representation of a source document for archiving, reference, and search (not narration). Use when working on OCR-derived exports, scanned-book pages, or extraction.txt/chapter files that need artifact repair, hyphenation rejoining, structure preserved as lightly-structured Markdown, and footnotes/citations kept intact while preserving original wording. |
| compatibility | Requires Bun (optional, for batch queue tracking) |
| allowed-tools | Bash Read Edit Write Glob Grep |
| metadata | {"short-description":"Clean OCR text into faithful Markdown for archiving","author":"autoshow","version":"1.0"} |
OCR Clean
Overview
Turn raw OCR output into the most accurate, faithful text representation of the source
document, one file at a time. The goal is an archival/reference/search record — not
read-aloud narration. Output is lightly-structured Markdown that mirrors the source:
headings, lists, tables, blockquotes, preserved page markers, and footnotes kept intact.
This is the inverse of TTS cleanup. Where tts-batch-polish removes footnotes, expands
abbreviations, and dissolves structure for spoken flow, ocr-clean preserves wording,
spelling, structure, and scholarly apparatus exactly.
Use this whenever the input is OCR-derived text (typically .txt, e.g. an
extraction.txt or chapter export) and quality issues include scanning artifacts,
hyphenation splits, running-header noise, lost structure, or garbled glyphs.
Read references/ocr-editing-rules.md before editing. It is the source of truth for
fidelity-safe cleanup, structure mapping, footnote handling, ambiguity handling, and QA.
Workflow
Progress:
Commands
Run commands from the skill directory. Replace DOC_DIR with the target directory from
the user or current task.
DOC_DIR="/absolute/path/to/ocr-export-directory"
ls -1 "$DOC_DIR"/*.txt | sort
Optional: pick a single file deterministically (first sorted file).
ls -1 "$DOC_DIR"/*.txt | sort | head -n 1
Optional: use the Bun queue helper to track repeatable single-file passes. By default it
scans .txt; pass --ext md to track Markdown outputs instead.
bun scripts/ocr_batch_queue.ts status --root "$DOC_DIR"
bun scripts/ocr_batch_queue.ts next --root "$DOC_DIR" --size 1
bun scripts/ocr_batch_queue.ts done --root "$DOC_DIR" "page-01.txt"
bun scripts/ocr_batch_queue.ts status --root "$DOC_DIR" --ext md
Editing Rules
Read and apply references/ocr-editing-rules.md for every file pass. Use it as the
single source of truth for fidelity-safe edits.
Core constraints:
- Preserve the source's exact wording, spelling, capitalization, and punctuation.
- Repair only genuine OCR damage: rejoin hyphenation splits, remove spurious intra-word
spaces, fix high-confidence mis-recognized glyphs, remove scanning artifacts.
- Represent the original structure in lightly-structured Markdown:
#/## headings,
-/1. lists, > blockquotes, Markdown tables, fenced blocks for preformatted text.
- Preserve page boundaries as
--- Page N --- reference anchors; remove repeated
running headers/footers.
- Preserve footnotes and citations. Convert inline markers to
[^n] references and
footnote blocks to [^n]: … definitions. Never delete, inline, or paraphrase them.
- Limit each run to one file unless the user explicitly asks for a different batch size.
- Exception to single-file editing: if a sentence is split across a file boundary, you
may edit the immediately adjacent file solely to complete the split sentence.
- Do not modernize, expand abbreviations, paraphrase, or add SSML/vendor tags.
- For genuinely illegible text, keep the literal reading and mark it
[?]; never guess.
Gotchas
- Limit each normal pass to one selected file. Edit an adjacent file only to repair a
broken boundary sentence.
- Footnote markers must be preserved as
[^n], not stripped. This is the opposite
of the TTS skill. Citation-only footnotes are kept too — they are reference content.
- Running headers/footers (the title reprinted on every page) are noise and are removed,
but page-boundary markers (
--- Page N ---) are reference anchors and are kept.
- Do not "correct" the author's spelling, grammar, or archaic usage. Only repair what is
clearly OCR damage. Glyph errors hide in words and numbers (
prob1em, astro1abe,
instru ments); body-text digits (dates, statistics, list numbers) are not footnote
markers.
File Completion Checklist
- Confirm exactly one selected target file was processed, unless an adjacent-file
boundary fix was required.
- Confirm Markdown renders cleanly: headings, lists, tables, and blockquotes are
well-formed.
- Confirm every
[^n] reference has a matching [^n]: definition and no footnote
content was dropped.
- Confirm running-header/footer noise was removed but
--- Page N --- markers remain.
- Confirm hyphenation splits are rejoined and no spurious intra-word spaces remain.
- Confirm wording, spelling, and punctuation are unchanged versus the source except for
genuine OCR-damage repairs.
- Confirm first and last lines are not sentence fragments and flow correctly with
neighboring files.
- Confirm all uncertain reads are marked
[?].
Reporting
After each file, report:
- Edited/produced file list.
- Categories of fixes applied (artifacts, hyphenation, glyphs, structure, footnotes).
- Whether opening/closing boundary continuity was checked and whether adjacent-file
repair was needed.
- How structure was mapped to Markdown (headings, lists, tables, page markers).
- Any uncertain reads marked
[?] and any remaining ambiguities.