[BUG] PostToolUse hook for ExitPlanMode not triggered when accepting plan with clear context

Resolved 💬 3 comments Opened Mar 27, 2026 by chrisbeardy Closed Apr 30, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When a PostToolUse hook is configured with a matcher for ExitPlanMode, the hook fires correctly when accepting a plan without clearing context, but does not fire when accepting the plan with the "clear context" option.

This was previously reported in #20397 but was closed due to inactivity rather than being resolved. I am experiencing the same behaviour, confirming this is a reproducible bug affecting multiple users across different platforms and API providers.

What Should Happen?

Accepting a plan with the "clear context" action should still trigger the PostToolUse hook for ExitPlanMode. The context clearing should occur after hook dispatch, not before/instead of it.

Error Messages/Logs

No error — the hook simply does not fire. The log file is never created/appended to.

Steps to Reproduce

  1. Add a PostToolUse hook for ExitPlanMode to .claude/settings.json:
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "ExitPlanMode",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"=== $(date) ===\" >> \"$CLAUDE_PROJECT_DIR/exitplanmode-hook.log\"; jq '.' >> \"$CLAUDE_PROJECT_DIR/exitplanmode-hook.log\" 2>&1 || cat >> \"$CLAUDE_PROJECT_DIR/exitplanmode-hook.log\""
          }
        ]
      }
    ]
  }
}
  1. Start Claude Code and enter plan mode
  2. Generate a plan
  3. Accept the plan without clearing contextexitplanmode-hook.log is created ✅
  4. Delete the log file, restart Claude Code, generate another plan
  5. Accept the plan with the clear context optionexitplanmode-hook.log is not created ❌

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.77

Platform

Anthropic (Direct)

Operating System

Windows 11

Terminal/Shell

PowerShell 7

Additional Information

This is the same issue as #20397 which was reported on macOS with AWS Bedrock. I am experiencing identical behaviour on Windows 11 with the Anthropic API directly, suggesting this is a platform- and provider-agnostic bug in the hook dispatch lifecycle.

The likely cause is that the context clearing path bypasses or pre-empts the PostToolUse event dispatch for the ExitPlanMode tool.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