-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: Compaction Recovery
opencode compacts long sessions by generating a summary and replacing the conversation history. Without intervention, a compacted session would lose awareness of thatch -- the agent would stop using memory tools, extraction would stop, and nudges would fire during summary generation where tools are blocked.
- Suppresses nudges during compaction (tools are blocked during summary generation)
- Injects compaction context so the agent retains awareness of thatch after compaction
- Clears the compacting flag on success (three mechanisms, belt-and-suspenders)
- Handles compaction failure (clears stale flag if autocontinue never fired)
-
experimental.session.compacting (hook) -- fires when opencode starts compacting. Adds sessionID to the
compactingset. PushescompactionContext(repo)intooutput.context. The context tells the agent to preserve what's been learned and decided this session so there's continuity after compaction. -
experimental.compaction.autocontinue (hook) -- fires after compaction succeeds and the auto-continue turn fires. Removes sessionID from the
compactingset so nudges resume. -
session.compacted (event) -- fires on successful compaction. Clears the
compactingflag. Belt-and-suspenders: if autocontinue didn't fire or wasn't installed, the event still clears the flag. -
Compaction failure fallback (chat.message hook) -- if a non-compaction chat.message arrives while the session is in the
compactingset, compaction failed (autocontinue never fired). The hook clears the stalecompactingflag and proceeds normally. Without this, the session would be stuck with nudges off forever.
During summary generation, tools are blocked. A nudge that instructs the agent to use thatch_memory_recall or thatch_memory_remember would cause a blocked-tool error. The compacting set is checked at the top of the chat.message hook -- if the session is compacting, all nudges are skipped.
compactionContext(repo) in src/prompts.ts generates text that tells the agent: you are using thatch, here's what you've learned and decided this session, preserve this context after compaction. This is pushed into output.context (not output.system) so it's part of the compaction output, not the permanent system prompt.
- Nudge pipeline (nudge-pipeline.md): compaction guard is the first check in the chat.message hook; suppresses all 4 tiers
- Session lifecycle (session-lifecycle.md):
session.compactedevent is handled in the event handler - Multi-host (multi-host.md): compaction recovery is opencode-only. Claude Code and Cursor do not have this feature. Mitigation:
CLAUDE.md/AGENTS.mdpersists through compaction, and SessionStart hooks fire after compaction.
-
src/runtime.ts-- all four hooks/events (experimental.session.compacting, experimental.compaction.autocontinue, session.compacted event, chat.message compaction guard on v1; session.hook("compaction")/("prompt") on v2), shared by both adapters -
src/prompts.ts-- compactionContext function
- The
compactingset is checked at the top of chat.message. If set, all nudges are skipped. - Three mechanisms clear the flag (autocontinue, session.compacted event, chat.message fallback). Belt-and-suspenders.
- Compaction failure fallback: a non-compaction message during compacting = compaction failed. Clear and proceed.
- opencode-only feature. MCP hosts rely on static instructions persisting through compaction.
User
- Guide: Behavior Engine
- Guide: Cli
- Guide: Code Review
- Guide: Commands
- Guide: Cross Session Chat
- Guide: Deduplication
- Guide: Default Behaviors
- Guide: Extraction
- Guide: Hygiene
- Guide: Memory
- Guide: Notifications
- Guide: Prediction Engine
- Guide: Overview
- Guide: Setup
- Guide: Skills
- Guide: Watchers
Developer
Dev Feature Guides
- Feature: Behavior Engine
- Feature: Cicd
- Feature: Cli
- Feature: Commands
- Feature: Compaction Recovery
- Feature: Cross Session Chat
- Feature: Database
- Feature: Deduplication
- Feature: Extraction
- Feature: Hygiene
- Feature: Memory Store
- Feature: Multi Host
- Feature: Notifications
- Feature: Nudge Pipeline
- Feature: Opencode Plugin
- Feature: Prediction Engine
- Feature: Qa System
- Feature: Overview
- Feature: Repo Identity
- Feature: Session Lifecycle
- Feature: Setup
- Feature: Sideband
- Feature: Watchers