Skip to content

Browse catalog

Search catalog

[READY] Type a title, tag, or description.

NOTES // snippet

PreToolUse read-only hook

LAST_MODIFIED
2026.10.07
CATEGORY
snippet

Plan mode feels read-only. Claude Code now blocks its edit tools until you approve a plan, but two gaps remain: sessions with bypass permissions available skip that block, and shell commands still run while planning. The instructions themselves are a short injected prompt - “MUST NOT make any edits” (Armin Ronacher, 2025-12-17) - and a March 2026 write-up got Claude to modify a .zshrc in plan mode. Writing MUST NOT in all caps is not a security boundary.

Make it actually read-only

Wire a PreToolUse hook that denies Write and Edit when permission_mode is plan, with one exception for the plan file under ~/.claude/plans/:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|NotebookEdit",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/block-plan-writes.sh"
          }
        ]
      }
    ]
  }
}

The script reads the hook payload on stdin and exits with code 2 (blocking the call - exit code 1 is a non-blocking error) when the condition matches. This costs nothing in capability: the agent never legitimately writes anywhere else while planning.

For untrusted repos or unattended runs, climb the sandbox ladder instead. Decision tree for when to use plan mode: Plan mode decision tree. Full article: Claude Code plan mode.

Sources

  1. Hooks referenceAnthropic
  2. Choose a permission modeAnthropic
  3. What is plan mode?Armin Ronacher
  4. Claude Code's plan mode isn't read-onlySondera
claude-codeplan-modehookssecurity

Related_Notes