Allow custom slash commands to trigger /clear or /compact

Resolved 💬 2 comments Opened Mar 22, 2026 by lucasmccomb Closed Apr 19, 2026

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.)
  • /clear and /compact are built-in CLI commands handled by the client process
  • No hook event fires when /clear is run
  • No mechanism exists for a command to signal "clear context after I finish"

Proposed Solution

Any of these would work:

  1. 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"
---
``

  1. Hookable /clear event: Add a PreClear / PostClear hook event so hooks can run git operations when /clear is triggered.
  1. Tool for context management: Expose a Clear or ResetContext tool 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.

View original on GitHub ↗

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