Skip to content

Allow custom slash commands to trigger /clear or /compact #37307

Description

@lucasmccomb

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:

    ---
    description: Clear and reset to default branch
    allowed-tools: Bash
    post-action: clear  # or "compact"
    ---
  2. Hookable /clear event: Add a PreClear / PostClear hook event so hooks can run git operations when /clear is triggered.

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions