Summary
Implement Codex-style conversation compaction inside the plugin, including a /compact-like flow and optional auto-compaction heuristics, while staying compatible with opencode's existing behavior (and future core-level compaction support).
Background
openai/codex treats compaction as a first-class capability:
codex-rs/core/src/compact.rs defines a SUMMARIZATION_PROMPT and compaction logic.
codex-rs/core/src/tasks/compact.rs and docs/slash_commands.md expose a /compact slash command.
openai_model_info.rs and docs/config.md reference auto_compact_token_limit, enabling automatic history compaction based on model token limits.
In this plugin:
- In CODEX_MODE we currently strip OpenCode's own auto-compaction prompt because it references a summary file path that doesn't exist for our stateless ChatGPT backend.
- We rely on
store: false + include: ["reasoning.encrypted_content"] to keep enough context across turns but don't offer a plugin-specific compact/summary flow.
There is now a core feature request in sst/opencode for a provider-agnostic /compact command and auto-compaction, but the plugin can already start building a Codex-specific compaction story on top of today's API.
Proposed Behavior
-
Plugin-level /codex-compact command
- Implement a plugin-specific slash command or special user input pattern (e.g.
/codex-compact) handled entirely in the plugin.
- Behavior:
- Use a compaction prompt derived from Codex CLI's
SUMMARIZATION_PROMPT to ask the model for a handoff summary of the current conversation.
- Replace the existing conversation history (as seen by the plugin) with:
- The summary message, and
- The current encrypted reasoning content (
reasoning.encrypted_content) if available.
- Ensure the compaction turn itself is not treated as user instructions for the actual task (i.e., subsequent turns operate on the summary, not the compaction instructions).
-
Optional auto-compaction heuristics (plugin-side)
- Estimate conversation size using a cheap token approximation over:
body.input, and
reasoning.encrypted_content (when present).
- When an approximate token threshold is reached (configurable in the plugin config file), automatically run the plugin-level compaction flow before sending the next user request to Codex.
- Keep this behavior opt-in via plugin config (e.g.
enableCodexCompaction, autoCompactTokenLimit).
-
Integration with prompt_cache_key and forks
- When compaction runs, ensure that:
- The
prompt_cache_key remains stable for simple resume flows (same conversation identity).
- If a compaction is used as a branch point (fork), it can cooperate with the fork-aware
prompt_cache_key behavior (see related issue for fork-aware caching).
- Add tests that mirror Codex's
compact_resume_fork.rs semantics as closely as possible with the information we have.
-
Forward compatibility with opencode core
- Design the plugin-level compaction logic so that, if opencode later introduces a generic
/compact command and provider hooks (as proposed in sst/opencode), the plugin can:
- Map the core
/compact action onto its existing compaction prompt and state update.
- Gradually deprecate the plugin-only
/codex-compact alias in favor of the core command.
Rationale
- Gives users of the Codex plugin a clear, documented way to compact long conversations, independent of the host's current compaction implementation.
- Aligns better with Codex CLI features users may already rely on (
/compact, auto_compact_token_limit).
- Provides a concrete design target for future integration with opencode core compaction hooks.
Acceptance Criteria
- A
/codex-compact (or equivalent) command exists and is handled entirely in the plugin.
- Compaction produces a stable, reversible summary that can be used for subsequent turns without breaking the Codex-mode bridge or reasoning continuity.
- Optional auto-compaction behavior is configurable and disabled by default.
- New tests cover:
- Basic compaction (manual command).
- Auto-compaction when token thresholds are exceeded.
- Interactions with
prompt_cache_key and forks (in combination with the fork-aware caching feature).
Summary
Implement Codex-style conversation compaction inside the plugin, including a
/compact-like flow and optional auto-compaction heuristics, while staying compatible with opencode's existing behavior (and future core-level compaction support).Background
openai/codextreats compaction as a first-class capability:codex-rs/core/src/compact.rsdefines aSUMMARIZATION_PROMPTand compaction logic.codex-rs/core/src/tasks/compact.rsanddocs/slash_commands.mdexpose a/compactslash command.openai_model_info.rsanddocs/config.mdreferenceauto_compact_token_limit, enabling automatic history compaction based on model token limits.In this plugin:
store: false+include: ["reasoning.encrypted_content"]to keep enough context across turns but don't offer a plugin-specific compact/summary flow.There is now a core feature request in
sst/opencodefor a provider-agnostic/compactcommand and auto-compaction, but the plugin can already start building a Codex-specific compaction story on top of today's API.Proposed Behavior
Plugin-level
/codex-compactcommand/codex-compact) handled entirely in the plugin.SUMMARIZATION_PROMPTto ask the model for a handoff summary of the current conversation.reasoning.encrypted_content) if available.Optional auto-compaction heuristics (plugin-side)
body.input, andreasoning.encrypted_content(when present).enableCodexCompaction,autoCompactTokenLimit).Integration with
prompt_cache_keyand forksprompt_cache_keyremains stable for simple resume flows (same conversation identity).prompt_cache_keybehavior (see related issue for fork-aware caching).compact_resume_fork.rssemantics as closely as possible with the information we have.Forward compatibility with opencode core
/compactcommand and provider hooks (as proposed insst/opencode), the plugin can:/compactaction onto its existing compaction prompt and state update./codex-compactalias in favor of the core command.Rationale
/compact,auto_compact_token_limit).Acceptance Criteria
/codex-compact(or equivalent) command exists and is handled entirely in the plugin.prompt_cache_keyand forks (in combination with the fork-aware caching feature).