Feature Request: Allow Claude to programmatically trigger /clear or /compact

Resolved 💬 3 comments Opened Jan 23, 2026 by choisangh Closed Jan 26, 2026

Feature Request

Problem

Currently, Claude Code cannot programmatically execute commands like /clear or /compact. These commands can only be triggered manually by the user.

Use Case

In workflow-based development with task management (e.g., Jira integration):

  1. Story/Task transitions: When completing Story #1 and starting Story #2, the context from Story #1 is no longer relevant and creates noise
  2. Branch switches: After git checkout to a different feature branch, previous branch context becomes stale
  3. Phase transitions: Moving from "planning" phase to "implementation" phase, or from "coding" to "testing"

Example workflow:

/work XM-100  → Work on story, accumulate context
/work done    → Complete story
              → [AUTO /compact or /clear here]
/work XM-101  → Start fresh with new story

Proposed Solution

Add a tool or hook that allows Claude to:

  • Execute /compact programmatically after completing a logical unit of work
  • Execute /clear when explicitly transitioning to unrelated work
  • Or provide a "workflow boundary" signal that triggers context cleanup

Benefits

  • Clean context when switching between unrelated tasks
  • Reduced token usage and faster responses
  • More focused context for each task
  • Better suited for agentic workflows with clear task boundaries

Additional Context

This is especially important for orchestrator patterns where Claude manages multiple stories/tasks in sequence. Each task deserves a clean context without pollution from previous unrelated work.

View original on GitHub ↗

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