Skip to main content

Check that it works

zn-gate check shows that zn stops your coding agent from reading a secret: a test .env file with a fake key is blocked. Nothing is sent anywhere.

View .md

After you install zn-gate for your coding agent, open a new terminal and run:

npx -y zn-gate check

(or zn-gate check if you installed it with npm install -g zn-gate).

Words used here

  • Prompt injection: hidden instructions in a file, web page or tool result that try to make your agent do something you did not ask for.
  • Hook: a small check your agent runs before an action, such as reading a file or running a command. zn uses hooks to block secrets and risky actions.
  • MCP server: a separate program that gives your agent extra tools. zn-gate can be one, or sit in front of others to check what they return.
  • Vault: zn's encrypted store for your secret values, on your machine. Files keep a marker such as __ZN_API_KEY__ in place of the value.

What it does

zn-gate makes a temporary folder with two files: a .env file that holds a fake key and an ordinary README.txt. For each agent set up for your user, it asks zn's hook to let the agent read each file, the same way your agent asks. An agent counts as protected only when the .env file is blocked and the ordinary file is allowed.

  • Claude Code: zn-gate checks the zn-gate plugin, or the hooks of zn hooks install claude-code. It also notices when the plugin is turned off and when a Claude Code setting turns hooks off. If your hooks were installed by an older zn-gate and lack the check for typed skills and commands, it suggests running zn hooks install claude-code again.
  • Codex CLI and Cursor: zn-gate checks the hooks of zn hooks install.
  • What it runs: for Claude Code, Codex CLI and Cursor it runs the hook that is installed, exactly as your agent would. A hook that cannot start, or that blocks every file because part of zn is missing, is reported as NOT protected. On Windows, a hook installed as zn hook <agent> is not started; zn-gate checks zn's rules for it instead and says so.
  • OpenCode: zn-gate checks zn's rules. The zn plugin runs inside OpenCode, so it is not started here.
  • What it leaves alone: it checks the setup for your user. A setup made for one project only is listed but not run.
  • Nothing changes: nothing is sent over the network, no agent is started and no setting changes. The run adds a few lines to your local evidence log (~/.zn/evidence.jsonl, a chained record of the decisions of the test hook), which stays on your machine. The test folder is deleted at the end.

What you will see

zn-gate check: does zn stop your coding agent from reading a secret?

  OK Claude Code  blocked the .env file and allowed the ordinary file. Your agent would be told:
     "zn: ..."
  -  Codex CLI    zn is not set up for this agent. To protect it, run `zn hooks install codex` in your own terminal.
  ...

