TokenHound

v1.0.1
io.github.aiagentpro/tokenhound Checked 4 days ago Published 7 days ago

Find leaked AI keys, verify them read-only and price the exposure.

Find the AI keys your coding agents have spread, see which are live and what they cost, and stop them going public. Works with Claude Code · Codex · Cursor · VS Code · GitHub Actions · git hooks and pre-commit English · 简体中文 · 日本語 · 한국어 · Español · Português (Brasil) · Deutsch · Français

Summary extracted from the README.

$ npx tokenhound

  2 live keys, $29,227.68 a day at risk, grade F

  LIVE  OpenAI     sk-pro...TEST (56)   $28,800/day  .env:1
  LIVE  Groq       gsk_m3...TEST (56)   $427.68/day  app.py:2
  DEAD  Anthropic  sk-ant...H-AA (108)           $0  .env:2

  Why F: In repo app: 2 live keys, $29,227.68 a day at risk, at or over the $500.00 threshold.
  Next:  tokenhound fix th_676a05fa4d1c9bb1

Example output on synthetic test keys. Keys are only ever shown redacted.

Quickstart

npx tokenhound                                  # scan this machine's agent files and the current repo
npx tokenhound fix <finding-id>                 # step-by-step fix plan for one key
npx tokenhound hook install --claude-code --command "npx tokenhound"   # block live and high-confidence keys before Claude Code writes or runs them

--command "npx tokenhound" makes the hook run TokenHound through npx, so it works without an install. Once TokenHound is installed (Install), run tokenhound hook install --claude-code instead and the hook uses that binary.

No account, no sign-up and no telemetry. Prefer Homebrew, pip, Docker or Go? See Install.

What you get

Coding agents copy API keys into config files, .env files, notebooks, shell history and session transcripts. TokenHound is a scanner, run on your own machine, built to find them:

  • Find the AI provider keys your agents have spread: in the files of Claude Code, Codex, Cursor, Gemini CLI, Windsurf and more on this machine (full list), in Claude Code and Codex session transcripts, and in your repositories, with --history their full git history too.
  • Prove which keys still work, with one read-only call per key to its own provider, how many dollars per day each one puts at risk, and an A to F grade for every repository and machine. The live or dead check covers the 14 providers that support it.
  • Prevent new leaks: the Claude Code hook blocks live and high-confidence keys before Claude Code writes or runs them. High-confidence means a strong match that is not verified yet (policy). Git hooks and the GitHub Action fail a commit, push or pull request that adds a live key; to fail on unverified keys too, add not-verified, unknown and rate-limited to fail_on.status.
  • Fix each one with a plan you can paste (tokenhound fix <id>): revoke the key on the provider's revoke page, replace it everywhere it is used (with the usual environment variable name), purge it from git history when it was committed, and check usage for abuse.

Why not just ask your agent?

"Check this repo for leaked API keys" is a reasonable prompt, but it can't do this job:

Asking your agent TokenHound
The keys themselves The agent has to read every key it checks, so each one lands in its context, its transcript and the model provider's logs. Looking for a leak makes another one. Redacts each key as it reads it. No key ever reaches a model.
Where it looks The project it is working in, with grep. The config files of Claude Code, Codex, Cursor, Gemini CLI, Windsurf and more, Claude Code and Codex transcripts and shell history on the machine, plus repositories (with --history, their full git history), decoding base64, URL encoding, JSON escapes and notebooks.
Live or dead Has to curl the key itself, which logs it again, and guess a safe endpoint. One read-only call per key to a vetted endpoint from the registry, for the 14 providers that support it.
What is at risk No way to know. Dollars at risk per day and an A to F grade.
Same answer twice Varies from run to run; "looks clean" proves nothing. Deterministic, with results published on an open benchmark.
New leaks Caught only when someone remembers to ask. The Claude Code hook blocks live and high-confidence keys before they are written or run; git hooks and the GitHub Action fail commits and pull requests that add a live key.
Cost Tokens and minutes for every scan. Seconds, free, and fully offline with --no-verify.

You can still use your agent: the MCP server and agent skill let it run TokenHound and get back redacted results instead of raw keys.

Benchmark

The open agent leak benchmark plants generated AI keys, and decoys that only look like keys, in the places coding agents leave them, then runs each scanner over the same files.

Of 1,047 AI keys hidden in agent files, repository files, git history, encoded values and notebooks, TokenHound found 1,047, gitleaks 825 and TruffleHog 440.

Tool Keys found Keys missed False alarms
TokenHound 1,047 of 1,047 (100%) 0 39
gitleaks 825 of 1,047 (79%) 222 203
TruffleHog 440 of 1,047 (42%) 607 8

