Runs OCR locally on PDFs and page images using Datalab's open models (Chandra OCR 2, Surya OCR 2.5, Indra OCR). Automatically selects the best model based on hardware, runs a resumable job, and exports to JSON, plain text, Markdown, HTML, ALTO XML, PAGE XML, TEI, or hOCR.
Ships in local-ocr. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
This skill runs OCR on the user's own machine. Nothing is sent to a cloud service, except that each model is downloaded once from Hugging Face. It uses three open models from Datalab (https://www.datalab.to):
| Model | Size | Runs on | Speed (one page) | Best for |
|---|---|---|---|---|
| Chandra OCR 2 | 5.2 GB (8-bit MLX) / 10.6 GB (full) | Apple Silicon with 16 GB+, or NVIDIA GPU with 16 GB+ | about 35–55 s | the best text: old prints, vertical CJK, mixed layouts, tables |
| Surya OCR 2.5 | 1.4–2 GB | Apple Silicon, NVIDIA, or CPU (slow) | about 3–8 s | big, clean printed books; a fast searchable draft |
| Indra OCR | 0.1 GB | any computer, CPU only | about 0.1–0.5 s | modern horizontal print, quick text, weak machines |
All three give layout blocks (heading, text, footnote, page header, picture, table …) with boxes, so
the XML formats keep the page layout. The numbers come from a 150-page test on Chinese books
(references/models.md). Short version: Chandra is the most accurate, Surya is close on clean print, and
Indra cannot read vertical (top-to-bottom) Chinese or Japanese.
Every script is in scripts/ and runs with uv run. The runners carry their own dependencies (PEP 723),
so uv installs them the first time.
In the commands below, SCRIPTS stands for the full path of this skill's scripts/ folder (for example
~/.claude/skills/local-ocr/scripts). Write the real path out in every command. Do not put it in a shell
variable (S=...; uv run SCRIPTS/doctor.py): Claude Code cannot check a command that sets a variable against
the user's permission rules, so it is refused.
If uv prints a warning that a .python-version file does not match the script's Python, ignore it. uv
picks a fitting Python by itself. Tell the user it is not an error.
Not for: a PDF that already has a good text layer (extract that text instead; ask first), or pages that need a scholar's reading of every hard character. For those, a vision LLM reading or a person is better. Use local OCR as the first pass.
Follow the steps in order. Use plain words with the user and explain any technical term once.
uv run SCRIPTS/doctor.py
This prints the machine (chip, memory, GPU, free disk), the tools found (llama-server, docker,
nvidia-smi, gh), a verdict for each model (GOOD / SLOW / NO, the backend, and the download size, or
"already downloaded"), and earlier jobs on this machine with their progress.
~/.cache/huggingface/hub).Ask with AskUserQuestion (up to 4 questions in one call). If that tool is not there (for example in a
headless run), write the questions as plain text and wait for the answer. Skip any question the request has
already answered. Ask:
The documents. Path to the PDF, images or folder. Roughly how many pages?
The material. Script and language (Chinese, Japanese, Korean, English, mixed …). Writing direction (horizontal or vertical columns). Kind (modern print, old woodblock or movable type, typescript, handwriting, newspapers, tables). Scan quality.
The goal. "Best text I can get" or "a quick searchable draft". Is there a deadline? (A 500-page book takes about 8 hours with Chandra and about 1 hour with Surya.)
Output formats (multiSelect). Plain text (txt), Markdown (md), JSON (json, one file per
document with blocks and boxes), JSON Lines (jsonl, one line per page), reading page (html), ALTO XML
(alto), PAGE XML (pagexml), TEI (tei), hOCR (hocr). Say what each is for in a few words: ALTO and
PAGE are what library systems, Transkribus and eScriptorium import; TEI is for text editions.
Confidential? Ask this when the material may be unpublished, restricted, or about living people: "May I look at the pages and the text myself? What I open is sent to the cloud model I run on." The OCR itself always stays on this computer. See "Confidential material" below for what to do on a no.
Then look at 2–3 pages yourself (render a page or open an image and Read it). Check the writing direction and the layout. Users are sometimes wrong about these. (Not for confidential material: ask the user to describe the pages instead.)
Save the answers to a small JSON file, for example brief.json, with the keys material, script,
direction, languages, condition, goal, formats. prepare.py --brief stores it in the job, and the
field report uses the non-private keys.
Combine the material with the doctor's verdicts:
| Material | First choice | Fallback |
|---|---|---|
| Vertical CJK (classical prints, manuscripts) | Chandra | Surya (draft only). Never Indra. |
| Hard pages: worn, faint, tables, mixed scripts, notes between lines | Chandra | Surya, then check the flagged pages |
| Clean modern print, many pages | Surya | Chandra if the time is there; Indra if the machine is weak |
| Modern horizontal print on a weak machine, or a quick look | Indra | Surya on CPU (slow) |
| Handwriting | Chandra | none of these is good; say so |
Tell the user the plan in one short paragraph: the model, why, the download size, the time (pages × the speed in the table above, or the smoke-test speed), and the output formats. Wait for their OK before a download over 1 GB or a run over an hour.
uv run SCRIPTS/prepare.py BOOK.pdf --job ~/ocr-jobs/NAME --model chandra --formats json,txt,alto --brief brief.json
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/NAME --setup # installs, downloads and loads the model, then stops
prepare.py takes PDFs, images and folders, as many as you like. Each file becomes one document, and a
folder of images is one document. Pages are saved as PNG in JOB/pages/. Useful options:
--pages 1-20,35, --dpi 300 for small print, --long-side 3000 for very dense pages.prepare.py again on the same job adds only new files, so a corpus can grow.--read-blank reads them anyway).~/ocr-jobs/<name> is a good default. Every job is recorded in
~/.cache/local-ocr/registry.json, so the doctor finds it later.--setup is safe to run again. If the model is already there, it only loads it.Backends are picked automatically (--backend overrides):
| Runner | Apple Silicon | NVIDIA GPU | CPU only |
|---|---|---|---|
run_chandra.py | mlx (8-bit) | hf (PyTorch, full model) | not supported |
run_surya.py | llamacpp if llama-server is installed (fastest), else mlx (builds an 8-bit copy once) | vllm with Docker, else llamacpp | llamacpp (slow) |
run_indra.py | cpu | cpu | cpu |
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/NAME --limit 5
uv run SCRIPTS/export.py ~/ocr-jobs/NAME --formats txt
--limit N reads the next N unread pages and stops. --pages 12,40 reads only those pages, also if they
were read before. For a one-page test use --limit 1. For pages from different parts of the document use
--pages, for example --pages 3,150,290.
Read 2–3 page images next to their text and count clear errors. Look for whole lines that are missing or
replaced, not only for wrong characters: Surya once wrote eight lines of "CamScanner" in place of a real
line of a 1637 print, and nothing in its output marked it. Show the user one page of output. Tell them the real speed and the new time estimate.
If the quality is poor, change the model now (prepare.py ... --model surya switches the job), not after
500 pages.
Run it in the background, because it can take hours. The runner is resumable: stopping is safe, and running the same command again goes on from the next unread page. Pages with an error are tried again.
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/NAME > ~/ocr-jobs/NAME/run.log 2>&1 # with run_in_background
uv run SCRIPTS/jobs.py status ~/ocr-jobs/NAME # pages done, speed, time left
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/NAME --pages 12,40 # read only these pages, again
While it runs, log anything unusual with uv run SCRIPTS/jobs.py note JOB "...": a crash, a page that stalled,
a layout the model gets wrong, a surprise in speed or memory. These notes go into the report.
What the runners flag:
The report (step 8) adds checks on the text itself: pages with no text, with little text for the ink, with text on a blank-looking page, with scanner or watermark text (CamScanner, "Digitized by Google" …, which models also invent), and with the same line many times.
uv run SCRIPTS/export.py ~/ocr-jobs/NAME # the formats chosen in the interview
uv run SCRIPTS/export.py ~/ocr-jobs/NAME --formats tei,pagexml # any others
Files go to JOB/export/<format>/. Options: --drop-furniture leaves out running heads and page
numbers; --no-page-marks writes txt/md without [[page N]] marks. Loop, error and skipped pages are
exported as empty pages and listed. Pages not read yet are left out. Format details are in
references/api_reference.md.
Coordinates. Boxes in ALTO, PAGE XML, hOCR and JSON are in pixels of the working copies in JOB/pages/
(prepare.py shrinks pages whose long side is over 2400 px). Each ALTO and PAGE file says so. If the user
will load the XML next to their own, larger images (Transkribus, eScriptorium), export with
--coords original: the boxes are then scaled to the original image size. For a PDF, "original" is the
page as rendered at --dpi.
uv run SCRIPTS/report.py ~/ocr-jobs/NAME --describe "Qing woodblock print, vertical, good scan"
This writes two files:
JOB/report.md is for the user: pages read, speed, the pages to look at (loops, slow pages, no text,
little text for the amount of ink, text on pages that look blank), the files, notes, and the licence.
Give the user the main points in plain words. Always say: machine transcription, not proofread.JOB/field-report.md is for a GitHub issue: machine, model, backend, versions, speed, flags, notes. It
has no page text, no file paths and no document names (unless --share-titles). Read it, fill in
"What the skill says / lacks" and "Proposed change", and remove anything private.Then offer to post the field report. It helps tune the advice on speed, memory and model choice for other machines. Issues are public, so ask first and show the text:
gh issue create --repo kltng/humanities-skills \
--title "[local-ocr] field report: <model> on <chip>, <material>, <pages> pages" \
--body-file ~/ocr-jobs/NAME/field-report.md
Without gh, give the user the link https://github.com/kltng/humanities-skills/issues/new and the file to paste.
The models run on this computer, so the scans are never uploaded by the OCR. But anything you open or print in the chat goes to the cloud model you run on: a page image you Read, a page of output you show, a line you quote. For unpublished, restricted or personal sources, ask first (interview question 5). If the user says no:
rows.jsonl or anything in export/. Do not print page text.JOB/pages/00012.png
next to JOB/export/txt/...) and ask what they see.jobs.py status, the runner's log lines (page, seconds, characters, status) and
report.md. The report lists page ids and counts, never page text. field-report.md is safe to read.This skill has no mode that proves the network is off. If the sources must stay on a machine with no
network at all, say so plainly, and see local-audio-transcription for how that skill builds and tests
everything first and then hands over a script to run after disconnecting.
jwindle47/chandra-ocr-2-8bit-mlx). In our test it read as well as the full model.A 300-page Qing woodblock print on a 32 GB MacBook, ALTO and text wanted:
# SCRIPTS = the full path of this skill's scripts/ folder, written out in every command
uv run SCRIPTS/doctor.py # chandra GOOD mlx, download about 5.2 GB
uv run SCRIPTS/prepare.py ~/Downloads/wenmiao.pdf --job ~/ocr-jobs/wenmiao --model chandra \
--formats alto,txt --brief /tmp/brief.json
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/wenmiao --setup # one-time download
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/wenmiao --limit 5 # smoke test, then look at the pages
uv run SCRIPTS/run_chandra.py ~/ocr-jobs/wenmiao > ~/ocr-jobs/wenmiao/run.log 2>&1 # background, ~4–5 h
uv run SCRIPTS/jobs.py status ~/ocr-jobs/wenmiao
uv run SCRIPTS/export.py ~/ocr-jobs/wenmiao
uv run SCRIPTS/report.py ~/ocr-jobs/wenmiao --describe "Qing woodblock print, vertical"
A folder of 2,000 modern English typescript scans on an older Windows laptop:
uv run SCRIPTS/doctor.py # chandra NO, surya SLOW, indra GOOD
uv run SCRIPTS/prepare.py D:/scans --job D:/ocr-jobs/letters --model indra --formats txt,pagexml
uv run SCRIPTS/run_indra.py D:/ocr-jobs/letters --limit 10
uv run SCRIPTS/run_indra.py D:/ocr-jobs/letters # about 0.5 s per page
references/models.md: the three models, the test results, hardware needs, licences.references/api_reference.md: every script and option, the job folder, the row format, and the exports.cd local-ocr && python3 -m unittest discover -s testsReport a problem. This skill is part of the public repository kltng/humanities-skills. If it fails (a model or package changed, a script errors, or these instructions are wrong), report it as a GitHub issue:
gh issue list --repo kltng/humanities-skills --state all --search "local-ocr"gh issue create --repo kltng/humanities-skills --label bug --title "[local-ocr] <short summary>" --body "<details>". Without gh, give the user this link: https://github.com/kltng/humanities-skills/issues/new?template=skill-problem.ymlField reports from finished jobs (step 8) are welcome too. Use the title [local-ocr] field report: ....
Credit the source. The reading is done by models from Datalab (Vikas Paruchuri and the Datalab team). Name the model and its version in anything you publish from the output.
jwindle47 under the same licence. On Apple Silicon the models run on mlx-vlm by Prince Canuma (MIT).Cite. If this skill helped work that is published, please cite it, together with the source credited above:
Tang, Kwok-leong. humanities-skills: local-ocr (version ). GitHub, . https://github.com/kltng/humanities-skills
When you help a user write up results that relied on this skill, remind them once about this citation and the credit above.
references/api_reference.md (opens in a new tab)references/models.md (opens in a new tab)scripts/_common.py (opens in a new tab)scripts/doctor.py (opens in a new tab)scripts/export.py (opens in a new tab)scripts/jobs.py (opens in a new tab)scripts/prepare.py (opens in a new tab)scripts/report.py (opens in a new tab)scripts/run_chandra.py (opens in a new tab)scripts/run_indra.py (opens in a new tab)scripts/run_surya.py (opens in a new tab)tests/test_local_ocr.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/local-ocr:local-ocrfrom local-ocr
npx claudepluginhub kltng/humanities-skills --plugin local-ocrOther plugins' skills for the same job