prep-scan

prep-scan is a skill for Claude Code, Codex from MidnightDarling/collate. It costs 228 tokens per session (2,640 once invoked), scanned A, original, Apache-2.0.

A Mac tool that cleans unwanted marks from scanned PDF papers and historical documents before text recognition. It removes items such as library stamps, database watermarks, scan dates, headers, and footers, then creates a cleaned PDF and page images.

In plain words
What is it for?
It is for preparing scanned papers, books, archival records, and historical documents downloaded from services such as CNKI, libraries, and archives for OCR, or optical character recognition.
Why use it?
Scanned documents often make text recognition mistake stamps, logos, and dates for part of the main text. Cleaning them first helps preserve the document’s actual content, especially when the original print is faint or damaged.

Skill for Claude CodeCodex

Installs and runs on its own, but its text points at files inside its plugin — anything it tells you to read at a ${CLAUDE_PLUGIN_ROOT} path is only there once the plugin is installed. Installing the plugin gets both.

Part of the collate plugin — 15 skills, 2 commands, 2 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/midnightdarling/collate/prep-scan
Any agent
npx skills add MidnightDarling/collate --skill prep-scan
Clone the repo
git clone --depth 1 https://github.com/MidnightDarling/collate

Made for: Claude Code, Codex.

Or install collate, the plugin that ships this one along with the rest of its 15 skills, 2 commands, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for prep-scan

