Feature: Hook JSON output field to trigger /clear programmatically
Problem
After completing a task, I want to offer the user a choice to clear context for a fresh start. Currently, the only way to trigger /clear is for the user to type it manually. There is no hook output field, API, or programmatic mechanism to trigger context clearing.
Current Workaround
My AskUserQuestion hook presents options like "Type /clear for fresh context" — but the user has to manually type /clear after selecting the option. This creates a 2-step interaction where 1 step should suffice.
Proposed Solution
Add a clearContext: true field to the hook JSON output specification. When a hook (e.g., PostToolUse on AskUserQuestion) returns {"clearContext": true}, Claude Code would clear the conversation context as if the user typed /clear.
Alternatively, a Stop hook could return a field like {"triggerClear": true} to clear context at session boundaries.
Use Case
Automated workflow systems (like conductor tracks) that complete multi-phase work and want to offer clean context transitions between phases. The claude-mem plugin already handles context re-injection on /clear events (SessionStart fires on startup|clear|compact), so the infrastructure for post-clear recovery exists.
Environment
- Claude Code CLI
- Using hooks system (PreToolUse, PostToolUse, Stop, SessionStart)
- claude-mem plugin for cross-session memory
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