How it works

How Tokenhush works

Tokenhush is a local base-URL gateway. Point an AI coding tool at 127.0.0.1 instead of a provider endpoint, and every request passes through one local gate: detected values are replaced before the request goes out, and restored only on the way back to the client.

The path of one request

The gateway sits between your tool and the model provider. It reads each outbound request in full, rewrites detected values as placeholders, and keeps the placeholder mapping local to the session.

Tokenhush request flowA request from an AI coding tool goes to the local Tokenhush gateway, where detected values are replaced with placeholders before the request is forwarded to the model provider. The response returns with placeholders, which are back-filled with original values only on the path to the client. Metadata-only records stay in the local audit store.Your AI coding toolone base-URL changeTokenhush local gateway127.0.0.1 + [::1]Detect & replacematches become placeholdersBack-fill (inbound only)placeholders return as originalsModel providergets the redacted bodyLocal audit (metadata only)12 redacted request3 response with placeholders4
One request, one local gate: the outbound path is redacted before it leaves, and back-fill only ever runs on the response path back to your tool.
  1. Outbound request

    The gateway reads the full JSON body and walks every leaf, running all six detectors. Each match becomes a session-scoped placeholder such as__PII_email_9f2c8a4b6d1e__. The redacted body is forwarded upstream.

  2. Upstream

    The provider receives the redacted request body, with placeholders where matches were found. Values the detectors did not flag still travel as they normally would, which is why detector quality is the honest boundary of the tool.

  3. Inbound response

    Placeholders that come back are replaced with the original values, and only on the path to the client. Streaming responses are handled incrementally, including placeholders split across chunk boundaries.

  4. Local audit

    Each request appends a metadata-only record to a local store: provider, path, byte counts, detector hits. Content is not recorded unless you explicitly opt in, and records are chained with an HMAC so tampering is detectable.

The outbound-never-back-fill invariant

Outbound requests are never back-filled with original values.

Back-fill runs in exactly one direction: responses returned to the client. That is the hard invariant behind the placeholder mapping, and the public core locks it with named tests.

The invariant closes a specific attack path. Prompt injection can try to make a coding tool echo a stored secret into a new outbound request. If the gateway replaced placeholders on the way out, that request would carry the original value to the model. Because back-fill is inbound-only, a placeholder that appears in an outbound body stays a placeholder.

What the six detectors cover

Detection is deliberately deterministic: rules that are cheap, explainable, and tunable. No model calls, no semantic guessing.

Secret prefixes
Known key shapes such as sk-, AKIA, or ghp_.
High-entropy strings
Long random-looking tokens that do not carry a named prefix.
JSON Web Tokens
Three-part signed tokens, recognized by structure.
PEM private-key headers
Private-key material pasted into a prompt or file.
Payment card numbers
Candidate numbers confirmed with the Luhn checksum, not digit count alone.
Email addresses
Common PII that tends to appear in prompts, diffs, and logs.

Beyond the built-in rules, the core exposes two extension paths: an allowlist for literals that must never be redacted, and content plugins (Inspector and Transformer) that run inside the pipeline. V1 supports compile-time plugins only, as described in thepublic plugin documentation.

Where the gateway fits

Coverage starts with any tool that accepts a custom base URL or endpoint: the CLI and IDE tools listed in the public README. Tools that do not expose that setting, such as some IDE agents, desktop chat apps, and browser UIs, are outside the public core's scope. It installs no root certificate and performs no system-level interception.

Traffic from your tool to the gateway stays on the loopback interface. Traffic from the gateway to the provider goes out over HTTPS, carrying the redacted request body.

Public sources

This page summarizes material published in the open-source core: