[FEATURE] Add /unclear command to undo /clear and restore conversation context

Resolved 💬 5 comments Opened Mar 27, 2026 by oconnorjoseph Closed Jun 23, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

The /clear command is irreversible and destructive, yet it is trivially easy to invoke — a single unconfirmed slash command permanently destroys the entire conversation context with no recovery path.

This creates a high-severity usability problem in several common scenarios:

  1. Accidental invocation: A user deep into a productive multi-hour session — where Claude has built up rich understanding of the task, codebase state, prior decisions, and ongoing plan — accidentally runs /clear (muscle memory, typo, or misclick). The session is gone. There is no undo, no confirmation prompt, and no way to get back to where they were.
  1. Regretted invocation: A user intentionally clears context thinking they're done with a topic, then realizes moments later that they still needed that context — e.g., to reference a prior decision, revisit an approach Claude suggested, or continue a multi-step task.
  1. Exploratory clearing: A user wants to temporarily start fresh to test whether Claude performs better on a subtask without prior context biasing it, but wants the option to return to the full-context session if the fresh start doesn't pan out.

The impact scales with session length and complexity. The more valuable the accumulated context, the more devastating an accidental or regretted /clear becomes. Users working on complex, multi-file refactors or architectural tasks — precisely the sessions where Claude Code provides the most value — are the most harmed.

Current workarounds are inadequate:

  • Asking Claude to "save your context to a file" before clearing only produces a lossy summary — it cannot capture the full internal conversation state, tool call history, or nuanced understanding Claude has built up.
  • The memory system (# annotations, CLAUDE.md) captures long-term facts but not session-specific working state.
  • There is no session snapshot/restore mechanism.

Proposed Solution

Add an /unclear command (or /clear --undo) that restores the conversation state from immediately before the most recent /clear was executed.

Proposed behavior:

  • /clear continues to work exactly as it does today, but internally snapshots the full conversation state before discarding it.
  • /unclear restores the most recent snapshot, bringing back the complete conversation as it was before /clear.
  • Only the single most recent /clear needs to be undoable (not an unlimited undo stack).
  • If /unclear is run when there is no snapshot to restore (e.g., at the start of a session, or after the snapshot has been garbage-collected), it should display a clear message: "No previous session to restore."
  • The snapshot should persist for the duration of the Claude Code process (i.e., until the terminal/IDE session is closed). It does not need to survive across process restarts.

Optional enhancements (not required for the core feature):

  • A confirmation prompt before /clear executes (e.g., "Clear conversation context? This can be undone with /unclear. [y/N]") — though this may annoy power users, so it could be opt-in via settings.
  • Displaying a brief hint after /clear: "Context cleared. Run /unclear to restore."

Alternative Solutions

  1. Confirmation prompt on /clear: Adding a "are you sure?" prompt would prevent accidental clears but doesn't help with regretted intentional clears. It also adds friction to every /clear invocation, even when the user is certain.
  1. Session bookmarks / named snapshots: A more general /snapshot save <name> / /snapshot restore <name> system would be more powerful but is significantly more complex to implement and represents a different (broader) feature. /unclear is a minimal, targeted solution to the most common pain point.
  1. Auto-persist all session history to disk: Writing every conversation turn to a recoverable log would allow arbitrary restoration but raises storage, privacy, and performance concerns. This is a heavier architectural change.
  1. Asking Claude to summarize context to a file before clearing: This is what users do today. It is lossy — the summary cannot capture tool call history, file read results, or the full conversational nuance. It's a workaround, not a solution.

Priority

High - Significant impact on productivity

Feature Category

Interactive mode (TUI)

Use Case Example

Scenario: Accidental clear during complex refactor

  1. A developer is 45 minutes into a session where Claude has been helping refactor an authentication system across 12 files
  2. Claude has built up deep context: which files were changed, what the migration strategy is, which tests need updating, and what's left to do
  3. The developer types /clear accidentally (intended to type /compact, or hit enter on a previous /clear still in shell history)
  4. All context is gone — Claude no longer knows which files were touched, what the refactor strategy was, or what remains
  5. The developer has no way to recover. They must either start over (re-explaining everything) or abandon the session

With /unclear:

  1. The developer runs /unclear
  2. The full conversation state is restored — Claude picks up exactly where it left off
  3. Zero time lost, zero context re-explanation needed

Additional Context

This is a frequently reported pain point in community discussions. The asymmetry between how easy /clear is to invoke (one command, no confirmation) and how catastrophic its effect is (total, irreversible context loss) makes it one of the sharpest edges in the Claude Code UX.

The implementation should be lightweight — the conversation state already exists in memory before /clear discards it. The core change is simply: don't discard it, stash it.

View original on GitHub ↗

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