Skip to main content

zn-gate for Claude Code

Install the zn-gate plugin for Claude Code: it blocks reads of .env files with real values, scrubs tool output and blocks secrets pasted into prompts.

View .md

zn-gate needs Node.js 18 or later; the Claude Code plugin needs Node.js 20.19 or later. You also need Git and Claude Code 2.1.295 or later. Paste each line in a terminal and press Enter after each one:

claude plugin marketplace add usezn/zn#plugin-v1.18.0
claude plugin install zn-gate@usezn

The marketplace is added at the plugin tag plugin-v1.18.0, which is created on the commit that pins zn-gate 1.18.0 and never moves. To confirm that the tag exists before you add it, run git ls-remote https://github.com/usezn/zn refs/tags/plugin-v1.18.0.

If your Node.js is older than 20.19, zn-gate init does not install the plugin: it sets up zn's hooks for Claude Code instead and says so in one line, and zn-gate check reports an installed plugin on such a Node.js with the way out.

Then start a new Claude Code session.

The plugin does not update by itself. To move to a newer release, run claude plugin marketplace remove usezn, claude plugin marketplace add usezn/zn#plugin-v1.18.0 again, and claude plugin install zn-gate@usezn, then start a new session. zn-gate check tells you when the plugin is older than zn-gate.

Already ran zn hooks install claude-code before? Run zn hooks uninstall claude-code first, otherwise both sets of hooks run.

What you get

  • Claude Code is blocked from reading .env files with real values and credential files.
  • Secrets in what its tools return are replaced with markers or redacted before the model sees them.
  • A secret pasted into a prompt is blocked.
  • Claude can check untrusted text for prompt injection.
  • Typed skills and commands (from 1.13.0): zn also checks what a skill or command expands into, with a UserPromptExpansion hook. It blocks the expansion, with the reason and the next step, when it would show the model a secret value, a private key or the lines of a .env file; if the hook cannot run, the expansion is blocked. The plugin has it already; with zn's hooks, run npx -y zn-gate hooks install claude-code again to add it.

Not covered: Claude Code sessions in the cloud, Cowork and chat.

If the zn hook cannot run (for example, node is missing) or does not answer in time, tool calls, prompts and typed-command expansions are blocked. After a tool has run, its output then reaches the model without zn's scrubbing.

Keep your .env values in the vault

The agent cannot read .env files with real values. Move the values into zn-gate's encrypted vault, and the file keeps markers such as __ZN_STRIPE_KEY__:

npx -y zn-gate unlock            # creates the vault the first time
npx -y zn-gate env shadow .env

After this your own app also reads the markers: start it with zn-gate's run command once you allow it. env shadow tells you how to undo it. More: the vault.

Check that it works

In a new terminal, run npx -y zn-gate check. It should show OK for Claude Code. What the output means.

On Windows PowerShell, if npm or npx says "running scripts is disabled on this system", use npx.cmd instead of npx: see Install.

Further reading