Skip to main content

Scrubber and secrets vault

zn-gate keeps secret values out of what your coding agent sends to its model: the agent sees markers; real values stay in an encrypted local vault.

View .md

zn-gate keeps secret values out of what your coding agent sends to its model. The agent works with markers such as __ZN_GITHUB_TOKEN__; the real values stay in an encrypted vault on your machine and are filled in only where you allowed them. Detection, replacement and the vault are 100% local: no cloud service, ours included, takes part.

Available in zn-gate 1.5.0 and later (npm); on Windows use 1.5.1 or later (GHSA-rf3f-ppm5-3xrx). Supported agents: Claude Code, Codex CLI, Cursor (IDE) and OpenCode. What each agent lets the hooks change differs: see compat.md and the limits in threat-model.md.

What it does

  • Scrubs what the model sees. File reads, command output, searches, MCP tool results and pasted prompts go through the scrubber before they reach the model. Known values (from the vault and your .env files), more than 60 secret formats (cloud keys, tokens, private keys, connection-string passwords) and personal data (card numbers, IBANs, DNI/NIE and SSNs with checksum validation; emails, phone numbers and IPv4 addresses) become stable markers. The same value always gets the same marker, so the model can still reason about it and the line keeps its shape: DATABASE_URL=postgres://app:__ZN_DATABASE_URL_PASSWORD__@db:5432/app. In Cursor only MCP output can be rewritten: shell and file output is not scrubbed there. A zn API key (zn_ followed by 48 characters) is recognised and hidden like other provider keys.
  • Finds phone numbers written with odd spaces. From 1.17.0, a phone number with a no-break space (U+00A0, U+202F or U+2007) or two spaces between the country code and the number, or between its groups, is detected like one with a normal space. Short numbers, dates and versions stay unflagged.
  • Blocks reads of raw credentials. .env files with real values, credential files such as ~/.aws/credentials or ~/.ssh/id_*, and zn's own ~/.zn: the hooks block the agent's tools from reading them (a guardrail, not a sandbox).
  • Keeps values in an encrypted vault. The vault is encrypted with age; its key lives in your operating system's keychain (or behind a passphrase). It never leaves your machine and is never synced. A local audit log records which secret was used where, never the values.
  • Fills values in only where you allowed them. A command you allowed gets the value through zn run, and its output is masked. HTTP APIs are called through the secrets MCP server, which sends the value only to the hosts you allowed and returns the response with secrets replaced by markers. No tool returns a value to the agent.
  • Asks you, not the agent. The first use of a secret by a program, and any change that widens a secret's policy, are confirmed in a system dialog or in the vault's own terminal. The agent cannot answer these prompts.

Get started

npm install -g zn-gate
zn unlock                         # creates the vault the first time
zn env shadow .env                # moves the values into the vault; .env keeps markers
zn hooks install claude-code      # or: codex, cursor, opencode

With the system keychain, zn unlock needs an interactive terminal from 1.10.0: it asks nothing, so it does not run from a script. With a passphrase, --passphrase-stdin still works from a pipe.

To let a command use a secret, allow that program:

zn secret allow DATABASE_URL_PASSWORD --command psql

Allow a specific program: node, python, npm, make and other interpreters run any code they are given, so allowing one lets every script it runs read the secret, and zn warns you when you do.

To add a single secret, type it at a hidden prompt, never as an argument: zn secret set GITHUB_TOKEN --host api.github.com.

The full walkthrough is in the secrets guide.

Useful commands

Command What it does
zn secret list Names, modes, hosts and commands (never values)
zn secret rm NAME Remove a secret
zn vault log Local audit log: who used which secret where, never values
zn vault verify Check that the audit log has not been altered
zn lock Lock the vault now
zn hooks uninstall <agent> Remove the hooks. For Claude Code it also removes zn's own secrets MCP server, and keeps any other server with that name

If the vault is locked, the hooks still redact what they recognise, with markers that cannot be restored (__ZN_REDACTED_AWS_KEY__), and remind you to run zn unlock.

Limits

  • The scrubber finds known values and recognisable formats. A secret with no known format that is not in the vault or a .env file can get through: move your secrets into the vault.
  • Approving a batch file (.cmd, .bat) on Windows approves that file, not the programs it starts by name. Prefer secrets_http_request for HTTP APIs, or approve the program itself.
  • While the vault is unlocked, any program running as your OS user, including a command the agent runs, can ask it for a secret by name. Lock it with zn lock when you do not need it.
  • A program you allowed holds the value and can send it anywhere: allow specific programs, use narrow-scope tokens and your agent's sandbox.
  • Some agents keep their own local copies (Codex's session log keeps the original output).
  • The Python package (PyPI) has secret redaction in its library functions (redact_secrets, sanitize_tool_result, guard), not the vault, the hooks, zn run or personal-data scrubbing.
  • Shell, PowerShell and Monitor commands over 100 KB are blocked instead of checked, because checking a command that long could take longer than the agent's hook waits. The agent is told to tell you and not to resend the command in parts.
  • In Codex and OpenCode, patches (apply_patch) over 100 KB are blocked too, for the same reason (zn-gate 1.8.1 or later).
  • MCP calls with arguments over 1 MB are blocked, because they are too large to check. The agent is told to tell you and not to resend the content in parts.

For redaction in MCP tool output and arguments only, see Secret redaction.

Open source

MIT, like the rest of zn-gate: github.com/usezn/zn. Changes are listed in the CHANGELOG.