anomalyco / anomalyco/opencode

[FEATURE]: Compaction: deterministic retention of user messages and a configurable compaction prompt

Open
#49,463 0 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Sep 17, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Feature hasn't been suggested before.
  • I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request

Problem / use case

After compaction the model only sees the summarizer's output plus a recent token tail. The original user messages and tool results are still in the session history, but they are no longer part of what the model sees. In practice this means requirements I stated at the start of a session, and constraints I set mid-session, stop being followed. Each subsequent compaction loses whatever the previous summary didn't carry forward, so degradation compounds over a long session.

There is also no config-level way to steer what must be preserved. The compaction summarizer runs without any system prompt or user-provided instructions. The experimental.session.compacting hook can replace the prompt, but it only receives { sessionID } — no per-invocation dynamic input — and it does not fire on the prune path.

Proposed solution

  1. Keep user messages visible verbatim after compaction (at minimum the first message, optionally pinned ones), independent of the LLM summary. Since the history rows are retained anyway, this is a projection decision rather than a storage change.
  2. A config-level way to supply persistent compaction instructions (for example a compaction.prompt or compaction.instructions field), and/or giving the compacting hook per-invocation input so it can decide dynamically what must be carried forward. Ideally the same mechanism applies to the prune path, which today preserves nothing.

This request is about fidelity semantics, not about restructuring the compaction pipeline.

Alternatives considered

  • The experimental.session.compacting hook: covers prompt replacement only; no config-level support and no deterministic retention semantics.
  • AGENTS.md re-injection (#43723, merged) already covers on-disk constraint files. This request is about session content, not files.

Similar requests

I have searched for similar requests. #37551 (closed, not planned) proposed reinjecting a prompt; PR #38103 (closed, unmerged) attempted verbatim user messages; PR #45125 (open) proposes a restoration document, but even if merged it remains summarizer-mediated, not deterministic retention. #42574 (open) asks for configurable compaction instructions but not for user-message retention. #41358 (open) asks to keep the original user goal in the summary — again summarizer-mediated. #16512 and #16960 describe the same underlying pain. I believe this request is still distinct: it asks for deterministic (not summarizer-mediated) retention, plus a config surface for compaction instructions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.