Use OpenAI's official Responses API compaction v2 in OpenCode.
OpenCode can compact long coding sessions. When you are using OpenAI Responses models, this plugin sends a normal /responses request whose final input item is compaction_trigger, instead of asking another model to write a text summary.
| Default prompt summary | OpenAI native compaction |
|---|---|
| Generates a plain text summary | Returns an encrypted compaction item |
| Can miss tool or reasoning state | Built for the Responses API state model |
| App-owned summary format | Official Responses compaction output |
| You decide what to keep | OpenAI returns the next compacted window |
The important part is simple: compaction v2 returns an encrypted compaction item that should be passed to the next /responses request. This plugin makes OpenCode do that for OpenAI providers.
- Intercepts OpenCode session compaction for configured OpenAI providers.
- Sends the current Responses input window to
/responseswith a finalcompaction_triggeritem. - Removes OpenCode's internal summary prompt from the compact request body.
- Stores the compacted output in a local SQLite checkpoint.
- Injects that checkpoint into the next
/responsesrequest for the same session. - Replaces OpenCode's synthetic post-compaction exchange with the active checkpoint while preserving later real messages.
Use this if:
- You use OpenAI Responses API models in OpenCode.
- You run long coding sessions that hit compaction.
- You want OpenAI's official compaction item instead of a custom text summary.
Skip it if:
- You do not use OpenAI Responses API providers.
- You prefer OpenCode's default prompt-based summary.
- Your sessions are short enough that compaction does not matter.
Add the npm package to your OpenCode config.
For a local checkout during development, use a file URL.
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["file:///path/to/opencode-openai-compact"]
}Requirements:
| Runtime | Version |
|---|---|
| Node.js | >=22.12.0 |
| OpenCode | >=1.3.8 (Tested with 1.18.18) |
Most users do not need plugin-specific configuration.
Create openai-compact.json or openai-compact.jsonc only when you want to override defaults. Later layers override earlier layers. Within the same directory, openai-compact.jsonc is read after openai-compact.json and can override it.
Read order:
- Built-in defaults.
- Global OpenCode config directory:
openai-compact.json, thenopenai-compact.jsonc. - Directory from
OPENCODE_CONFIG_DIR:openai-compact.json, thenopenai-compact.jsonc. - Nearest project
.opencodedirectory found by walking upward from the current directory:openai-compact.json, thenopenai-compact.jsonc.
Global OpenCode config directory:
$XDG_CONFIG_HOME/opencode, whenXDG_CONFIG_HOMEis set.~/.config/opencode, whenXDG_CONFIG_HOMEis not set.
If neither openai-compact.json nor openai-compact.jsonc exists in the global OpenCode config directory, the plugin creates an empty openai-compact.jsonc file on first load.
Runtime checkpoints are stored in SQLite at:
~/.config/opencode/openai-compact/checkpoints.db
The default retention is 30 days. Checkpoints are deleted when OpenCode emits session.deleted.
{
"$schema": "https://raw.githubusercontent.com/partment/opencode-openai-compact/main/configSchema.json",
"enabled": true,
"providers": {
"openai": {
"compactModel": null,
"compactReasoningEffort": null
}
},
"headers": {
"compact": "x-opencode-openai-responses-compact",
"session": "x-opencode-openai-responses-compact-session"
},
"responses": {
"endpointPath": "/responses"
},
"compactBodyKeys": [
"input",
"instructions",
"tools",
"parallel_tool_calls",
"reasoning",
"service_tier",
"prompt_cache_key",
"text"
],
"summary": "Context compacted.\nFollowing conversations will continue from this compacted checkpoint.",
"state": {
"retentionDays": 30,
"deleteOnSessionDeleted": true
}
}| Field | Type | Default | Description |
|---|---|---|---|
enabled |
boolean |
true |
Enables or disables the plugin. |
providers |
object |
{ "openai": { "compactModel": null, "compactReasoningEffort": null } } |
Provider ids to wrap, keyed by OpenCode provider id. |
headers |
object |
see below | Internal header names. |
responses |
object |
see below | Responses endpoint path settings. |
compactBodyKeys |
string[] |
see example | Request body keys copied into compact calls. |
summary |
string |
see example | Synthetic assistant text emitted after compaction. |
state |
object |
see below | SQLite retention and delete behavior. |
| Field | Type | Default | Description |
|---|---|---|---|
compact |
string |
"x-opencode-openai-responses-compact" |
Internal header that marks a compaction request. |
session |
string |
"x-opencode-openai-responses-compact-session" |
Internal header that carries the OpenCode session id. |
| Field | Type | Default | Description |
|---|---|---|---|
providers.<id>.compactModel |
string | null |
null |
Model sent to the /responses compaction v2 request. null follows the model used by the latest conversation part for both automatic and manual compaction. |
providers.<id>.compactReasoningEffort |
"none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | null |
null |
Reasoning effort sent to compaction. null follows the current conversation selection. Supported levels vary by model. |
Priority: explicit setting > latest conversation part > OpenCode's original compaction request.
null uses the next available value in that order.
| Field | Type | Default | Description |
|---|---|---|---|
endpointPath |
string |
"/responses" |
Responses API path suffix to intercept. |
compactEndpointPath |
string |
"/responses/compact" |
Deprecated and ignored. Retained only so existing configuration files continue to load. |
| Field | Type | Default | Description |
|---|---|---|---|
retentionDays |
integer |
30 |
Number of days to keep checkpoints. |
deleteOnSessionDeleted |
boolean |
true |
Deletes checkpoints when OpenCode emits session.deleted. |
pnpm install
pnpm run typecheck
pnpm run test
pnpm run build
{ "$schema": "https://opencode.ai/config.json", "plugin": ["opencode-openai-compact"] }