AI coding agents can edit files, run shell commands, and touch infrastructure. One bad rm -rf, force-push, or docker compose down -v can wipe hours of work or production data.
| 1 | # Using agent-guard with Claude Code |
| 2 | |
| 3 | This is a **pattern**, not a native Claude Code plugin. |
| 4 | |
| 5 | ## Advisory gate |
| 6 | |
| 7 | Before approving a shell tool call, ask Claude Code (or a wrapper script) to run: |
| 8 | |
| 9 | ```bash |
| 10 | agent-guard check --json "<proposed command>" |
| 11 | ``` |
| 12 | |
| 13 | Interpret: |
| 14 | |
| 15 | | `decision` | Suggested agent behavior | |
| 16 | |------------|--------------------------| |
| 17 | | ALLOW | Proceed | |
| 18 | | WARN | Ask the human / show reason | |
| 19 | | BLOCK | Refuse; propose a safer alternative | |
| 20 | |
| 21 | Exit codes: `0` / `10` / `20`. |
| 22 | |
| 23 | ## Enforcing wrapper |
| 24 | |
| 25 | Replace direct bash execution with: |
| 26 | |
| 27 | ```bash |
| 28 | agent-guard run -- <command> [args...] |
| 29 | ``` |
| 30 | |
| 31 | WARN prompts the human (default N). Non-interactive sessions need `--allow-risk` for WARN only. BLOCK never runs. |
| 32 | |
| 33 | ## Project setup |
| 34 | |
| 35 | ```bash |
| 36 | cd your-project |
| 37 | agent-guard init |
| 38 | agent-guard scan |
| 39 | ``` |
| 40 | |
| 41 | Commit `.agent-guard.yml` so agents and humans share the same policy. |
| 42 | |
| 43 | ## Notes |
| 44 | |
| 45 | - Do not claim Claude Code API integration unless you build it. |
| 46 | - Prefer argv-style `run -- git status` over nested shells. |
| 47 | - Never paste live secrets into prompts; agent-guard redacts output but prevention is better. |