The test keys are generated from TokenHound's own patterns, which favours TokenHound at finding them; read the method before comparing.

Each row is a tool at its default config: the tuned gitleaks and TruffleHog configs found no extra keys, so they get no rows of their own. Not compared yet: GitHub secret scanning.

What these numbers mean:

  • Keys found: of the 1,047 keys planted, how many the tool reported. A missed key is a leak you never hear about, so this is the number that matters most.
  • False alarm: an alert on something that was not a key (the test also holds 1,175 look-alike decoys). A false alarm costs you a moment to check and dismiss.

Where others do better: TruffleHog raises fewer false alarms (8 against TokenHound's 39), but it found only 440 of the 1,047 keys (42%).

TokenHound's live or dead check gave the right answer for 534 of the 534 keys it checked (against the benchmark's stand-in for the provider APIs, not real providers).

Run on 2026-11-19 with the open agent leak benchmark against TokenHound commit b6aa45ed4bc9, seed 20261119. Full technical results, with precision and recall per category, the tuned configs and every place TokenHound scores lower: RESULTS.md; summary: summary.json; data: docs/benchmark/results.json.

How the benchmark is built and kept in sync with this page: docs/benchmark.md.

What it scans

  • Your coding agents' files on this machine: Claude Code settings and transcripts, Codex, Cursor, Gemini CLI, Windsurf, Claude Desktop, VS Code MCP config, Jupyter, .npmrc and friends, and Bash, Zsh, Fish and PowerShell history.
  • Repositories: the working tree, staged changes and, with --history, every commit, including keys hidden in base64, URL encoding, JSON escapes and notebooks.
  • Standard input, single files and saved reports.
Agent surface Files read (macOS paths)
Claude Code ~/.claude/settings.json, ~/.claude/settings.local.json, ~/.claude.json, **/.claude/settings.local.json, ~/.claude/projects/**/*.jsonl
Claude Desktop ~/Library/Application Support/Claude/claude_desktop_config.json
Codex ~/.codex/config.toml, ~/.codex/auth.json, ~/.codex/sessions/**/*.jsonl
Cursor ~/.cursor/mcp.json, **/.cursor/mcp.json, ~/Library/Application Support/Cursor/User/settings.json
dotenv files **/.env, **/.env.*
Gemini CLI ~/.gemini/settings.json, **/.gemini/settings.json
Gemini CLI .env ~/.gemini/.env, **/.gemini/.env
Jupyter notebooks **/.ipynb_checkpoints/*.ipynb
Jupyter config ~/.jupyter/*.json, **/.jupyter/*.json
npmrc, yarnrc and pypirc ~/.npmrc, **/.npmrc, ~/.yarnrc, **/.yarnrc, ~/.pypirc, **/.pypirc
Bash history ~/.bash_history
Fish history ~/.local/share/fish/fish_history
PowerShell history ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt
Zsh history ~/.zsh_history, ~/.zhistory
VS Code MCP ~/Library/Application Support/Code/User/mcp.json, ~/Library/Application Support/Code/User/settings.json, **/.vscode/mcp.json, **/.vscode/settings.json
Windsurf ~/.codeium/windsurf/mcp_config.json

macOS paths shown; Linux and Windows: tokenhound providers --surfaces and docs/surfaces.md.

Verified live or dead (14) Detected (12)
Anthropic, AWS (Amazon Bedrock), Azure OpenAI, Cohere, DeepSeek, Google Gemini, Google Vertex AI, Groq, Hugging Face, Mistral AI, OpenAI, OpenRouter, Perplexity, xAI Cerebras, ElevenLabs, Fireworks AI, Helicone, Jina AI, Langfuse, LangSmith, Pinecone, Replicate, Stability AI, Together AI, Voyage AI

tokenhound providers lists every provider and detector in your binary. Missing one? Add it in 10 minutes.

How it is different

TokenHound General secret scanners
Reads coding agent files and transcripts on your machine Built in Point them at the paths yourself
Live or dead check Read-only call per key Varies by tool and detector
Dollars at risk per day and an A to F grade Yes No
Blocks live and high-confidence keys in agent tool calls before they run Claude Code hook Not built in
Fix plan with revoke, replace, purge and usage-check steps Yes No

TokenHound is focused on AI provider keys. Keep your general secret scanner for everything else; the two work side by side.

Install

