Allow custom slash commands to trigger /clear or /compact
Problem
Custom slash commands and hooks have no way to programmatically trigger /clear or /compact. These are client-side CLI operations with no extension point.
Use case: I want a single /cgr command that clears the conversation context, checks out the default branch, and rebases on latest origin - a "fresh start" command for switching between tasks. Currently this requires two manual steps: /cgr (git ops) then /clear (context reset).
Current Behavior
- Custom commands run within the existing conversation and can use tools (Bash, Read, etc.)
/clearand/compactare built-in CLI commands handled by the client process- No hook event fires when
/clearis run - No mechanism exists for a command to signal "clear context after I finish"
Proposed Solution
Any of these would work:
- Post-command context action: Allow command frontmatter to specify a context action after completion:
``yaml``
---
description: Clear and reset to default branch
allowed-tools: Bash
post-action: clear # or "compact"
---
- Hookable
/clearevent: Add aPreClear/PostClearhook event so hooks can run git operations when/clearis triggered.
- Tool for context management: Expose a
ClearorResetContexttool that commands can invoke like any other tool.
Why This Matters
Power users build workflows around custom commands (commit, PR, status dashboards, etc.). The inability to chain context management with these commands creates friction in task-switching workflows. With the raw API you control the message array directly, so this is a limitation specific to Claude Code's extension system.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