Feature Request: Programmatic Context Clear (Tool or Skill Primitive)

Resolved 💬 2 comments Opened May 25, 2026 by danblake Closed May 29, 2026

The Problem

When working on long sessions with Claude Code, context windows accumulate stale information - resolved bugs, abandoned approaches, superseded decisions, old file contents. Compaction helps extend the window, but it can't solve the fundamental issue: compacted context preserves noise alongside signal. A compacted summary of a 2-hour debugging detour still takes up space and can mislead the model, even after the bug is fixed and the approach has changed.

The cleanest recovery is a full context reset - snapshot state, clear the window, then resume with only the information that matters going forward. This is the workflow I've built with two custom skills:

  1. /context-push - This is not a simple save. It runs a multi-step teardown of the current session:
  • Runs a coverage gate to ensure test coverage hasn't regressed below 80%
  • Snapshots work status to persistent memory files (branch, progress, decisions, gotchas)
  • Writes a session log capturing every user directive, correction, and decision from the conversation
  • Archives raw JSONL transcripts to the repo (via Git LFS for large files)
  • Regenerates cross-session pattern analysis from all prior session logs
  • Updates release plans, roadmaps, and status dashboards to reflect work shipped
  • Commits and pushes the project repo
  • Commits and pushes any global Claude config changes (skills, memory, settings)
  • Writes a structured resume prompt to context-push.md containing the branch, last commit, what's done, what's next, and key context
  1. /context-pop - Reads context-push.md and rehydrates the session: orients to the branch, reads memory, and picks up the work described in the resume prompt.

Between these two steps, the user must manually type /clear to reset the context window. This is the gap.

Why Compaction Isn't Enough

Compaction is great for extending a productive session. But there are scenarios where you genuinely need a clean slate, not a compressed version of the old one:

  • Accumulated wrong turns. You spent 45 minutes trying approach A before discovering it was fundamentally wrong. Compaction preserves a summary of approach A - its files, its rationale, its partial implementation. The model may unconsciously anchor to that summary even after you've pivoted to approach B.
  • Context pollution from large reads. You read 15 files to diagnose an issue. You now know only 3 of them matter. Compaction can't know which 3 - it preserves summaries of all 15, diluting the signal.
  • Session handoff. You want to hand work from one session to another (e.g., switching machines, resuming tomorrow, or simply starting fresh after a messy debugging session). The resume prompt captures exactly what the next session needs - nothing more, nothing less. Compaction would carry forward the mess.
  • Skill-driven workflows. A single /context-reset skill could atomically push state, clear the window, and pop state - a one-command "refresh" that keeps only what matters. Today this requires three manual steps across two skills with a built-in command sandwiched between them.

What I'm Requesting

Expose context clearing as a tool or skill-invocable primitive so that skills and automated workflows can trigger it programmatically. This would allow:

/context-reset
  ├── Step 1: context-push (snapshot state, commit, write resume prompt)
  ├── Step 2: Clear context (no manual /clear needed)
  └── Step 3: context-pop (read resume prompt, rehydrate)

Today, Step 2 is only available via the interactive /clear command, which the user must type manually. There's no tool, no API, no way for a skill to invoke it.

Proposed Solutions (in order of preference)

  1. A ClearContext tool - callable from skills like any other tool. The skill invokes it, the context resets, and execution continues in the fresh window with whatever the skill passes forward.
  1. A context.clear() primitive in the skill runtime - similar to the above but scoped to skill internals rather than the general tool surface.
  1. A post-skill lifecycle hook - allow a skill to declare "clearContextAfter": true in its metadata, so the system clears context after the skill completes and before the next turn.

Any of these would let me collapse push/clear/pop into a single atomic operation.

Impact

This is a quality-of-life improvement for anyone building multi-session workflows, but it's also a correctness improvement. The manual /clear step is a reliability gap - if the user forgets it, /context-pop runs in the old polluted context and the whole point of the reset is lost. Making it programmatic eliminates that failure mode.

View original on GitHub ↗

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