anomalyco / anomalyco/opencode

[FEATURE]: allow user to inject custom instruction when compacting a session

Open
#42,574 0 comments 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Aug 14, 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

When a session is compacted, the LLM generates a structured summary of the conversation. However, the user has no way to provide per-compaction guidance — e.g., what to prioritize in the summary, what information is no longer relevant, or what the next work focus should be.

The existing experimental.session.compacting plugin hook can inject context into the compaction prompt, but:

  • It only receives { sessionID } — no per-invocation dynamic input
  • The injected content is static (determined by plugin code), not changeable per compaction

Additionally, the recent conversation that the user might use to convey such guidance is often excluded from the compaction scope (it falls into the "recent" portion that is preserved verbatim), so the compaction LLM never sees it.

Proposal

Allow the user to pass an optional instruction string when triggering a compaction, which gets appended to the compaction LLM prompt.

Suggested changes
  1. API layer — Add instruction?: string to SummarizePayload (packages/opencode/src/server/routes/instance/httpapi/groups/session.ts)

  2. Handler — Pass instruction through compactSvc.create()compaction.process() (packages/opencode/src/session/compaction.ts)

  3. Compaction prompt — Append the user instruction to the summary prompt in processCompaction:

    if (input.instruction) {
      nextPrompt += `\n\nAdditional user instruction for this compaction:\n${input.instruction}`
    }
    
  4. TUI — When the user triggers /compact (or c), show a DialogPrompt input box (already available at packages/tui/src/ui/dialog-prompt.tsx) with a placeholder like "Optional: guide the compaction (what to prioritize, what to drop)…". The user can type a one-liner or leave it empty and press Enter to proceed.
    Why

  • Per-compaction guidance is a common pattern in agent frameworks (e.g., Claude Code's /compact with optional instructions)
  • The change is minimal — one field threaded through 4 layers, each just passing it along
  • No breaking changes — instruction is optional; existing behavior is preserved when it's absent
    Context
  • Current compaction implementation: packages/opencode/src/session/compaction.ts (V1 path, actively used)
  • V2 core compaction (packages/core/src/session/compaction.ts) does not yet support plugin hooks; this proposal should be considered for both paths
  • DialogPrompt component already exists and is used by other commands (e.g., session rename, provider config)

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.