Skip to main content
PaperClean

🧹 Turn rough document photos into conservative, scanner-like files. 🧹

PaperClean is a Python CLI for people who need cleaner PDFs or images from phone photos and poor scans without silently accepting changed content. Give it a PDF, JPEG, PNG, or folder; it recreates each page, runs local safety checks, requires mandatory model verification, and falls back to the original page when a candidate cannot be trusted.

Complete page pixels are sent through the configured backend: OpenRouter, or a loopback AgentBridge server backed by your authenticated Codex CLI. Before work begins, PaperClean shows a preflight and asks for confirmation. OpenRouter mode includes live cost and credit checks; AgentBridge mode shows model-call ceilings because Codex subscription USD usage is not exposed. Every generated page must pass local geometry and foreground checks plus five-view multimodal fidelity verification.

Install

PaperClean requires Python 3.11 or newer. Keyenv is recommended on macOS:

uv tool install keyenv-macos
uv tool install paperclean-cli

The PyPI distribution is named paperclean-cli; it installs the paperclean command and Python package.

Keyenv is the recommended way to keep OPENROUTER_API_KEY in the macOS Keychain. Create ~/.config/keyenv/.keyenv.toml:

[keyenv]
version = 1

[secrets.OPENROUTER_API_KEY]
account = "paperclean-user/OPENROUTER_API_KEY"
required = true

Authorize and store the key:

cd ~/.config/keyenv
keyenv authorize OPENROUTER_API_KEY
keyenv set OPENROUTER_API_KEY
keyenv doctor

Run PaperClean from the directory containing your document:

paperclean document.pdf

To run generation and mandatory verification through Codex instead, start the sibling AgentBridge checkout and select its backend. No OpenRouter key is needed:

cd ../agentbridge
uv run agentbridge

# In another terminal, from the directory containing the document:
paperclean document.pdf --backend agentbridge --yes

Commands

paperclean document.pdf                         # clean one PDF
paperclean photo.jpg                            # clean one JPEG or PNG
paperclean scans/                               # recursively clean a directory
paperclean document.pdf --backend agentbridge   # use Codex through local AgentBridge
paperclean document.pdf --max-attempts 3        # set generation attempts per page
paperclean document.pdf --max-cost-usd 1.00     # set a soft observed-cost ceiling
paperclean document.pdf --review-model openai/gpt-5.6-sol  # select verifier
paperclean --help                               # show every CLI option

A source named document.pdf produces:

document.clean.pdf
document.clean.pdf.report.json

Exit status 0 means every page passed, 2 means one or more original pages were used, and 1 means a fatal file or batch failure.

Configuration

CLI flags override environment variables, which override these defaults:

Environment variable Default
PAPERCLEAN_BACKEND openrouter
OPENROUTER_BASE_URL https://openrouter.ai/api/v1
PAPERCLEAN_AGENTBRIDGE_BASE_URL http://127.0.0.1:8082/api/v1
PAPERCLEAN_AGENTBRIDGE_TIMEOUT 660
PAPERCLEAN_IMAGE_MODEL openai/gpt-image-2
PAPERCLEAN_REVIEW_MODEL openai/gpt-5.6-sol
PAPERCLEAN_MAX_ATTEMPTS 3
PAPERCLEAN_JOBS 1
PAPERCLEAN_MAX_COST_USD unset
PAPERCLEAN_ZDR false

OPENROUTER_API_KEY is required only for the default OpenRouter backend. AgentBridge defaults both models to codex/gpt-5.6-sol, requires a loopback URL, and does not support --max-cost-usd or --zdr. PaperClean reads supported values from the process environment first, then user-level .env or Keyenv configuration, then repository-level configuration.

