Skip to main content

How zn-gate works

Where zn-gate sits in a tool call, what each piece does today, and what it does not do.

View .md

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, then npx -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, cursor or opencode). They also act on the agent's built-in tools: they block reads of .env files 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_result and zn_status. See MCP clients.
  • As a proxy around other MCP servers (zn-gate shield, or zn-gate init --wrap-mcp to 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:

  1. Before the tool runs, the arguments are checked for injection, exfiltration patterns and sensitive paths. A blocked call never reaches the tool. (check_tool_call also returns the arguments with secrets masked, for logging.)
  2. The tool runs.
  3. 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.
Sequence diagram. The agent sends analyze_prompt to zn-gate on your machine, which allows or blocks it. Then check_tool_call, which allows the call with secrets masked or blocks it. The agent runs the tool. The output comes back through check_tool_result or shield, and zn-gate returns it with secrets redacted, or neutralized if it carries an injection.

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_result for 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.