# Walls outside the agent ## 1. Permission rules (`.claude/settings.json`) Checked by Claude Code before a tool runs. Deny rules block in every permission mode. ```json { "permissions": { "deny": [ "Bash(git push --force *)", "Bash(git push -f *)", "Bash(git push origin main*)", "Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)" ], "ask": [ "Bash(git push *)", "Bash(npm publish *)" ] } } ``` Syntax: https://code.claude.com/docs/en/permissions ## 2. A blocking hook (`.claude/hooks/block-rm.sh`) A `PreToolUse` hook can deny a call. Exit code 2 blocks it and sends stderr to Claude as the reason. Hooks run with your user's privileges and **fail open** if they crash, unless you add `"onFailure": "block"`. ```json { "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh", "onFailure": "block" } ] } ] } } ``` ```bash #!/bin/bash # Blocks recursive force deletes. Requires jq. COMMAND=$(jq -r '.tool_input.command') if echo "$COMMAND" | grep -Eq 'rm +-[a-zA-Z]*r[a-zA-Z]*f|rm +-[a-zA-Z]*f[a-zA-Z]*r'; then echo "Recursive force delete blocked by the harness walls." >&2 exit 2 fi exit 0 ``` Reference: https://code.claude.com/docs/en/hooks ## 3. Sandbox Run `/sandbox` in Claude Code to limit where shell commands can read, write and connect. Built in on macOS, Linux and WSL2. Reference: https://code.claude.com/docs/en/permission-modes ## 4. Permission mode for unattended runs - Use `dontAsk` (only pre-approved tools run) or `auto` (a classifier reviews actions) for scheduled jobs, plus `--permission-prompts none` so nothing waits for an answer. - Never use `bypassPermissions` outside an isolated container or VM. Reference: https://code.claude.com/docs/en/headless ## 5. Branch protection on GitHub (the outside wall) On the `main` branch, require: - [ ] A pull request before merging - [ ] Passing status checks (tests, lint, accessibility) - [ ] Your approval - [ ] No force pushes and no deletions Note: GitHub lists protected branches for **private** repositories as a paid-plan feature (Pro, Team or Enterprise). See https://docs.github.com/en/get-started/learning-about-github/githubs-plans ## 6. No credentials to hold - [ ] Deploy keys live in CI secrets, never in the agent's environment or the repository. - [ ] Deploy runs from CI on merge to `main`. - [ ] The Claude Code GitHub Action uses `ANTHROPIC_API_KEY` or `CLAUDE_CODE_OAUTH_TOKEN` stored as a repository secret. ## 7. Your top rule - [ ] [For example: personal accounts only; no company or client accounts, folders or credentials are ever connected.] - [ ] How you will notice if it is broken: [check]