CodexGuild

Guides

Command guard

Stop coding agents from running destructive commands — rm -rf of your home directory, database resets, force pushes, infrastructure teardown, secrets sent over the network — and from switching off hooks, CI checks and git hooks. A local hook, no API key needed.

Agents have wiped home directories (rm -rf $DIR/ after a variable from an earlier shell call was gone), production databases and cloud resources. The command guard reads every Bash command before it runs and stops the ones that destroy data. It runs locally and offline — nothing is sent anywhere — and it is the same hook as the package guard, so one setup covers both.

Denied — never runs

CommandWhy
rm -r / rm -rf of /, your home directory, a parent of it, or a system directory (/usr, /etc, /System…)catastrophic, never what an agent should do
a recursive delete whose path uses a variable that is not set (rm -rf $BUILD_DIR/)it may expand to rm -rf / — the classic agent incident
rm -rf /*, ~/*deletes everything
mkfs, dd of=/dev/…, writing to a disk deviceoverwrites a disk
chmod -R / chown -R on / or your homebreaks the system
cat .env | curl …, curl -F [email protected], env | nc …, scp ~/.ssh/id_rsa …sends secrets over the network
fork bombs

Asks you first

CommandWhy
recursive deletes outside the project (and links that resolve outside it); temp dirs are finemay hit other work
git push --force / -f / +branch / --delete, git reset --hard, git clean -f, git checkout -- ., git branch -Drewrites history or throws away work
git add .env, private keysstages secrets (.env.example is fine)
prisma migrate reset, prisma db push --force-reset / --accept-data-loss, rails db:drop, manage.py flush, DROP / TRUNCATE / DELETE FROM in psql/mysql, FLUSHALLdeletes database data
terraform/tofu destroy, pulumi destroy, cdk destroy, kubectl delete namespace / --all, helm uninstalltears down infrastructure
docker compose down -v, docker system prune -a --volumes, docker volume rmdeletes volumes
aws s3 rm --recursive, aws s3 rb, aws … delete-/terminate-, gcloud … delete, az … delete, platform destroy commandsdeletes cloud resources

Routine commands are not touched: rm -rf node_modules dist inside the project, git push, prisma migrate deploy, docker compose down, terraform plan. The body of a here-document that only writes a file (cat > script.sh <<'EOF' … EOF) is data, not commands; one that bash, ssh or psql runs is checked.

Guardrail changes — asks you first

From 1.17.0 the guard also reads file edits (Claude Code Write/Edit/MultiEdit, Codex apply_patch, Cursor Write/Delete) and asks before the agent weakens a check on its own work. It compares the file before and after, so adding a hook, a rule or a CI step never triggers it.

ChangeExample
agent settings lose a hook or a deny/ask rule, or gain a bypass.claude/settings.json, .cursor/hooks.json, .codex/config.toml: bypassPermissions, disableAllHooks, danger-full-access, approval_policy = "never"
a git hook is deleted, emptied or exits early.husky/pre-commit, .git/hooks/*, .pre-commit-config.yaml, lefthook
a CI check is removed or made non-blockinga test/lint/audit/scan step removed; continue-on-error: true, allow_failure: true, || true, if: false
code owners removedCODEOWNERS
commands that skip or remove themgit commit --no-verify / -n, HUSKY=0, SKIP=…, core.hooksPath, pre-commit uninstall, rm/mv/sed -i/> on the files above, claude --dangerously-skip-permissions, codex --yolo, cursor-agent --force

Coding-agent credentials — asks you first

From 1.17.0 the guard also asks before a command (cat, cp, tar, base64, sed, python -c …, also after a cd into the folder) or the file-read tool (Claude Code and Kimi Code Read with Read in the matcher, Cursor beforeReadFile) opens a file where coding agents keep credentials: ~/.claude/.credentials.json, ~/.claude.json, ~/.codex/auth.json, ~/.local/share/opencode/auth.json, ~/.gemini/oauth_creds.json, ~/.gemini/.env, ~/.cursor/mcp.json, ~/.config/gh/hosts.yml, Claude Code and Codex transcripts, and security find-generic-password -w. Sending any of them over the network is denied. Where they are and how to protect them: Where Claude Code, Codex and Cursor keep your API keys.

Where nobody can answer the question, the guard denies instead and tells the agent to hand the change to you: Claude Code in bypassPermissions mode, Codex, Kimi Code and Cursor's preToolUse (no "ask" from hooks there), and guard --strict — use it in Cursor if you run with --force, which approves a hook's "ask" without showing it. Background and test results: Stop your coding agent from switching off its own guardrails.

Set it up (Claude Code)

Requires @codexguild/mcp 1.5.0 or newer, 1.17.0 for guardrail changes (@latest below always takes the newest).

Add the hook to ~/.claude/settings.json (or the project's .claude/settings.local.json, which is not committed):

json
{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash|Write|Edit|MultiEdit", "hooks": [{ "type": "command", "command": "npx -y @codexguild/mcp@latest guard", "timeout": 20 }] }
    ]
  }
}

The command checks need no key. The package checks use CODEXGUILD_API_KEY from the environment Claude Code starts in — export it in your shell profile; never put the key in a settings file.

Note: A hook is a safety net, not a sandbox. Keep using Claude Code's permission modes, devcontainers and backups for anything that matters.