Skip to content

Allow tools/skills to programmatically clear context and inject a continuation prompt #35150

Description

@peterdrier

Context

When working on long, multi-step tasks, the context window fills up and performance degrades. The natural response is to clear and continue, but this destroys all accumulated context — decisions made, files identified, progress tracked, corrections given.

Problem / Motivation

There is no programmatic way for a skill or tool to:

  1. Summarize the current session context
  2. Clear the conversation
  3. Inject a continuation prompt into the fresh session

This means the human must manually orchestrate the "save context → clear → restore context" bridge every time. It's error-prone, breaks flow, and is exactly the kind of repetitive task that should be automatable.

Real-world use case: A /cls skill that the user invokes when context is getting heavy. The skill gathers git state, conversation decisions, active tasks, and the user's gist of what's next — then clears the conversation and injects the summary so Claude picks up seamlessly. Today this is impossible because:

  • Skills cannot invoke /clear
  • There is no PostClear hook event
  • SessionStart hooks cannot inject prompt content
  • Hooks generally cannot submit text into the conversation

The workaround is for the skill to save a summary to a file, then the user manually runs /clear, then manually types "read the file and continue." This defeats the purpose of having a skill.

Related: #32861

Proposed Solution

Enable one or more of these mechanisms (in order of preference):

Option A: Tool-invocable clear with continuation

A tool like ClearContext that a skill can call programmatically:

ClearContext({ continuation_prompt: "I'm continuing from a previous session..." })

This clears the conversation and injects the continuation as the opening message.

Option B: PostClear hook with prompt injection

Add a PostClear hook event that fires after /clear. Allow hooks of type "prompt" to inject text into the fresh session:

{
  "hooks": {
    "PostClear": [{
      "hooks": [{ "type": "prompt", "promptTemplate": "Read {{file}} and continue" }]
    }]
  }
}

Option C: /clear --run <prompt-or-file>

A built-in flag that clears and then submits a prompt or reads a file:

/clear --run "read local/cls-prompt.md and continue"

This is the simplest to implement but limits automation to what the human types.

Any of these would unblock the use case. Option A is the most powerful (skills can fully orchestrate the flow). Option C is the simplest to ship.

Acceptance Criteria

  • A skill or tool can programmatically trigger a context clear
  • A continuation prompt can be injected into the fresh session without user action
  • The user initiates the flow (not automatic) — this is a human-in-the-loop bridge action
  • Works in both CLI and IDE integrations

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