Skip to content

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

Description

@danry446

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions