Tokenhush is a local secret-redaction gateway for AI coding tools. It sits between AI coding tools and vendor APIs, replacing detected sensitive information before requests leave the local machine and restoring the original values when responses return, so the model can only see placeholders.
Purpose: To do their work, AI coding tools read large amounts of code, configuration, and secrets, and this content may be sent externally with requests. Tokenhush adds a checkpoint in front of the tools: it reads each request, replaces content suspected to be secrets, and then forwards the cleaned version, thereby reducing the risk of secret leakage.
Main capabilities:
- Reversible redaction: each detected secret becomes a session-level placeholder PII<type>_<digest>_ in the request body, and is restored to the original value when the response returns.
- Built-in detectors: prefix (known secret forms such as sk-, AKIA, ghp_, glpat-, xox*, AIza, npm_), jwt, pem (PEM private key headers), luhn (Luhn-validated card numbers), and email are enabled by default; entropy (high-entropy strings) is disabled by default and must be enabled manually according to the workload.
- Deep traversal: traverses the entire outbound JSON request body, so secrets in nested objects and arrays are also identified.
- Response buffering: responses (including SSE streams) are first fully buffered and decoded, and then placeholders are restored; output is not streamed token by token.
- Loopback-only listening: binds to 127.0.0.1, and additionally to [::1] when the host has an IPv6 loopback; it does not terminate TLS, does not install a root certificate, and does not perform MITM.
- Tool adaptation: tokenhush env <tool> outputs directly pasteable base-URL snippets for 14 tools: claude, codex, aider, cline, roo, opencode, qwen, crush, zed, continue, openwebui, goose, openhands, and kilo.
- Rule extension: supports Ed25519-signed rule pack synchronization (tokenhush rules sync), with anti-weakening floors that reject rule packs that disable built-in detectors, drop required categories, carry allow actions, or set the email replace flag; supports declaring sensitive key names (such as password), whose values are redacted at any object depth; supports compile-time plugins that implement the Rule interface in pkg/filter.
- Security checks: always checks the Host header, checks Origin for browser-style requests, uses a per-run generated bearer token with permissions 0600 for the control API, and fails closed rather than allowing traffic through on failure.
Usage:
- Install: the Linux and Windows installers resolve the release version, download the corresponding archive, verify sha256 with checksums.txt, and install to the user directory (Linux: ~/.local/bin, Windows: %LOCALAPPDATA%\Programs\tokenhush), with no administrator privileges or package manager required; you can pin a version with --version X.Y.Z (Linux) or -Version X.Y.Z (Windows). macOS tracks the latest release via cask. You can also build it yourself, using @main rather than @latest.
- Start the gateway: run tokenhush run, which by default listens on http://127.0.0.1:8787,前台运行,Ctrl-C to exit; on startup it prints the loopback endpoint, the effective upstream routes, and the two base-URL forms.
- Configure tools: Anthropic-style clients use the bare origin http://127.0.0.1:8787;OpenAI compatible clients use http://127.0.0.1:8787/v1。
- Route upstream: when unconfigured, the OpenAI-compatible path is forwarded to https://api.openai.com,Anthropic path is forwarded to https://api.anthropic.com;使用中转或其他端点时,需在配置目录创建 tokenhush.yaml (or specified via tokenhush run --config PATH), fill in the provider origin address (including the prefix before /v1, without a trailing slash and without /v1). API keys remain in the tool's own configuration; the gateway forwards authentication headers as-is and only redacts the request body. Routing matches by request path rather than provider name; one path maps to one upstream.
Verification: run tokenhush run and observe stderr; at startup it prints the endpoint and routes, each redaction outputs one line of masked log (including detector type, matched byte length, and mask form, without the full value), each response restoration outputs one line of count, and locally generated request-side rejections output one line with the rejection code. tokenhush status --json reports redaction counts as JSON. You can also run a local echo upstream at 127.0.0.1:9999 for a full round-trip verification.
Use cases: developers who use AI coding tools and want to reduce secrets and PII in the codebase being sent out with requests; clients that need to be compatible with OpenAI- or Anthropic-style base URLs; scenarios that want local protection deployed as a single binary without administrator privileges.
Limitations and notes:
- The gateway sees secrets in-process and in memory, because it must read the request body to replace them; but it does not persist request bodies, response bodies, detected secrets, or placeholder mappings, and redaction logs are output only in masked form to stderr.
- Only metadata files are written: run.json (pid, port, addrs, started_at), a 0600 control token, a verified rules cache, and an update anti-rollback marker.
- Performance overhead data is not yet available; any specific numbers are unverified.
- The data path is local, but the provider itself requires network access; Tokenhush's only two outbound requests (update check, rules sync) can both be disabled, and there is no telemetry by default.
- The entropy detector is disabled by default, because its false positives on long tool names and session IDs in real proxy traffic would break function calls; enable it only when the workload contains no images, data URLs, or long random identifiers.
- Rule packs are loaded on the next startup and do not support hot reloading; if loading fails, it falls back to built-in defaults with a warning.
- Container values and k8s/docker-env sibling forms are not yet matched; see the documentation for details.
- Placeholders are restored only on the response path and are not filled back in on the outbound direction, so that clients can obtain the original values.