Channel Command Platforms
npm (no install) npx tokenhound macOS, Linux and Windows; amd64 and arm64
PyPI uvx tokenhound, pipx run tokenhound or pip install tokenhound macOS, Linux and Windows; amd64 and arm64
Homebrew brew install aiagentpro/tap/tokenhound macOS and Linux; amd64 and arm64
Scoop scoop bucket add aiagentpro https://github.com/aiagentpro/scoop-bucket then scoop install tokenhound Windows; amd64 and arm64
Docker docker run --rm -v "$PWD:/src" ghcr.io/aiagentpro/tokenhound scan /src Linux; amd64 and arm64
Go go install github.com/aiagentpro/tokenhound/cmd/tokenhound@latest macOS, Linux and Windows; amd64 and arm64
GitHub Action uses: aiagentpro/tokenhound/dist/github-action@v1.0.1 macOS, Linux and Windows; amd64 and arm64
Binaries Releases, with checksums.txt and its cosign bundle macOS, Linux and Windows; amd64 and arm64

Every release is built reproducibly and ships with a cosign-signed checksums.txt and an SPDX SBOM per archive; npm and PyPI packages carry provenance. How to verify a download: docs/releasing.md.

Every command, flag, output format and exit code: docs/cli.md. Config file and environment variables: docs/configuration.md. Go library: docs/library.md.

MCP server and agent skill

claude mcp add tokenhound -- tokenhound mcp

The MCP server gives any agent scan, verify_status, fix_plan and report tools that only ever return redacted keys. Setup for Codex, Cursor, Claude Desktop and VS Code: docs/mcp.md. The agent skill teaches Claude Code, Codex and Cursor when and how to run TokenHound: docs/skill.md.

CI and hooks

GitHub Action

Fail pull requests that add a live AI key, with one updated PR comment, line annotations and SARIF in code scanning:

on: pull_request
permissions:
  contents: read
jobs:
  tokenhound:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write    # the PR comment
      security-events: write  # the SARIF upload
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - uses: aiagentpro/tokenhound/dist/github-action@v1.0.1
        with:
          new-only: true      # fail only on keys that are not in the baseline

Without new-only, the step fails on every live key it finds in the checkout, not only the ones the pull request adds. Pin both actions by commit SHA in production. Inputs and outputs: dist/github-action. Other CI systems run tokenhound scan --format sarif or --format json and use the exit code.

Hooks

tokenhound hook install --claude-code   # Claude Code: PreToolUse hook plus a session-end scan
tokenhound hook install --pre-commit    # git pre-commit (or --pre-push)

The git hooks fail a commit or push that adds a key matching fail_on, by default a live key; add not-verified, unknown and rate-limited to fail_on.status to fail on unverified keys too (docs/hooks/git.md). The pre-commit framework, husky and lefthook are supported too: see docs/hooks.

What it prevents and what it does not

The Claude Code hook prevents live and high-confidence keys in Bash commands, file writes, edits, notebook edits and MCP calls from running or being written, and keeps a blocked command from being saved to Claude Code's "don't ask again" allowlist.

It does not see:

  • keys the agent reads into its context (for example by opening a .env file);
  • keys pasted into a prompt;
  • warned keys (dead or lower-confidence) that the user lets through, including with "don't ask again";
  • anything with hook.mode: warn, which only warns.

The session-end scan reports keys like these after the session, when they end up in Claude Code's settings files or the session's transcript. It reports; it does not prevent. Full policy: docs/hooks/policy.md.

Privacy and safety

TokenHound runs on your machine. It sends nothing anywhere except the one read-only verify call per key to that key's own provider, and none with --no-verify. There is no telemetry, no account and no phone-home. Raw keys are held only in memory during the scan and never appear in any output, log or report.

How verification stays safe

  • Each key gets one read-only call to its own provider (GET/HEAD, or a POST documented as side-effect free), never a generation, billing or write call.
  • TokenHound never revokes a key and never calls a revoke URL. fix --open only opens the revoke page in your browser.
  • Verify calls go only to the provider host in the registry, through your proxy and CA bundle if you set them. --no-verify makes no network call at all.
  • No output, log, report or error ever holds more than the redacted form sk-pro...a1b2 (51). A leak test checks every output format on every build.

Details: docs/verification.md.

Contributing

Add a provider in 10 minutes: providers are one YAML file each. Copy registry/providers/_template.yaml, fill in the pattern and the read-only verify call, run make registry-test, and open a pull request. Everything else, including how to run every CI gate locally with make ci, is in CONTRIBUTING.md.

How TokenHound works inside, for contributors: architecture rules, detection, spend model and threat model. Providers and agent surfaces are YAML data in registry/, not code.

Community

Licence

Code: Apache License 2.0. Registry data in registry/: CC0 1.0, public domain. See NOTICE.

Star history