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 doctorpasses (Quickstart). - The agent you want to guard is installed. Each connector page lists what it needs.
Set it up
Run setup
defenseclaw setup guardrailDefaults 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 25guardrail 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).
| Pack | Blocks | Alerts | Gateway not running (per-user, no saved fail mode) | Pick it when |
|---|---|---|---|---|
default | CRITICAL | MEDIUM and up | The call runs, with a warning and a record | You want the shipped baseline |
strict | MEDIUM and up | LOW and up | The call is blocked | A missed attack costs more than a stopped call |
permissive | CRITICAL | HIGH and up | The call runs, with a warning and a record | Agents 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 packThe 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
| Mode | What happens to a finding |
|---|---|
observe | Recorded as an alert. Nothing asks you, and nothing is blocked except by the self-protection rule below. This is the default. |
action | The 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:
| Finding | Human approval off | Human approval on (minimum HIGH) |
|---|---|---|
| CRITICAL | Block | Block |
| HIGH | Alert | Ask, or alert where the agent cannot ask |
| MEDIUM | Alert | Alert |
| LOW | Allow | Allow |
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 againSwitching 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.
| Install | With no saved fail mode | You can change it |
|---|---|---|
| Per-user | The rule pack decides: default and permissive are open, strict is closed | defenseclaw guardrail fail-mode closed (add --connector X for one agent) |
| Managed | closed | The 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
openmode, 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
- How the guardrail works: the path of one call and what each setting changes.
- Turn on blocking: move one agent from observe to action.
- Several agents: guard more than one agent with one gateway.
- Why was this blocked?: read a block and fix a false one.
How the guardrail works
Follow one agent call through the DefenseClaw guardrail, see what each step reads, and learn what rule pack, preset, profile and Rego policy mean.
Guard several agents
Guard several hook agents with one DefenseClaw gateway, each with its own mode, fail mode, approval, block message and rule pack in guardrail.connectors.