Feature: Compact tool + customizable plan exit options
Summary
Two related feature requests that would improve context management during plan-based workflows:
1. Compact tool — let Claude trigger compaction programmatically
Currently, /compact and /clear are harness-level CLI commands that only the user can invoke. Claude has no tool to trigger context compaction. This means:
- After exiting plan mode, Claude cannot compact context before starting execution
- Hooks on
ExitPlanModecan run shell commands but cannot invoke/compact - Even with CLAUDE.md instructions like "compact before executing," Claude has no mechanism to do it
Proposed: Add a Compact tool (and optionally a Clear tool) that Claude can call like any other tool. This would enable workflows like:
- Auto-compact after plan approval but before execution begins
- Compact mid-task when context is getting large but hasn't hit the auto-compact threshold
- Hook-driven compaction via
PostToolUseonExitPlanMode
2. Customizable plan exit options
When exiting plan mode, the UI shows fixed options:
1. Yes, and bypass permissions
2. Yes, manually approve edits
3. No, refine with Ultraplan on Claude Code on the web
4. Tell Claude what to change
Proposed: Allow users to configure additional plan exit options in settings.json, such as:
- "Yes, and clear context first"
- "Yes, and compact context first"
- "Yes, and run in a worktree"
These could map to pre-execution actions. Example config:
{
"planExitOptions": [
{
"label": "Yes, compact context first",
"actions": ["compact"],
"permissionMode": "default"
}
]
}
Motivation
For complex tasks, plan mode generates significant context. By the time the plan is approved, a large portion of the context window is consumed by planning discussion. Users currently must manually run /compact after approval — an easy step to forget, and one that breaks flow.
A Compact tool would also enable hooks to trigger compaction at strategic points (e.g., after plan exit, after large research phases), making context management more autonomous.
Alternatives considered
PostToolUsehook onExitPlanMode— works for shell commands but cannot invoke/compactsince hooks can't trigger internal CLI commands- Reminder injection via hook — can echo a reminder to run
/compact, but still requires manual user action - Waiting for auto-compaction — only triggers at the context limit, which is too late for optimal performance
🤖 Generated with Claude Code
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