Skip to content

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

Closed

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

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Feb 18, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 18, 2026
  3. github-actions commented on Apr 20, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions