How zn-gate works
Where zn-gate sits in a tool call, what each piece does today, and what it does not do.
This page explains how zn-gate works inside. Just want to protect your coding agent? Open your own terminal (not the agent's chat), run
npx -y zn-gate init, thennpx -y zn-gate check. Step by step: Install.
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.
More words are in the Glossary.
Where it sits
zn-gate runs on your machine, between your agent and the tools and content it touches. It works in three ways, and you can combine them:
- As agent hooks (the Claude Code plugin, or
zn hooks install codex,cursororopencode). They also act on the agent's built-in tools: they block reads of.envfiles with real values and of credential files, replace secrets in tool output before the model sees it, and block a secret pasted into a prompt. In Cursor, only MCP tool output is scrubbed. See the Quickstart. - As an MCP server (
npx -y zn-gate mcp). Your agent calls its tools:analyze_prompt,check_tool_call,check_tool_resultandzn_status. See MCP clients. - As a proxy around other MCP servers (
zn-gate shield, orzn-gate init --wrap-mcpto wrap them all). Every call and every result passes through zn-gate without the agent having to ask. See Protect MCP servers.
For a tool call, that means:
- Before the tool runs, the arguments are checked for injection, exfiltration patterns and sensitive paths. A blocked call never reaches the tool. (
check_tool_callalso returns the arguments with secrets masked, for logging.) - The tool runs.
- Before the agent reads the output, it is checked for indirect prompt injection and secrets are redacted. If it carries an injection, it is neutralized instead.
The three pieces
| Piece | What it does today | Where it runs |
|---|---|---|
| Scrubber | Replaces secrets with markers in MCP tool output and arguments and, with the hooks (npm), in the agent's file reads, command output and prompts; values stay in an encrypted local vault (details) | Locally, always |
| Galvanize | Deterministic rules with normalization against homoglyphs, zero-width characters, BiDi overrides, comment splicing and Base64 (it decodes Base64 in shell commands that pipe it to base64 -d; Base64 text pasted in a prompt or tool output is not decoded). Checks prompts, tool arguments, tool output and MCP tool descriptions |
Locally. Optional cloud second opinion for prompts with the Galvanize 3.1 model |
| Scan | zn-gate scan <path> audits prompt templates, AGENTS.md / SKILL.md files and configs for injection traps and leaked secrets, with exit code 1 on findings, and lists the files it does not read, and can print text, JSON or GitHub annotations with the rule, the reason and the location, never the matched text |
Locally, and in CI |
The Scrubber and the encrypted secrets vault (zn-gate 1.5 and later) are described in Scrubber.
Verdicts and modes
allow: nothing detected. Proceed, with secrets redacted.block: do not run the tool call, or do not feed the text to the model. Results that carry an injection are replaced by a short notice.
Every result names the rule and reason that decided it, so decisions can be logged and debugged. zn-gate shield records each decision in a local audit log.
When you roll zn-gate out, start in shadow mode (zn-gate init --shadow or zn-gate shield --shadow): decisions are logged but traffic is not altered.
Local or cloud?
Everything above is local, free and open source (MIT). The optional zn Cloud API adds Galvanize 3.1, a prompt-injection classifier, as a second opinion on prompts. Tool arguments are never sent. Tool output is not sent either, except for one opt-in setting in Claude Code (cloudCheckToolOutput, off by default) that sends a capped, redacted sample. See What leaves your machine.
What it does not do
- An MCP server alone does not see the agent's built-in tools. For example, a native file read in Claude Code is not seen by an MCP server; the plugin and the hooks cover those tools (in Cursor, only MCP tool output is scrubbed).
- It is not a semantic classifier. The local engine is a signature and normalization layer: fast and explainable, but paraphrased attacks can get through. On whole source files it currently produces false positives on ordinary code comments; until that is fixed, use
check_tool_resultfor web and third-party content rather than your own repository files. - It is one boundary, not your whole security model. Keep least-privilege tool scopes, authorization and human review for high-impact actions.