[FEATURE] PrePlanMode and PostPlanMode Hook Events
Feature Request: PrePlanMode and PostPlanMode Hook Events
Summary
Users who create plans in Claude Code cannot hook into plan mode lifecycle events. Adding PrePlanMode and PostPlanMode hook events would enable workflows like archiving existing plans before overwrite, validating prerequisites, and post-plan processing.
Problem Description
Current Behavior
- User enters plan mode (via
/planor plan permission mode) - Claude creates/updates plan file at
~/.claude/plans/<session-name>.md - If a plan already exists in that file, it gets overwritten with no backup
- There's no way to hook into this process
Expected Behavior
Users should be able to:
- PrePlanMode: Run hooks before plan mode starts (archive existing plan, validate state)
- PostPlanMode: Run hooks after plan mode exits (process completed plan, trigger workflows)
Use Cases
1. Auto-Archive Existing Plans
Before a plan is overwritten, archive it for future reference:
# PrePlanMode hook
if [[ -f "$PLAN_FILE" ]]; then
cp "$PLAN_FILE" "$ARCHIVE_DIR/$(basename $PLAN_FILE .md)-$(date +%s).md"
fi
2. Prerequisite Validation
Ensure certain conditions are met before planning:
# PrePlanMode hook - ensure clean git state
if [[ -n "$(git status --porcelain)" ]]; then
echo "WARNING: Uncommitted changes exist"
exit 1 # Block plan mode
fi
3. Plan Processing
After exiting plan mode, trigger downstream workflows:
# PostPlanMode hook
# Convert plan to issue tracker tickets
./scripts/plan-to-tickets.sh "$PLAN_FILE"
4. Plan Persistence to Project
Copy finalized plan into project directory for version control:
# PostPlanMode hook
cp "$PLAN_FILE" ".plans/$(date +%Y%m%d)-plan.md"
git add ".plans/"
Proposed Solution
New Hook Events
{
"hooks": {
"PrePlanMode": [
{
"hooks": [
{
"type": "command",
"command": ".claude/hooks/plan-archive/hook.sh"
}
]
}
],
"PostPlanMode": [
{
"hooks": [
{
"type": "command",
"command": ".claude/hooks/plan-complete/hook.sh"
}
]
}
]
}
}
Hook Input Schema
{
"event": "PrePlanMode",
"plan_file": "/Users/name/.claude/plans/graceful-kindling-wombat.md",
"plan_exists": true,
"plan_content_size": 4096,
"session_id": "abc123"
}
Exit Code Semantics
| Exit Code | PrePlanMode | PostPlanMode |
|-----------|-------------|--------------|
| 0 | Allow plan mode | Continue normally |
| 1 | User decision (prompt) | N/A |
| 2 | Block plan mode | N/A |
Current Workaround
Using PreToolUse with Write matcher to intercept plan file writes:
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"command": ".claude/hooks/plan-archive/hook.sh"
}
]
}
Limitations of this workaround:
- Fires on ALL Write operations (must filter by path)
- Doesn't know if we're entering/exiting plan mode specifically
- No access to plan mode metadata
- Can't block plan mode entry, only individual writes
Impact
Current State
| Capability | Status |
|------------|--------|
| Archive plans before overwrite | Workaround (fragile) |
| Validate prerequisites for planning | Not possible |
| Process completed plans | Not possible |
| Track plan mode sessions | Not possible |
With Feature
| Capability | Status |
|------------|--------|
| Archive plans before overwrite | Native support |
| Validate prerequisites for planning | Enabled |
| Process completed plans | Enabled |
| Track plan mode sessions | Enabled |
Environment
- Claude Code CLI
- Using custom hooks for workflow automation
- Long sessions with multiple planning cycles
Related
This complements existing hook events:
SessionStart/SessionEnd- session lifecyclePreCompact- context managementPreToolUse/PostToolUse- tool lifecycle
Plan mode is a distinct operational mode that deserves first-class hook support.
15 Comments
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
Please bring this hook. commenting here before this feature request goes stale
We need this!
Need this!
Bump!
There is an EnterPlanMode and ExitPlanMode hook - does that solve the problem? FYI, I have just dropped in a solution on a similar bug that gives you:
Hope it helps someone else like it helped me
+1 on this. My immediate use case is simple: I want a push notification (via ntfy.sh) when planning mode finishes so I can walk away and come back when it's ready for review.
Today there's no reliable way to do this —
PostToolUse:ExitPlanModedoesn't fire, and theStophook is too broad since it fires on every response. A dedicatedPostPlanModeevent would solve this cleanly.We had ExitPlanMode event in tooluse, so??? We better still have this.
Lifecycle hooks make total sense, but they're compensating for something that should be built-in — plans don't have a lifecycle at all right now. There's no status (draft vs approved vs done), no archiving on transition, no way for a new plan to know an old one existed. If plans had native identity and state transitions, hooks like Pre/PostPlanMode become clean extension points instead of the entire persistence mechanism. Wrote up the fuller proposal in #29445 — hooks + a plan registry would be the real combo.
I want to hook EnterPlanMode and cancel it and tell the agent to use a skill instead. Is this possible?
would use this immediately. we have a workflow where the agent writes implementation plans to a file before starting work, and being able to hook into plan mode transitions would let us auto-archive the previous plan.
right now we work around it with a PreToolUse hook that checks if the tool is Write and the target is a plan file. it's hacky and misses cases where the agent updates a plan in-place rather than rewriting it.
the PostPlanMode hook is the more valuable one for us - it would let us snapshot the plan to a versioned file (plan-v1.md, plan-v2.md) so we have a history of how the approach evolved during a session. currently that context is lost when the plan gets overwritten.
we run a bunch of automated workflows triggered by hooks already, here's an example of the kind of thing PrePlanMode/PostPlanMode would unlock - right now we work around it with custom skill entry points: https://github.com/m13v/social-autoposter/blob/main/skill/SKILL.md
While dedicated
PrePlanMode/PostPlanModeevents don't exist yet, you can hook into plan mode transitions today using existing matchers:PostToolUse+ExitPlanMode— fires when plan mode exits:PermissionRequest+ExitPlanMode— fires before exit, can block:Exit code
0= approve,2= block (with reason in stdout sent back to Claude).Example: archive plan on exit + notify
Limitations:
PreToolUse+EnterPlanModeis inconsistent across versions (#21282)PostToolUse+ExitPlanModedoes not fire when the user accepts the plan with "clear context" (#20397)~/.claude/plans/For
EnterPlanModeinterception, aUserPromptSubmithook that checks for/planin the prompt is a rough fallback, though it won't catch programmatic entry.+1 on this
+1 on this, this is a great improvement in productivity