[FEATURE] Add opaque/deep compaction for long-running coding sessions

Status Closed — not planned
Maintainer reply None cached
Activity 5 comments · opened Jun 30, 2026 · closed Sep 16, 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

Claude Code’s current compaction workflow is very helpful, but in long-running coding sessions it can still lose important working state after compaction.

In practice, I rarely inspect the compacted summary in detail. What I care about most is not whether the summary is human-readable, but whether Claude Code can continue the task reliably after compaction without losing:

  • the current implementation plan
  • files already changed and why
  • failed approaches and why they were abandoned
  • test commands and their results
  • subtle constraints discovered during debugging
  • decisions that should not be revisited
  • the next concrete steps

For long coding tasks, a human-readable summary can be too lossy. It is useful for review, but it may not be the most efficient representation for the model itself.

The current behavior makes long sessions feel fragile: after compaction, Claude Code can sometimes become less aware of the exact state of the work, requiring the user to restate context or manually maintain state in files.

Proposed Solution

I would like Claude Code to support a deeper, model-oriented compaction mode in addition to the current human-readable summary-based compaction.

Ideally, Claude Code would maintain two layers of compacted context:

  1. Human-readable summary
  • high-level task status
  • changed files
  • current plan
  • unresolved issues
  • next steps
  1. Model-oriented opaque/deep compaction state
  • a high-density internal representation optimized for continuation
  • not necessarily human-readable
  • focused on preserving detailed working state across long sessions

This could be exposed as an option such as:

  • /compact --deep
  • /compact --preserve-state
  • a setting like compaction.mode = "deep"
  • automatic deep compaction when the context window approaches the limit

The goal is not to remove the current readable /compact behavior. The readable summary is still valuable. The request is to add a deeper continuation-oriented compaction layer for users who prioritize long-session reliability over inspectability.

It would also be useful if /context showed that such a deep compaction state exists, when it was created, and roughly how much context it preserves, without necessarily exposing its full contents.

Alternative Solutions

Current workarounds include:

  • Manually asking Claude Code to summarize the session before compaction
  • Using /compact with detailed focus instructions
  • Writing important state into CLAUDE.md, TODO files, scratchpads, or implementation notes
  • Keeping external notes about changed files, test results, and decisions
  • Starting a new session and pasting a hand-written state summary

These workarounds help, but they add manual overhead and are easy to forget during intense debugging or refactoring sessions.

The existing human-readable compaction is useful, but it still feels optimized for readability rather than maximum task-continuation fidelity.

Priority

High - Significant impact on productivity

Feature Category

Performance and speed

Use Case Example

_No response_

Additional Context

Other coding agents and APIs are exploring continuation-oriented compaction approaches where the compacted state is not necessarily exposed as a fully human-readable summary, but is optimized for preserving task state across long-running agentic work.

For example, OpenAI Codex / Responses API has a concept of opaque or encrypted compaction items for carrying forward compressed context. I am not asking Claude Code to copy that implementation directly, but I think Claude Code could benefit from a similar product-level capability: a deeper, model-oriented compaction mode that prioritizes long-session continuity over human readability.

For Claude Code, the ideal design could be hybrid:

  • keep the current readable summary for transparency
  • add a deeper model-oriented compaction layer for continuity
  • allow users to choose between normal compaction and deep/state-preserving compaction
  • allow focus instructions, e.g. /compact --deep focus on tests, changed files, failed attempts, and unresolved decisions

The key point is that many users do not carefully inspect the compaction output every time. For long coding sessions, preserving execution continuity may be more valuable than making the compacted context fully readable.

View original on GitHub ↗

3 Comments

github-actions[bot] · 3 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/70555
  2. https://github.com/anthropics/claude-code/issues/62903
  3. https://github.com/anthropics/claude-code/issues/34556

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

spira-unplugged · 3 months ago

I reviewed #70555, #62903, and #34556. They are closely related, but I think this request is distinct.

The existing issues mainly focus on persistent memory, structured handoff, working scratchpads, hooks, or durable state re-injection across compaction and session boundaries.

This issue specifically asks for a model-oriented opaque/deep compaction layer inside the compaction mechanism itself, in addition to the current human-readable summary. The goal is not only to save state externally, but to make compaction itself more suitable for long-running model continuation.

I see these as complementary approaches rather than exact duplicates.

junaidtitan · 3 months ago

The frustration here is legitimate — current compaction answers "what happened" and discards "where exactly are you right now." Failed approaches and "don't revisit this" decisions are precisely the things that don't survive, because they're absence-of-action, and absences don't summarize.

The specific list you want preserved across compaction — implementation plan, files already changed and why, failed approaches, test commands and results, subtle constraints, decisions not to revisit, next concrete steps — breaks cleanly into two categories: what happened (file changes, test results — the narrative parts), and behavioral/decision state (failed approaches, constraints discovered, decisions locked in). Current compaction mostly handles the first category. It systematically loses the second.

The closest working version of this before Anthropic builds it natively:

cozempic runs a behavioral digest on the session JSONL that specifically targets the second category. It extracts behavioral corrections, discovered constraints, and "don't do X" decisions in prohibition-framed form (the framing that survives to actual compliance rather than being remembered and ignored), and re-injects them at the tail post-compaction where attention is highest. That covers the "failed approaches" and "decisions not to revisit" items on your list.

It also does pre-compaction JSONL pruning: strips historical tool output that's dead weight for the summarizer, which means the compaction summary has denser, more recent material to work with — so more of the what happened narrative survives too.

Honest scope: no actual "opaque/deep" compaction layer is built. Cozempic works externally on the JSONL and doesn't touch the compaction engine itself — it can't preserve structured state about specific file changes or exact test output (those need the compaction contract to change). What it does cover is the behavioral/decision-memory part of your list, which is also the part most likely to cause the "confidently wrong continuation" failure you described.

Showing cached comments. Read the full discussion on GitHub ↗