Guardrail

Guardrail setup and modes

Turn on the guardrail with defenseclaw setup guardrail, pick a rule pack and a mode (observe or action), and set what a hook does if the gateway is down.

defenseclaw setup guardrail sets the connector, mode, scanner, judge, human approval and rule pack, then restarts the gateway. Three choices decide how hard the guardrail acts: the rule pack, the mode and the hook fail mode. Start with the default pack in observe mode, and move an agent to action when its alerts look right.

Before you start

  • DefenseClaw is installed and defenseclaw doctor passes (Quickstart).
  • The agent you want to guard is installed. Each connector page lists what it needs.

Set it up

Run setup

defenseclaw setup guardrail

Defaults are in brackets; Enter accepts them. On first setup, and when you change the mode, it also asks for the hook fail mode. The picker's "never block" covers policy findings. With the strict pack, observe still blocks an agent that changes DefenseClaw's own files; the default and permissive packs raise a HIGH alert and do not block it (Modes). To build the command in the browser, use the command generator.

Or run it with no prompts

defenseclaw setup guardrail \
  --non-interactive \
  --connector claudecode \
  --mode observe \
  --rule-pack default \
  --scanner-mode local \
  --restart

--non-interactive (also --accept-defaults or --yes) skips every prompt; a missing flag takes the wizard default. The LLM judge stays off until you pass --judge-model. The saved detection strategy defaults to regex_judge, but with the judge off only the regex lane runs, so the setup summary and guardrail status show the strategy that runs: regex_only. The summary line reads guardrail.detection_strategy: regex_only. Every flag is on Setup guardrail.

Check it worked

defenseclaw doctor
defenseclaw guardrail status
defenseclaw alerts --limit 25

guardrail status shows the pack, mode and fail mode each connector resolves to. Setup writes the agent's hook entries (for Claude Code, into ~/.claude/settings.json) and the hook scripts under ~/.defenseclaw/hooks; on Windows the registered command runs defenseclaw-hook.exe through a small guarded launcher (Claude Code paths). If the guardrail does not load or check calls, see Fix setup problems.

To undo setup, see Turn it off.

Rule packs

A finding has a severity: CRITICAL, HIGH, MEDIUM or LOW. The rule pack holds the rules and sets the default lowest severity that blocks (block_at) and the lowest that alerts (alert_at).

PackBlocksAlertsGateway not running (per-user, no saved fail mode)Pick it when
defaultCRITICALMEDIUM and upThe call runs, with a warning and a recordYou want the shipped baseline
strictMEDIUM and upLOW and upThe call is blockedA missed attack costs more than a stopped call
permissiveCRITICALHIGH and upThe call runs, with a warning and a recordAgents must stay available and you read alerts

A level you set yourself (globally, for a connector or in a profile) wins over the pack's level (Block and alert levels).

defenseclaw guardrail list-packs                          # packs, and which one each agent uses
defenseclaw guardrail use-pack strict                     # every agent
defenseclaw guardrail use-pack strict --connector codex   # one agent
defenseclaw guardrail use-pack --clear --connector codex  # back to the global pack

The new pack applies on the gateway's next reload, with no restart. To pick a pack you wrote, run defenseclaw guardrail use-pack PATH. After you edit a pinned pack, run defenseclaw guardrail use-pack NAME --repin to pin the new digest. Validation and pinning in full: Packs and rules.

Modes

ModeWhat happens to a finding
observeRecorded as an alert. Nothing asks you, and nothing is blocked except by the self-protection rule below. This is the default.
actionThe levels apply: a finding at the block level is blocked, one at the alert level raises an alert. Human approval can ask you first for a finding below the block level.

With the default pack in action mode:

FindingHuman approval offHuman approval on (minimum HIGH)
CRITICALBlockBlock
HIGHAlertAsk, or alert where the agent cannot ask
MEDIUMAlertAlert
LOWAllowAllow

Observe mode does not enforce policy findings, whatever the levels say. Hook fail mode and proxy availability still apply.

One rule still acts in observe mode: an agent that writes, deletes or changes DefenseClaw's own state in ~/.defenseclaw (rule tamper.detector_state_write). That state is the files .env, config.yaml, confidence_policy.yaml, guardrail_runtime.json, device.key, picked_connector, custom-providers.json, audit.db, judge.db and judge_bodies.db (with their -wal and -shm files), and anything under cache/, hooks/, installer/, policies/, previous/installer/, quarantine/, receipts/ and registries/. Other files in that folder are not covered. The strict pack blocks it in every mode, on a managed host that uses it too. The default and permissive packs, a managed install's default pack included, only raise a HIGH alert, in every mode; they do not block it.

defenseclaw guardrail mode action                          # every agent
defenseclaw guardrail mode action --connector claudecode   # one agent
defenseclaw guardrail mode --clear --connector claudecode  # follow the global mode again

Switching an agent out of action mode runs the version check setup runs. If setup would refuse that agent's version in every mode, the command changes nothing and names the reason.

Hook fail mode

The hook fail mode decides what a hook does when no gateway took the call: open lets the call run with a warning and a record, closed blocks it.

InstallWith no saved fail modeYou can change it
Per-userThe rule pack decides: default and permissive are open, strict is closeddefenseclaw guardrail fail-mode closed (add --connector X for one agent)
ManagedclosedThe administrator can choose open, which then applies only to a proven outage

The fail mode covers a gateway that is not running. These cases block in every fail mode:

  • The gateway answers with an error, or with an answer DefenseClaw cannot use.
  • The gateway took the call and gave no decision in time. One exception: on a per-user install in open mode, an ordinary Claude Code or Codex tool call that names nothing a protected file could be reached through runs with a warning.

Every case, per install and per connector, is on Fail modes and in the gateway outage table.

Next