[BUG] PostToolUse hook for ExitPlanMode not triggered when accepting plan with clear context
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
- Add a
PostToolUsehook forExitPlanModeto.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\""
}
]
}
]
}
}
- Start Claude Code and enter plan mode
- Generate a plan
- Accept the plan without clearing context →
exitplanmode-hook.logis created ✅ - Delete the log file, restart Claude Code, generate another plan
- Accept the plan with the clear context option →
exitplanmode-hook.logis 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