Summary
Burn's OpenCode session reader (packages/reader/src/opencode.ts) does not detect context compaction events, while Claude Code and Codex readers already support this. This means burn waste --kind compaction cannot report compaction losses for OpenCode sessions.
Background
OpenCode emits compaction events as message parts with type: "compaction" (see OpenCode compaction.ts) and fires a session.compacted bus event. The CompactionEvent type (packages/reader/src/types.ts:307-318) is already defined and used by other readers.
Existing implementations
- Claude Code: Detects
compact_boundary system markers (claude.ts:330)
- Codex: Detects
type: "compacted" session records (codex.ts:471)
Implementation Steps
-
Detect compaction parts in parseOpenCodeSession and parseOpenCodeSessionIncremental:
- Parse OpenCode session JSONL for message parts with
type: "compaction"
- Extract
sessionID, messageID, auto flag from the compaction part
-
Anchor to preceding turn:
- Match each compaction event to the immediately preceding assistant turn (store
precedingMessageId)
- Capture
tokensBeforeCompact from the preceding turn's cache read tokens (same pattern as Claude/Codex)
-
Emit CompactionEvent:
- Push
CompactionEvent objects to the events array returned by the parser
- Follow the existing
CompactionEvent schema (types.ts:307-318)
-
Wire through ledger pipeline:
- Existing
appendCompactions → CompactionLine → queryCompactions → burn waste --kind compaction will automatically pick up OpenCode compaction events once emitted by the reader
References
- OpenCode
CompactionPart type: SDK types
- Burn
CompactionEvent interface: packages/reader/src/types.ts:307-318
- Claude compaction detection:
packages/reader/src/claude.ts:330
- Codex compaction detection:
packages/reader/src/codex.ts:471
- Ledger compaction writer:
packages/ledger/src/writer.ts:83
Summary
Burn's OpenCode session reader (
packages/reader/src/opencode.ts) does not detect context compaction events, while Claude Code and Codex readers already support this. This meansburn waste --kind compactioncannot report compaction losses for OpenCode sessions.Background
OpenCode emits compaction events as message parts with
type: "compaction"(see OpenCode compaction.ts) and fires asession.compactedbus event. TheCompactionEventtype (packages/reader/src/types.ts:307-318) is already defined and used by other readers.Existing implementations
compact_boundarysystem markers (claude.ts:330)type: "compacted"session records (codex.ts:471)Implementation Steps
Detect compaction parts in
parseOpenCodeSessionandparseOpenCodeSessionIncremental:type: "compaction"sessionID,messageID,autoflag from the compaction partAnchor to preceding turn:
precedingMessageId)tokensBeforeCompactfrom the preceding turn's cache read tokens (same pattern as Claude/Codex)Emit CompactionEvent:
CompactionEventobjects to theeventsarray returned by the parserCompactionEventschema (types.ts:307-318)Wire through ledger pipeline:
appendCompactions→CompactionLine→queryCompactions→burn waste --kind compactionwill automatically pick up OpenCode compaction events once emitted by the readerReferences
CompactionParttype: SDK typesCompactionEventinterface:packages/reader/src/types.ts:307-318packages/reader/src/claude.ts:330packages/reader/src/codex.ts:471packages/ledger/src/writer.ts:83