README.md
[![agentmods](https://agentmods.dev/badge/skills/midnightdarling/collate/prep-scan.svg)](https://agentmods.dev/skills/midnightdarling/collate/prep-scan)
Your own site
<a href="https://agentmods.dev/skills/midnightdarling/collate/prep-scan"><img src="https://agentmods.dev/badge/skills/midnightdarling/collate/prep-scan.svg" alt="Measured on agentmods" height="20"></a>
Per session 228 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,640 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00228 $0.02640
Opus 5 $0.00114 $0.01320
Sonnet 5 $0.00046 $0.00528
Haiku 4.5 $0.00023 $0.00264

Measured 3d ago against content hash 920c2f106313, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

prep-scan scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

The scan reads SKILL.md. This mod also ships 4 executable files (scripts/dewatermark.py, scripts/pages_to_pdf.py, scripts/remove_margins.py, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/prep-scan/SKILL.md · 194 lines

How it starts

The opening of the file, as written. The whole thing — 194 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PDF 预处理 — 历史扫描件专用

Task

用户要校对的扫描件不是干净原稿。典型来源和污染物:

来源 常见污染
中国知网(CNKI)/ 万方 右下角 logo 水印、"中国学术期刊出版总库" 对角线水印
读秀 / 超星 全页淡灰"读秀学术搜索"水印
国家图书馆 / 省图 红色馆藏章、馆藏登记号、扫描日期戳
中华再造善本 / 古籍数据库 馆藏章、版权水印、影印页眉
档案馆扫描件 红色骑缝章、档号戳、扫描批次编号
民国期刊影印本 刊名页眉、期号页脚、补白广告

这些污染会让 OCR 把"國立北平圖書館藏"之类的章文识别进正文,也会把"下载日期:2024-xx-xx"当成脚注。你要把它们清掉,但不能伤到正文——尤其是淡墨古籍、残损民国报刊,比水印还浅。

输出:<pdf-basename>.ocr/prep/cleaned.pdf + 逐页 PNG(供 OCR 和后面的对照预览复用)。

目录布局:本 skill 产物全部落在 <pdf-basename>.ocr/prep/ 下,和后续 OCR 产物共享同一个 .ocr/ 工作区。权威规范见插件的 references/workspace-layout.md——不要在 PDF 同级另建 .prep/ 目录。

Process

Step 1:确认输入

test -f "<pdf-path>" && file "<pdf-path>" | grep -qi pdf || echo "NOT_A_PDF"

若返回 NOT_A_PDF,终止并报告路径或格式问题。

检查是不是"已 OCR 的文字版 PDF"(例如知网下载的"CAJ 转 PDF"带有文本层):

python3 -c "
import PyPDF2
with open('<pdf-path>', 'rb') as f:
    r = PyPDF2.PdfReader(f)
    t = r.pages[0].extract_text() or ''
    print('TEXT_LAYER' if len(t.strip()) > 50 else 'SCAN_ONLY')
"
  • TEXT_LAYER:PDF 已含文字层,OCR 步骤可跳过。继续处理图像水印(文字层不影响)。
  • SCAN_ONLY:走完整流程。

Step 2:建工作目录

在 PDF 同级.ocr/ 工作区,并在里面开 prep/ 子目录,不改动用户原文件:

PDF="<pdf-path>"
DIR=$(dirname "$PDF")
BASE=$(basename "$PDF" .pdf)
OCR="$DIR/$BASE.ocr"
WORK="$OCR/prep"
mkdir -p "$WORK/pages" "$WORK/cleaned_pages" "$WORK/trimmed_pages"
cp "$PDF" "$WORK/original.pdf"

original.pdf 作为原始备份保留在 prep/,供后续回滚。注意:.ocr/ 根目录的 source.pdf 会在 Step 6 由 cleaned.pdf 派生出来,它才是"进入 OCR 阶段的 PDF"。

Step 3:拆页成 PNG

python3 "${CLAUDE_PLUGIN_ROOT}/skills/prep-scan/scripts/split_pages.py" \
    --pdf "$WORK/original.pdf" \
    --out "$WORK/pages" \
    --dpi 300

300 DPI 是 OCR 黄金点。再高 → 图大内存贵 OCR 不多提升;再低 → 小字(民国 5 号字、古籍双行夹注)糊掉。

老扫描件本身就不到 200 DPI 的情况,强行 300 会放大噪点。脚本会先探测原图 DPI,自动封顶:原图低于 250 就不强行上采样。

Step 4:去水印 / 去馆藏章

python3 "${CLAUDE_PLUGIN_ROOT}/skills/prep-scan/scripts/dewatermark.py" \
    --in "$WORK/pages" \
    --out "$WORK/cleaned_pages" \
    $( [ "$2" = "--aggressive" ] && echo "--aggressive" ) \
    $( [ "$2" = "--keep-color" ] || [ "$3" = "--keep-color" ] && echo "--keep-color" )

Read the full file on GitHub · 194 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 194 lines · 228 tokens per session scan A 920c2f106313

Subscribe to this mod's changes

prep-scan is a skill published in the GitHub repository MidnightDarling/collate (6 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 228 tokens to every session and 2,640 once invoked, about $0.0011 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

liteparse

Parse documents into LLM-ready content entirely on the local machine — PDF / DOCX / XLSX / PPTX / images → Markdown, structured JSON (with bounding boxes), or page screenshots, via the lit CLI. No cloud, no LLM, works offline. Use whenever the user attaches or points to a document that must be read before reasoning…

Prismer-AI/PrismerCloud · 90 tokens

office-artifacts

Generate real DOCX, PPTX, XLSX, PDF, CSV files using python-docx / python-pptx / openpyxl / reportlab by writing them into the dispatch artifacts dir, then explicitly deliver each one with cloud deliver . Use whenever the user asks for documents, slides, spreadsheets, reports, or PDFs.

Prismer-AI/PrismerCloud · 75 tokens

ingest

Turn external URLs and documents into LLM-ready content — load + cache web pages (HQCC compression) and OCR PDFs/images to Markdown. Use whenever the user gives a URL, asks you to read a webpage, or attaches a PDF/scan that needs to be parsed before reasoning. Executes via the cloud load, cloud search, and cloud parse…

Prismer-AI/PrismerCloud · 79 tokens

read

Read PDF page by page with structured output — key arguments, terms glossary, thesis connections. Use when reading academic papers, books, or articles.

yha9806/academic-writing-toolkit · 31 tokens

work-markitdown

办公文档通用 Inflow 编排:把 DOCX、PDF、PPTX、XLSX、图片、HTML、CSV 等 15+ 格式稳定转换为 Markdown。extends 上游 markitdown 技能,补充本地环境适配和批量转换工作流。用户提到'转成 md''文档转 markdown''解析文档''读取文档内容'时使用。.

seed-forge/harness-ai-kit · 93 tokens

llmwiki-ingest

Ingest one source document (or a folder of them) into the llmwiki. Use when the user drops a new markdown file, PDF, or URL into the wiki and asks you to process it. The user will typically say "ingest this", "add this to the wiki", "process this file into the wiki", or point at a file under raw/.

Pratiyush/llm-wiki · 83 tokens