Guard
The guard is a short list of patterns for things a coding agent should not do unnoticed. Seven of them block. Eight more only flag. The list is in core/guard.go.
countersign guard on # block the destructive ones
countersign guard off # go back to recording only
countersign guard status # show where things stand
Recording only and enforcing
A hook runs in one of two modes.
Recording only (monitor mode). The engine still decides every action and the verdict is written to the ledger. The hook does not act on the verdict: no rule stops the tool. A rule that says no is shown as would block. A rule that asks for a human is shown as would ask. The request itself carries mode=monitor under the agent's signature, so a recorded denial cannot later be presented as an action that was prevented.
One thing stops a recording-only agent: revoking its passport. Revoke is a person saying "stop this agent", and from build 2026.11.29.2 the hook stops every tool call once the passport is revoked, and says why. The request carries stops=revoked beside mode=monitor, so the record can tell this hook from an older one. A hook from an earlier build lets the tool run after a revoke: the ask is refused and recorded, and shown as ran anyway, never as stopped. Run countersign update on each machine so that Revoke reaches it. The console's Agents page says, before you confirm a revoke, which agents it will not stop.
A passport that has run out does not stop a recording-only agent. The tool runs, each call is recorded as refused and shown as ran anyway, and the person at the terminal is told once in each session to renew the passport.
When the engine refuses to record an ask for a reason that is not about the passport, see When the engine is reached and will not record.
Enforcing. The hook stops the tool when the engine blocks the action, holds it for a human, or refuses the request. The agent is told why.
countersign start sets recording only. So does connecting a coding agent from the console's Integrations page, from build 2026.11.29.2: "Start by recording" is on unless you switch it off before you sign, and the step-by-step hook command carries --mode monitor. A fleet rollout always enforces. A credential you make on the Agents page or with countersign agent add has no mode set, so it enforces. A machine whose command-line tool is older than 2026.11.29.2 does not read the choice and enforces from the first call: update it first.
Recording first is there so that you see what your rules would stop before they stop anything. Activity labels those actions "Would block" and "Would ask", Overview counts them beside what was stopped, and the Policy page checks a rule against the actions already recorded before you sign it.
The mode is stored in the agent's credential file as "mode": "monitor" or "mode": "enforce". The hook flag --mode monitor or --mode enforce overrides it for one hook command.
What guard on does
On the machine where the workspace was made (it holds the workspace's signing key):
- It adds the seven blocking rules to the top of your workspace's policy. Rules you wrote are kept, in their order, after them. The new policy version is signed with your key and recorded. Running
guard ontwice changes nothing. - It sets every agent credential in
~/.countersign/agentsto enforcing.
On a machine whose agents were connected from the console (it holds agents' credentials and no signing key), from build 2026.11.29.2:
- It changes no rule. The rules are the workspace's own, made and signed on the Policy page.
- It sets every agent credential in
~/.countersign/agentsto enforcing, so those rules now stop the agent on this machine.guard offsets them back to recording only, andguard statussays which they are.
The change applies from the next tool call.
Enforcing applies to the whole policy. If your policy or a passport has other rules that block or ask a human, those now stop the agent too.
guard off removes every rule whose id starts with guard. from the policy and sets the credentials on this machine back to recording only.
guard status prints one of three answers:
Guard is on.Guard rules are in the policy, but this machine's agents are in recording-only mode, so no rule blocks anything.Guard is off. Recording only.
What it blocks
These rules deny the action when the guard is on.
| Rule id | Blocks | Examples that match |
|---|---|---|
guard.delete_everything | A recursive rm aimed at the root, the home directory, the current directory, its parent, or a bare wildcard | rm -rf /, rm -rf ~, sudo rm -rf $HOME, rm -r -f ., cd /tmp && rm -fr * |
guard.git_force_push | git push with --force or -f | git push --force origin main, git push -f |
guard.git_reset_hard | git reset --hard | git reset --hard HEAD~3 |
guard.git_clean | git clean with -f | git clean -fdx |
guard.sql_drop | DROP DATABASE, DROP SCHEMA, DROP TABLE or TRUNCATE TABLE, in any letter case, handed to a database client (psql, mysql, mariadb, sqlite3, sqlcmd, pgcli, mycli, duckdb, clickhouse-client, cockroach, snowsql) on its command line or down a pipe. From build 2026.11.29.2 the words alone do not match: grep -rn "DROP TABLE" migrations/ runs | psql -c "DROP TABLE users" |
guard.disk_wipe | mkfs, dd writing to a device under /dev/, diskutil erase | dd if=/dev/zero of=/dev/disk2 bs=1m |
guard.infra_destroy | terraform destroy, tofu destroy, pulumi destroy, kubectl delete namespace, kubectl delete with --all | terraform destroy -auto-approve, kubectl delete namespace prod |
Commands that do not match the blocking rules include rm -rf ./build, rm -rf /tmp/scratch, git push origin main, git reset --soft HEAD~1, git clean -n, terraform plan and kubectl delete pod web-1.
When a command is blocked the agent receives a message of this form:
Countersign denied this action under rule guard.git_force_push: force push rewrites history other people may have. Recorded as event 57. Do not attempt to work around this.
What it only flags
These rules never block. They mark the action in countersign log, in countersign digest and in the status line count.
| Rule id | Flags | Example |
|---|---|---|
guard.recursive_delete | Any recursive rm | rm -rf ./build |
guard.force_with_lease | git push --force-with-lease | git push --force-with-lease origin feat |
guard.sudo | sudo at the start of a command, or straight after ;, &, | or ( | sudo apt-get install jq |
guard.pipe_to_shell | curl or wget piped to a shell | curl -fsSL https://example.com/i.sh | sh |
guard.secret_in_command | A command that names a secrets file: .env, .env.*, id_rsa, id_ed25519, id_ecdsa, .aws/credentials, .netrc, .pgpass | cat .env |
guard.secret_file | A file tool opening .env, .env.*, an SSH key file, .npmrc, .netrc, .pgpass, or anything under .ssh/, .aws/ or .gnupg/ | /Users/a/.ssh/id_ed25519 |
guard.publish | npm publish, pnpm publish, yarn publish, cargo publish, twine upload, gh release create | npm publish --access public |
guard.deploy | vercel, netlify, wrangler, flyctl or fly with deploy or --prod | vercel deploy --prod |
One list drives the policy rules, the digest and the status line. A test in the code checks that they agree.
To block something from the flag list, write your own policy rule. See Policy.
When the engine cannot be reached
The hook has a flag for this: --fail open or --fail closed. With no flag it is closed.
--fail open: if the engine cannot be reached, the tool runs. The hook keeps the signed ask on the machine, under~/.countersign/spool, and hands it in when the engine next answers. The ledger then holds it as an action that ran while the engine was unreachable (action_late), with the time it ran and the time it arrived. It is never recorded as allowed: nothing was decided before it ran. The hook thatcountersign startinstalls uses this setting, and so does a hook added bycountersign connector from the console's Integrations page, unless the owner ticked "Stop the agent when Countersign cannot be reached".--fail closed: if the engine cannot be reached, the tool is blocked, and the message says so and what to do: runcountersign doctor, or take the hook out withcountersign stop. A fleet rollout uses this setting, and so doescountersign claude, because they do not pass--fail.
The hook gives the engine 3 seconds. After one failure it takes the engine as out of reach for the next 30 seconds without asking, so an outage costs the agent one short wait and not one on every tool call. Thirty seconds after the failure the next call asks the engine again, however busy the agent has been in between. Builds before 2026.11.29.2 renewed the 30 seconds on every call, so an agent that stayed busy was not asked for until it went quiet. Run countersign update on each machine to get the fix.
In recording-only mode the hook does not block when the engine cannot be reached, whatever --fail says, and keeps calls for later in the same way.
The first time a call is let through this way the person is told, in the agent's own window where the agent shows such a message (Claude Code, Codex, Gemini CLI and Grok CLI) and on standard error everywhere.
Kept calls are handed in when the engine next answers a call from that agent. So that an agent which has finished its work does not hold them for days, the hook also starts a copy of the tool in the background that tries again by itself, six times over about forty minutes, and then ends. countersign spool --list says how many calls are waiting on this machine. countersign spool hands them in now. A call that has waited 14 days is dropped, and at most 2,000 are kept for one agent. If a call cannot be kept, the message says it will not be in the record.
When the engine is reached and will not record
The engine can also answer and refuse to record an ask. What the hook does depends on why. With --fail closed (and not recording only) the tool is blocked in every case and the message gives the reason. Otherwise the tool runs, and:
| The engine says | What the hook does |
|---|---|
| Asks are coming too fast (status 429: the limit for the workspace or for the network address) | Keeps the call and hands it in later, as in an outage. Tells the person once. A hand-in that meets the same answer stops and tries again later. Nothing is thrown away. |
| The workspace is at its plan's stop (Free, on the hosted service, at twice its monthly allowance) | Tells the person once in each session, in the engine's words, which say when recording starts again. Nothing is kept: what the plan does not record is not recorded later either. From build 2026.11.29.2 the rules still apply: the engine answers with what the policy and the passport decide, marked as not recorded, and an enforcing hook stops what a rule denies. An action a rule would hold for a person is stopped too, because there is nowhere to record the asking or the approval. Revoke still stops the agent. |
| It does not know this agent's credential (status 401, 403 or 404) | Tells the person on every call, and to run countersign doctor. Nothing is kept. Nothing this agent does is recorded until a person puts the credential right. |
| The workspace has been deleted and is in its seven days (410) | Tells the person once in each session, with the day it will be removed. Calls already kept on the machine stay kept, and are handed in if the owner undoes the deletion. |
| Anything else, for example an ask that is too large (413) | Tells the person once in each session. Nothing is kept. |
In all four rows the action runs with no entry in the ledger at the time. Only the first row is recorded afterwards. If the record has to be complete, use --fail closed and enforce mode.
The local engine starts itself when the hook calls it, so on a machine set up with countersign start an unreachable engine is unusual.
Limits
- It matches text. Each rule is a regular expression over the command or the file path. An agent can write a destructive command in a form no pattern catches. A pattern can also match a harmless command, for example a search for the words
drop table. Treat the guard as a safety check on common mistakes. It is not a sandbox. - Blocking rules read the shell command only. They read the
commandfact. An action without one, such as a file read, is never blocked by the guard. - Only the first 1,000 bytes of a command are read. The hook sends that much to the engine, cut at a whole character. In plain English text a byte is a character. An accented letter is two bytes and a Chinese or Japanese character is three.
- Minimal-facts mode switches it off. With
--facts minimalthe hook sends no command and no path, so no guard rule matches. - The patterns were tested on a fixed set of examples. Real agent traffic will show false alarms and misses.
- Someone with admin rights on their own machine can remove the hook. See Fleet rollout and Coverage for ways to detect that.
The guard on a hosted workspace
guard on changes the workspace's policy. On a workspace shared by several agents, the guard rules then apply to every agent in it. The mode change applies only to the credentials on the machine where you ran the command.