Configuration
Environment variables, command-line flags and custom rules for zn-gate.
zn-gate works with no configuration. Everything below is optional.
Environment variables
| Variable | Default | Effect |
|---|---|---|
ZN_CLOUD |
off | 1 lets prompt analysis (analyze_prompt, zn-gate analyze, Python analyze()) also ask the cloud model for a second opinion. Requires ZN_API_KEY; a key saved with zn-gate connect turns the check on without it. |
ZN_API_KEY |
unset | API key from the dashboard. No effect without ZN_CLOUD=1. |
ZN_LOCAL_ONLY |
unset | true forces local-only, even with ZN_CLOUD=1. |
ZN_STAGE |
v30 |
Cloud endpoint: v30 (current production API) or prod (legacy endpoint). |
ZN_API_URL |
unset | Overrides the cloud endpoint URL. Takes precedence over ZN_STAGE. |
ZN_VERBOSE |
unset | 1 turns on debug logging to stderr. DEBUG=zn (or another DEBUG value that names zn) does the same; DEBUG=* and the DEBUG values of other tools do not. |
ZN_STRICT |
unset | 1 also blocks the checks that only warn by default. It can only make zn-gate stricter, never looser. Node.js and Python. Only the value 1 turns it on: another value such as true or yes leaves it off, and the Python package logs a warning (logger zn_gate), once per value. |
ZN_LONG_INPUT |
windows |
How a long text (over 1,000 characters) is sent to the cloud model. windows checks it in overlapping 512-token pieces, up to 20, so an injection in the middle or at the end is not missed; off checks only the first 512 tokens. Only matters when the cloud is on. |
ZN_BLOCK_TRUNCATED |
unset | 1 blocks a tool result that is too large to scan in full (reported as size:truncated). By default it is allowed and marked truncated. Node.js and Python. Only the value 1 turns it on: another value such as true or yes leaves it off, and the Python package logs a warning (logger zn_gate), once per value. |
ZN_HOME |
~/.zn |
Folder where zn-gate keeps its local data: secret vault, usage counts, MCP pins, cloud key, the evidence log (evidence.jsonl), the hook settings in config.json and the secret request list (requests.jsonl). From 1.16.0 all of this moves together with ZN_HOME; with the variable unset nothing changes. The Node.js package uses it everywhere; the Python package reads it only for the usage counts. |
ZN_HOOK_FAIL_MODE |
closed |
Node.js only. What the agent hooks do when part of zn-gate is missing from the installation. closed blocks the action instead of letting it pass unchecked. closed is the only value this variable accepts: open is ignored, because a project can set the agent's environment. |
ZN_BLOCK_DESTRUCTIVE |
unset | 1 turns on all six destructive-command rules in the agent hooks (see below). It can only turn rules on: 0 is ignored. |
ZN_NO_COMPILE_CACHE |
unset | 1 turns off the cache of compiled hook code in ~/.zn/cache/compile (used on Node.js 22.1 and later to start hooks faster). |
npx -y zn-gate status prints the active engine and what your configuration sends. See What leaves your machine.
Turn on the cloud for one MCP server
Add the variables to that server's entry in your agent config, for example in ~/.cursor/mcp.json:
{
"mcpServers": {
"zn-gate": {
"command": "npx",
"args": ["-y", "zn-gate", "mcp"],
"env": { "ZN_CLOUD": "1", "ZN_API_KEY": "zn_live_your_key" }
}
}
}
Command-line flags
| Flag | Effect |
|---|---|
--local-only |
Never use the cloud, even if ZN_CLOUD=1 is set |
--key <api_key> |
API key for the optional cloud (same as ZN_API_KEY; still needs ZN_CLOUD=1) |
--stage v30 or --stage prod, --url <url> |
Cloud endpoint selection |
--shadow |
With init or shield: log detections without blocking or altering traffic |
--all, --include .rst,.xml, --exclude fixtures |
Control which files scan reads |
--verbose |
Debug logging to stderr |
Run npx -y zn-gate --help for every option.
Custom rules
In the Node.js package, add banned patterns and forbidden paths for your project in .znrules or zn.config.json in the directory zn-gate runs from:
# .znrules
path:.env.production
path:/etc/secrets
CONFIDENTIAL_INTERNAL_PROJECT_[A-Z0-9]+
Lines starting with path: block any input that contains that path. Other lines are case-insensitive regular expressions that block any input they match. Lines starting with # are comments. The JSON form:
{ "bannedPatterns": ["CONFIDENTIAL_INTERNAL_PROJECT_[A-Z0-9]+"], "forbiddenPaths": [".env.production", "/etc/secrets"] }
Blocks from custom rules report custom:banned_pattern or custom:forbidden_path. The Python package does not read these files.
Hook settings (Codex)
These keys go under hooks in ~/.zn/config.json. Environment variables do not set them.
| Key | Default | Effect |
|---|---|---|
stopReview |
"warn" |
"block" makes Codex ask the model to rewrite a final answer that contains a secret value, at most once per answer. Any other value only warns you. |
replaceToolOutputOnSecret |
false |
true makes a tool result that holds a real secret value come back with zn's stop text instead of the output. |
{
"hooks": {
"stopReview": "block",
"replaceToolOutputOnSecret": true
}
}
Details and limits: Final answer review (Codex).
Destructive command rules
The agent hooks refuse two kinds of destructive shell command by default: a recursive delete of the home folder, the filesystem root or a system folder (rm_root_home), and a write to a disk device (disk_overwrite). A blocked command is not run, and the agent is told to ask you to confirm first. Four more rules are off by default: pipe_to_shell (a download piped into a shell, such as curl ... | sh), perm_root (chmod -R or chown -R on the root or a system folder), fork_bomb and rc_download (a download written into a shell startup file).
Set blockDestructiveCommands under hooks in ~/.zn/config.json:
| Value | Rules applied |
|---|---|
| not set | rm_root_home and disk_overwrite |
true |
all six rules |
false |
none |
a list, for example ["rm_root_home", "pipe_to_shell"] |
exactly those rules |
{ "hooks": { "blockDestructiveCommands": true } }
ZN_BLOCK_DESTRUCTIVE=1 in the environment turns on all six rules. The environment can only add protection: ZN_BLOCK_DESTRUCTIVE=0 is ignored, and rules can only be turned off in the config file. This is a guardrail against a mistake, not a sandbox: it reads the text of one command, so it does not see a path built while the command runs or a script saved first and run later. If it blocks a command you want, run it yourself in a terminal. Every rule and what it misses: Destructive commands.
Files zn-gate writes
| File | What it is |
|---|---|
~/.zn/evidence.jsonl |
Local audit log of shield decisions (details). With ZN_HOME set, it is in that folder |
<config>.bak.<timestamp> |
Backup of each agent config that init changes; init --revert restores the latest |