Your agent cannot read secret files such as .env through these tools. Nothing was sent anywhere.
  • Decision time: the line after the agents gives how long zn takes to decide each tool call, as p50 and p95 of the last 100 calls on this machine. This is decision time only. It does not include process startup, writing the response to your agent, or saving stats and evidence, so it is not the whole delay your agent sees. It is measured locally and stored only as numbers in ~/.zn/stats.json. Until zn has checked a tool call, it says no data yet. With ZN_STATS=off it says that nothing is measured.
  • Hooks line: when at least one zn hook is installed, the output ends with one line about them, for example Hooks: 3 OK, 1 stale, 0 broken. Run zn-gate check --hooks for details. See List every installed hook.
  • OK: zn is protecting that agent. The quoted text is what your agent is told when it tries to read the file.
  • -: zn is not set up for that agent, or only for one project. The line gives the command that sets it up for your user.
  • X ... NOT protected: zn is set up but would not protect the agent. The line says why and what to run to fix it. For Claude Code, the zn-gate plugin together with the hooks of zn hooks install claude-code counts as not protected, because both run and a broken one can block every prompt: run zn hooks uninstall claude-code to keep only the plugin. From 1.17.0, when the installed plugin is older than zn-gate, zn-gate check and zn-gate init say so and print the three commands that move it to the current release (claude plugin marketplace remove usezn, claude plugin marketplace add usezn/zn#plugin-v1.18.0, claude plugin install zn-gate@usezn). If the plugin is the one that does not work, the fix it gives from 1.10.0 is claude plugin disable zn-gate@usezn, which keeps zn's hooks. A Claude Code or ZCode plugin hook also counts as not protected when it does not start a system shell by its full path (such as /bin/sh) on a script inside the plugin folder, because the agent looks a program name up on its own PATH before zn can check it: update the plugin with claude plugin update zn-gate@usezn, install the ZCode plugin again (Settings, Plugins), or use zn's hooks. The ZCode plugin has two hooks for every event: one starts /bin/sh (macOS and Linux) and one starts the Windows command interpreter by its full path (C:\Windows\System32\cmd.exe, Windows), which runs scripts/zn-hook.cmd. On each system only the matching one can start.

zn-gate check exits with 0 only when every agent that is set up for your user is protected.

zn-gate check also exits with 2 on an option it does not know, naming the option, instead of ignoring it. The same applies to doctor, status, version, test, evidence, logs, export, team status, scan and analyze. If a script or a CI job passed a mistyped option, it now fails with 2.

Machine-readable output

zn-gate check --json

doctor --json works too. It prints one JSON object on stdout and nothing else, built from the same check as the text output, so it is safe to use in a script, in CI or to paste into a support request. The exit code is the same as in the text form. It has no secret values, and your home folder is shown as ~.

{
  "schema": 1,
  "zn_gate_version": "1.18.0",
  "exit_code": 1,
  "protected": false,
  "agents": [
    {
      "id": "claude-code",
      "name": "Claude Code",
      "state": "not-protected",
      "protected": false,
      "reason": "its zn hook is turned off in ~/.claude/settings.json",
      "fix": "run `zn hooks install claude-code` in your own terminal"
    }
  ],
  "warnings": []
}

The example is shortened. The real object also has node_version, project_rules_errors, test_folder_removed and, for each agent, message, notes and checked.

  • schema: the version of this format. It changes only when a field is removed or changes meaning.
  • exit_code: 0 when at least one agent is set up and every agent that is set up is protected, 1 otherwise (also when a project rules file has errors). The process exits with this value.
  • agents: one entry per supported agent, with a state: protected, not-protected, not-set-up, project-only (set up for one project only) or not-found (the agent is not on this machine).
  • Per agent: protected (true only for the protected state), reason (why it is not protected, or empty) and fix (what to run, or empty).

What check writes to the decision log

The test requests go through the real zn hooks, so they are recorded like any other decision. For each agent whose hook runs, the blocked request for the fake .env file is added to your local decision log (evidence.jsonl in the .zn folder, or in the folder ZN_HOME names). The request for the ordinary file is allowed and is not logged. One zn-gate check can therefore add one record per agent whose hook ran, each with the agent, the read tool and the verdict block.

  • They stay on your machine. Like the rest of the log, they are never sent anywhere.
  • They look like real blocks. zn does not mark them as test records, and the preview in the record holds only the event and the tool, not the folder or the fake key. You can tell them apart by their time: they are written within a few seconds of each other, at the moment you ran the check.
  • zn why can explain one. With no id, zn why explains the last block in the log. If you ran the check after your last real block, that is one of these test records.
  • Nothing else is added. No setting changes, and the fake key is not stored.

Agent versions

Under each agent it finds, zn-gate check shows the version of that agent on your machine and the version zn-gate was last tested with, and says plainly when yours is newer or older. A version it cannot read is shown as version: not found, which is not an error. To read the version it runs only <agent> --version with a 2-second limit, and it changes nothing and sends nothing.

List every installed hook

zn-gate check --hooks

doctor --hooks works too. It lists every zn hook set up for your agents, one line per hook event, and says whether each one is working. It only reads your agents' settings files and zn's launcher files: it runs no hook, changes nothing and sends nothing. It looks at the settings for your user and, in the folder you run it from, at the project settings.

Here is a run on a test machine with two fictional setups: a Claude Code hook whose launcher was written by an older zn-gate, and a Codex hook whose launcher file was removed. The home folder is shown as ~.

zn hooks installed on this machine (nothing was run or changed):

Claude Code (user): ~/.claude/settings.json
  STALE  PreToolUse [^(Bash|PowerShell|Monitor|Read|Grep|LSP|Edit|MultiEdit|Write|NotebookEdit|WebFetch)$|^mcp__.*]  '~/.zn/hooks/zn-hook-claude-code.sh' PreToolUse
  STALE: the launcher records the zn-gate runner but not the other files the hook loads, so a change to one of them would not be seen: run `zn hooks install claude-code` to record them.
    Fix: run `zn hooks install claude-code` in your own terminal.

Codex CLI (user): ~/.codex/hooks.json
  BROKEN PreToolUse [^(Bash|apply_patch|mcp__.+)$]  '~/.zn/hooks/zn-hook-codex.sh' PreToolUse
  BROKEN: its hook cannot start: its launcher script (~/.zn/hooks/zn-hook-codex.sh) is missing or was changed.
    Fix: run `zn hooks install codex` in your own terminal.

0 OK, 1 stale, 1 broken.
To remove the hooks of an agent instead, run `zn hooks uninstall <agent>`.

How to read it:

  • The first line of each block names the agent, whether the hook is in your user settings (user) or in the project settings (project), and the settings file it was read from.
  • Each hook gets one line: its status, the event, the matcher in brackets (the pattern of tool names the hook applies to), and the command the agent runs.
  • A line that is not OK is followed by the reason and the Fix: line. Run the fix in your own terminal, then run zn-gate check --hooks again.
  • The last line counts the hooks: X OK, Y stale, Z broken.

The three statuses:

  • OK: the hook points at files that exist, and its launcher is the one this zn-gate writes.
  • STALE: the hook still works but was written by an older zn-gate, or runs an older copy of it. Run the fix to bring it up to date.
  • BROKEN: the hook cannot run, is turned off, is written twice for the same event, points at a file or Node.js that is gone, or is in a settings file zn cannot read. Run the fix; if the settings file is not valid JSON, repair it first. If you no longer want zn for that agent, run zn hooks uninstall <agent> instead.

The exit code of check --hooks is 0 when every hook is OK (or none is set up) and 1 when any is stale or broken. For a test that zn really blocks a secret, run zn-gate check without --hooks.

Run it after zn hooks install <agent>, after you upgrade zn-gate, after you change or remove Node.js, or when zn-gate check reports an agent as NOT protected and you want to see which hook is at fault. It is safe to run at any time.

What each NOT protected line means

A line that starts with X and says NOT protected gives one reason and one repair. Run the repair in your own terminal, then run npx -y zn-gate check again. The usual reasons:

  • The read check is missing: zn's hooks are installed for that agent, but not the one that runs before a file is read. Run zn hooks install <agent> again.
  • The Node.js or the zn-gate files the hook uses are gone, usually after you removed or upgraded Node.js with a version manager such as nvm: run npm install -g zn-gate, then zn hooks install <agent>.
  • The launcher script of the hook is gone or was changed: run zn hooks install <agent> again. On macOS and Linux, and for Claude Code on Windows, the launcher runs zn-gate's hook runner only while that file still has the SHA-256 recorded at install time, and never a zn found on your PATH. If the zn-gate files changed after the hooks were installed, the hook blocks tool calls and prompts and says that zn-gate changed since the hooks were installed. npm update -g zn-gate refreshes the launchers by itself, except with --ignore-scripts. After an edit, or after an update that did not run install scripts, run zn hooks install <agent> again in your own terminal. At install, the launcher records the SHA-256 of the runner and of every other file the hook loads (the code and data under lib/, package.json and bin/cli.js), and stops the hook if one of them was edited, is not in the list or is a link. zn-gate check names up to three changed files. A launcher written by an older zn-gate records only the runner: the check adds a note, and zn hooks install <agent> records the rest. If the update ran with pnpm, bun, --ignore-scripts or sudo, run zn hooks install <agent> again too.
  • The static launcher program of the hook is gone (Linux): the Claude Code and ZCode hooks start a small program, ~/.zn/hooks/zn-hook-launcher, that zn hooks install <agent> copies there. If it was deleted or is no longer executable, the agent cannot start the hook and the line reads its hook cannot start: its launcher program (<path>) is missing: run zn hooks install <agent> again.
  • A project hook is a bare zn hook <agent>, or is not exactly the guard zn writes: where zn or Node.js cannot start, the agent would run the call unchecked. Run zn hooks install <agent> --project again in that project to replace it with the guard that blocks instead. When the agent is set up for your user, this shows as a note under OK.
  • The hook calls zn, and there is no zn on your PATH, for example because you ran zn-gate only with npx: run npm install -g zn-gate.
  • The hook started but failed, or zn's own rules let the fake .env through: reinstall zn-gate and the hooks as above.

The full list is in the zn-gate documentation on GitHub.

If your agent needs a value from .env

zn blocks the file because it holds secret values. To let your agent use them without seeing them, move the values into zn's vault:

zn env shadow .env

The file keeps markers such as __ZN_API_KEY__ instead of the values, and zn puts the real values back only in the commands you allow. More: the vault.

If your agent blocks every prompt

When zn's hook cannot run, Claude Code 2.1.295 or later (with the zn-gate plugin or zn hooks install), Cursor and OpenCode block prompts instead of letting them through unchecked. This usually happens after Node.js is upgraded, moved or removed (for example with nvm), because the hook points to the old one. Codex CLI lets prompts through in that case. To fix it, in your own terminal:

  1. Run npx -y zn-gate check. It names each agent that is not protected and the command that fixes it.
  2. Usually that is npm install -g zn-gate, then zn hooks install <agent>. With the zn-gate plugin for Claude Code, start a new Claude Code session after fixing Node.js.
  3. If you need your agent right away, turn zn off for it until you have fixed it: npx -y zn-gate hooks uninstall <agent> (the zn command may be gone with the old Node.js), or claude plugin disable zn-gate@usezn for the plugin (or /plugin inside Claude Code). Turn it back on with zn hooks install <agent> or claude plugin enable zn-gate@usezn, then run zn-gate check again.

More about updates and Node.js changes: Upgrading zn-gate.

  • zn-gate test runs zn's built-in rule self-test (51 examples). It checks the rules, not your agent setup.
  • zn-gate status shows the active detection engine and whether the optional cloud check is on, and whether a key was saved by zn-gate connect (never the key itself). Sharing of usage statistics is off by default and has its own status: zn-gate stats share status.