Notes

  • Supported inputs are PDF, JPEG, and PNG. Directory traversal is recursive and does not follow directory symlinks.
  • Local registration, foreground, canvas, and resolution checks run before mandatory five-view model verification. Rejected candidates retry with feedback, then fall back to a source-preserving white-paper cleanup that must pass the same verification. A page-scoped review timeout is retried exactly once before that attempt fails closed. That recovery confirms every rejection once. Confirmed scanner-quality failures still veto publication; only expected global deskew/layout rectification and conservatively preserved source uncertainty are tolerated. Explicit missing, cropped, invented, text, table, and diagram discrepancies still fail closed; localized normalized source evidence is restored for text-like discrepancies and the candidate is reviewed again. The untouched original page is used only if recovery still fails.
  • PaperClean restores registered reviewer-identified text, tables, diagrams, layout, signatures, stamps, and edge content from cleaned source pixels without restoring stains, skew, shadows, or damaged edges. Large photographic and diagnostic-image panels and large shaded form regions remain pixel-exact while the surrounding scanned paper is cleaned, even when thin scan noise connects a panel to a page border. A binder hole and its halo are erased directly only when their surrounding context is blank. When a hole obscures authored ink, PaperClean attempts a localized model restoration only when the obscured continuation is highly probable and publishes it only after independent full-page and regional verification. Vague unresolved-content alerts reject assisted restoration; otherwise the original hole is retained instead of guessing. A changed_diagram review alert is tolerable only when the local detector confirms that large photographic panels were masked and preserved by this deterministic path.
  • The cost preflight checks selected endpoints, live pricing, available credits, and the conservative recovery ceiling. --yes accepts the displayed preflight but never overrides insufficient known credits.
  • The AgentBridge preflight verifies Codex availability, authentication, native image generation, strict JSON Schema output, and both selected models. It shows conservative call counts and records observable orchestration tokens, but does not invent a USD cost or Codex subscription balance.
  • --max-cost-usd is a soft ceiling. One completed request or an ambiguously billed timeout can exceed it.
  • --zdr works only when every selected model endpoint is listed by OpenRouter as zero-data-retention capable. Do not process documents whose external transmission is prohibited.
  • AgentBridge requests use store: false. Its strict Codex profile disables execution tools, treats page pixels as untrusted data, validates the returned raster, and removes request-scoped generated-image artifacts. Page pixels are still transmitted to the Codex service; do not process documents whose external transmission is prohibited.
  • PDF outputs keep searchable text streams beneath an opaque page overlay. Active content and attachments are removed; encrypted PDFs, unapplied redactions, XFA, JavaScript-driven forms, and calculation-driven forms are rejected.

Development

uv sync --frozen --all-groups   # install the locked development environment
uv run ruff check .             # lint
uv run mypy -p paperclean       # type-check
uv run pytest                   # run the offline test suite
uv build --no-sources           # build wheel and source distribution
keyenv run -- uv run pytest -m live  # run opt-in live tests

Architecture

PaperClean architecture

License

No license file has been added yet.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paperclean_cli-0.1.1.tar.gz (105.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paperclean_cli-0.1.1-py3-none-any.whl (92.6 kB view details)

Uploaded Python 3

File details

Details for the file paperclean_cli-0.1.1.tar.gz.

File metadata

  • Download URL: paperclean_cli-0.1.1.tar.gz
  • Upload date:
  • Size: 105.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for paperclean_cli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f92aa53ffe6c56da59744d8ef45129136438092db4045bcdc77dd78e9b31277d
MD5 402afe14c9249c925a934722048abe43
BLAKE2b-256 82fdb63571f5223df73d48dda536941f107dbbaae023324c3caf83ca36821e01

See more details on using hashes here.

Provenance

The following attestation bundles were made for paperclean_cli-0.1.1.tar.gz:

Publisher: release.yml on tsilva/paperclean-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file paperclean_cli-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: paperclean_cli-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 92.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for paperclean_cli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e5c85b27a753734c98fbe10c4b4690020aa8d3d44b52d02dd924c3c89bc56c0
MD5 42b7cf749fd7ecacb80374b28c279e40
BLAKE2b-256 0f9273e82f16db6667eb955666b478754032b794100e0faf06c128bfff51252c

See more details on using hashes here.

Provenance

The following attestation bundles were made for paperclean_cli-0.1.1-py3-none-any.whl:

Publisher: release.yml on tsilva/paperclean-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page