Skip to content

[FEATURE]:Add pre-compaction hook for session save/export #14164

@shplatt

Description

@shplatt

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

Description:

When a long conversation triggers context compaction, the full conversation history is permanently lost -- only a summary survives. There's currently no way to automatically save or export the session before this happens.

Related issues: #9387 (session export CLI), #7579 (plan persistence across compaction). This request differs in that it proposes an automatic local save triggered before compaction runs, rather than a manual export command.

Use case:

During extended coding sessions, compaction can trigger unexpectedly. The /share command exists but requires manual intervention (and cloud authentication). Users working in air-gapped or corporate environments may not have access to /share at all.

Proposed solution:

Add a pre-compaction lifecycle hook that fires before the context is compacted. This could support:

  1. Auto-export to a local file -- save the full conversation (messages + tool outputs) to a local file (e.g., .opencode/sessions/) before compaction runs
  2. Plugin hook -- expose a beforeCompaction event in the plugin system so users can implement custom save logic
  3. Config option -- a simple config flag like compaction.save_before: true that writes a local snapshot automatically

Example config:

{
  "compaction": {
    "auto": true,
    "save_before": true,
    "save_path": ".opencode/sessions/"
  }
}

Why this matters:

  • Long sessions accumulate valuable context about decisions, debugging steps, and rationale that's useful to revisit later
  • Compaction summaries lose nuance and exact details
  • A local-first approach works in all environments without requiring cloud auth

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions