skills/compact/SKILL.md
Compact session context — save work artifacts to state and update CHANGELOG with recent changes. Use when session context is full or before switching tasks.
npx skillsauth add Thomashighbaugh/opencode compactInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Save a structured snapshot of the current session to disk and record any code changes in the project CHANGELOG. Use this skill when the session context window is approaching capacity, before switching to a different task, or when you want to preserve work products before a context compaction event.
experimental.session.compacting) fires and you want to ensure artifacts are savedgit log for agent consumptionRead the heartbeat and session-stats files to collect current metrics:
| Source | Path | Fields |
|--------|------|--------|
| Heartbeat | .opencode/state/sessions/{sessionId}/heartbeat.json | toolCount, recentTools, todoProgress |
| Session stats | ~/.config/opencode/.session-stats.json | tool_counts, total_calls, started_at, updated_at |
Run git diff --stat to detect files modified since the last compaction. If there are changes, capture the list of changed files for the CHANGELOG entry.
Write a structured JSON artifact to:
.opencode/state/sessions/{sessionId}/compaction-{timestamp}.json
Artifact schema:
{
"sessionId": "string",
"compactedAt": "ISO-8601 timestamp",
"toolCalls": "number (total tool calls from heartbeat)",
"durationSeconds": "number (session duration from session-stats)",
"subagentInvocations": "number (Task tool count from session-stats)",
"modeState": {
"ralph": {
"active": "boolean",
"iteration": "number",
"prompt": "string"
} | null,
"ultrawork": {
"active": "boolean",
"originalPrompt": "string",
"reinforcementCount": "number"
} | null
},
"todoProgress": {
"completed": "number",
"remaining": "number",
"pending": "number",
"inProgress": "number"
} | null,
"recentTools": [
{
"name": "string",
"time": "ISO-8601 timestamp"
}
],
"preservedContext": "string[] (key context items preserved)"
}
If git diff --stat shows changes, append an entry to .opencode/CHANGELOG.md (create the file if it doesn't exist):
## [compaction-{timestamp}]
- Session: {sessionId}
- Tool calls: {count}
- Duration: {durationSeconds}s
- Files changed: {list from git diff --stat}
Output a concise summary of what was saved:
Compaction saved to: .opencode/state/sessions/{sessionId}/compaction-{timestamp}.json
CHANGELOG updated: {yes/no}
Tool calls: {count}
Duration: {durationSeconds}s
Files changed: {count}
| Input | Source | Description |
|-------|--------|-------------|
| sessionId | getSessionID tool | Current session identifier |
| directory | Project root | Working directory for path resolution |
| heartbeat | .opencode/state/sessions/{sessionId}/heartbeat.json | Tool call metrics and todo progress |
| sessionStats | ~/.config/opencode/.session-stats.json | Session timing and tool counts |
| gitDiff | git diff --stat | Code changes since last commit |
| Output | Path | Description |
|--------|------|-------------|
| Compaction artifact | .opencode/state/sessions/{sessionId}/compaction-{timestamp}.json | Structured session snapshot |
| CHANGELOG entry | .opencode/CHANGELOG.md | Record of code changes (if any) |
compaction-2026-06-20T12-00-00-000Z.json){
"sessionId": "abc123-def456",
"compactedAt": "2026-06-20T14:30:00.000Z",
"toolCalls": 142,
"durationSeconds": 3840,
"subagentInvocations": 8,
"modeState": {
"ralph": {
"active": true,
"iteration": 4,
"prompt": "Fix all TypeScript errors in src/"
},
"ultrawork": null
},
"todoProgress": {
"completed": 12,
"remaining": 3,
"pending": 2,
"inProgress": 1
},
"recentTools": [
{ "name": "Edit", "time": "2026-06-20T14:29:45.000Z" },
{ "name": "Read", "time": "2026-06-20T14:29:30.000Z" },
{ "name": "Bash", "time": "2026-06-20T14:29:15.000Z" }
],
"preservedContext": [
"## Ralph Loop State\n- Iteration: 4/10\n- Original Task: Fix all TypeScript errors in src/",
"## Pending Tasks\n[1 active, 2 pending]"
]
}
plugins/core/hooks.ts (experimental.session.compacting) auto-saves artifacts for long sessions (>75 tool calls, >15 min, or >5 subagent invocations). This skill provides a manual trigger for the same behavior./harvest-context session to extract session knowledge into durable context after compaction.remember skill to promote key findings into project memory.tools
Create valid, type-safe TypeScript tools for OpenCode — generates correct boilerplate, typed interfaces, and handler stubs. Use when building new tools for global config or per-project .opencode/tools/.
testing
Explore multiple solution branches in parallel, evaluate each, and recommend the best path. Use when the user explicitly invokes /ideation tree-of-thoughts or asks for "tree of thought" / "branching exploration".
testing
Run multiple independent reasoning passes and find consensus. Use when the decision is critically important, the stakes are high, or the user explicitly requests "run it multiple times" / "check consistency" / "self-consistency".
testing
Optimization by PROmpting — generate candidate prompt variations, test each against a benchmark, and report the best performer. Use when the user invokes /ideation opro or asks for "prompt optimization" / "OPRO".