Skip to main content

token-hunt

Catch secrets at chat time, not commit time.

release license python docs

Hook-based secret scanner for Claude Code. Catches leaks when you paste, when your agent reads, and when your agent's tools return — not at commit time when it's already too late.

Cursor and Aider supported via the CLI peer today (manual wiring); first-class plugin integrations ship in v0.2.

Why

Existing scanners (gitleaks, trufflehog, ggshield) scan git history. By the time you run git commit, your secret has been in the AI chat transcript for 30+ minutes — indexed by Anthropic, sync'd to other machines, possibly read by the agent and re-emitted in subsequent tool calls.

token-hunt catches at chat time. Zero cloud, zero telemetry, fail-closed by default.

Install

pip install token-hunt                              # standalone CLI
claude plugin install token-hunt@tokenhunt          # Claude Code plugin

Or from source:

git clone https://github.com/tokenhunt/token-hunt
cd token-hunt
pip install -e .

60-second demo

# In one terminal:
pip install token-hunt

# Scan a file:
echo "ANTHROPIC_API_KEY=sk-ant-..." > /tmp/test.txt
token-hunt scan /tmp/test.txt

# Watch a directory (e.g. Claude Code transcript dir):
token-hunt watch ~/.claude/projects/

# List open leaks:
token-hunt list

# Close after rotating:
token-hunt close 1 --note "rotated at console.anthropic.com"

Detection points

Hook What it sees Action on leak
UserPromptSubmit Your paste WARN (banner)
PreToolUse:Bash Command about to run BLOCK (won't run)
PostToolUse:Bash Command output WARN + log (transcript already has it)
PostToolUse:Read File contents WARN + log
PreToolUse:Edit/Write New file content BLOCK
PostToolUse:Edit/Write Echo WARN + log

The unique feature: bash escape-hatch detection

token-hunt catches patterns where bash evaluates a secret into emitted text, even when the literal secret isn't in your input:

# BLOCKED — both branches run, leaks the value:
echo ${ANTHROPIC_API_KEY:+SET}${ANTHROPIC_API_KEY:-UNSET}

# BLOCKED — direct echo of secret var:
echo $GITHUB_TOKEN

# ALLOWED — correct status-check pattern:
[ -n "$ANTHROPIC_API_KEY" ] && echo SET

No other scanner detects this class.

Configuration

Patterns layer (later extends earlier):

  1. token_hunt/patterns/builtin.toml (ships with package)
  2. ~/.token-hunt/patterns.local.toml (machine-local, gitignored)
  3. ./.token-hunt/patterns.local.toml (repo-local, gitignored)

Allowlist (test fixtures, etc.):

~/.token-hunt/allowlist.toml:

fingerprints = [
  "abc123def456...",  # SHA-256 first 16 chars of allowlisted value
]

Per-repo opt-out:

export TOKEN_HUNT_DISABLE=1

Bypass

Only the PreToolUse BLOCK hooks (Bash, Edit/Write) honor TOKEN_HUNT_ALLOW. The WARN hooks (UserPromptSubmit, PostToolUse:*) always fire — they don't block, so bypass is unnecessary.

TOKEN_HUNT_ALLOW=1 <command>  # one-shot bypass of BLOCK-level hooks (use sparingly)

Built-in providers

Dev/infra: Z.ai · Anthropic · GitHub (classic + fine-grained) · GitLab · Figma · PyPI · npm · Linear · Stripe · OpenAI · Slack

LLM inference (48 rules, 2026-10-15): OpenRouter · Groq · Together · Fireworks · Mistral · xAI · Perplexity · Hugging Face · Cerebras · Replicate · Vercel AI Gateway · NVIDIA NIM · Chutes · Requesty · Novita · Upstage · Baseten · Baidu Qianfan · fal.ai · Alibaba DashScope · Moonshot Kimi · Cohere · Scaleway · SambaNova · Nebius · AI21 · OVHcloud · FriendliAI · GMI Cloud · Crusoe · Featherless · DeepInfra · Inference.net · BytePlus

Providers whose keys are bare sk- (DeepSeek, StepFun, Moonshot, SiliconFlow, Poe, Qwen) are caught by the unattributed sk- rule; JWT-issued keys (MiniMax, DeepInfra scoped, Crusoe CLI) by the generic JWT rule. Providers with no publicly documented key format (SambaNova, Nebius, AI21, OVHcloud, FriendliAI, GMI Cloud, Crusoe, Featherless, DeepInfra, Inference.net, BytePlus) get keyword-gated opaque rules: the provider name must appear in the scanned text AND a 32+-char token must be present. Low-precision by design — the value is attribution and the rotation URL in the warn banner, not shape confidence.

token-hunt vs pat-scanner

pat-scanner is the one-command Claude Code plugin: one hook, 13 credential classes, regex matching. Install it and you're covered.

token-hunt is the engine underneath: the Python package, the CLI (scan / list / close / watch), six hooks with block-and-rotate behavior, the allowlist, and the bash escape-hatch runtime detector — the class regex can't see. Use pat-scanner when you just want the guard. Use token-hunt when you want the full scanner and the rotation workflow.

Comparison

Verified 2026-07-27. Re-check competitor claims before citing in marketing.

Tool Surface Local-only Fail-closed Escape hatch Fleet sync
token-hunt Claude Code + CLI yes yes yes v0.2
sensitive-canary Claude Code yes yes no no
ggshield Claude Code no (cloud API) no (fail-open) no no
gitleaks git + filesystem + stdin yes n/a no no

Development

pip install -e ".[dev]"
pytest                 # full suite (85 tests)
pytest --cov=token_hunt
ruff check .           # lint (line-length 100, target py310)

Python ≥ 3.10. Runtime deps: click (CLI), platformdirs (config paths), watchdog (watch mode), tomli (< 3.11 only).

Layout

src/token_hunt/    engine, regex scanner, escape-hatch detector, entropy,
                   patterns loader, allowlist, JSONL store, click CLI
plugin/            Claude Code plugin manifest + 6 hook shell scripts
tests/             unit + hook wiring + e2e tests

License

BUSL-1.1. Source-available; converts to MIT on 2030-10-12. See LICENSE.

Security

See SECURITY.md. 72-hour acknowledgment SLA.

Metadata

Release files for token-hunt 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for token-hunt 0.1.1
File Size Uploaded Provenance Actions
token_hunt-0.1.1.tar.gz 51.0 kB With provenance Details for token_hunt-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for token-hunt 0.1.1
File Interpreter ABI Platform Actions
token_hunt-0.1.1-py3-none-any.whl Python 3 none any Details for token_hunt-0.1.1-py3-none-any.whl

Total release size: 78.3 kB

Release files / token_hunt-0.1.1.tar.gz

Download URL token_hunt-0.1.1.tar.gz
Size 51.0 kB
Tags Source
SHA-256 checksum
How to use checksums
02824911d2d92853e27f2d76d37cbc22bb48a0985133d2d07e2abb1bb53b501a
BLAKE2b-256 checksum
How to use checksums
c98c87abe1c05e300045fa16c640e8521853796fc14f204d065726f8d6f46330
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / token_hunt-0.1.1-py3-none-any.whl

Download URL token_hunt-0.1.1-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a3a41486f8cbb904338bf464efdae606366a4c2a0454395ce4268bc31909465
BLAKE2b-256 checksum
How to use checksums
ed65f3c1810f5b7af544536ec6c2787fb6fc175a81c5179044c3a6d177f3890d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for token-hunt 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for token_hunt-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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