[FEATURE] Add PrePlanMode hook for context preservation before plan execution

Resolved 💬 3 comments Opened Feb 3, 2026 by rhoulihan Closed Feb 7, 2026

Feature Request

Add a new hook event that fires before plan mode clears the context window to execute an approved plan.

Current Behavior

When a user approves a plan in Claude Code, the context is cleared to make room for plan execution. There is currently no hook that allows external tools to save state before this happens.

Proposed Solution

Add a new hook event PrePlanMode (or similar) that fires:

  • After the user approves the plan
  • Before the context is cleared
  • With the ability to block/delay the clear until the hook completes

Proposed Input Schema

{
  "session_id": "abc123",
  "transcript_path": "/path/to/transcript.jsonl",
  "cwd": "/project",
  "hook_event_name": "PrePlanMode",
  "plan_summary": "Implementation plan summary...",
  "approval_type": "clear_context" | "manual_edits"
}

Use Case

I'm building Ben-Ten, a context persistence tool for Claude Code. It saves and restores context across sessions to eliminate the "cold start" problem.

Currently, Ben-Ten hooks into PreCompact to save context before automatic compaction. However, plan mode context clearing doesn't appear to trigger PreCompact, so context is lost when executing plans.

With a PrePlanMode hook, Ben-Ten could:

  1. Auto-save the current context before plan execution
  2. Restore that context in the next session if the plan fails or is interrupted
  3. Preserve important file references and task state across plan executions

Alternatives Considered

  1. PreCompact hook - Tried this, but plan mode clearing doesn't seem to trigger it
  2. SessionStart with source="clear" - Fires after the clear, not before
  3. Manual save - Requires user to remember to save before approving plans

Additional Context

  • Related bug: #19530 (Plan mode context cleared even when selecting manual edit option)
  • Ben-Ten already supports SessionStart, SessionEnd, and PreCompact hooks
  • This would complete the set of context-clearing lifecycle events

Thank you for considering this feature!

View original on GitHub ↗

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