feat(plugin): allow compaction hook to replace prompt entirely (#5907)

This commit is contained in:
Joel Hooks
2025-12-22 20:19:14 -08:00
committed by Aiden Cline
parent 0ccf6a8e2e
commit ce8ea03bd4
3 changed files with 42 additions and 9 deletions

View File

@@ -233,3 +233,30 @@ Include any state that should persist across compaction:
```
The `experimental.session.compacting` hook fires before the LLM generates a continuation summary. Use it to inject domain-specific context that the default compaction prompt would miss.
You can also replace the compaction prompt entirely by setting `output.prompt`:
```ts title=".opencode/plugin/custom-compaction.ts"
import type { Plugin } from "@opencode-ai/plugin"
export const CustomCompactionPlugin: Plugin = async (ctx) => {
return {
"experimental.session.compacting": async (input, output) => {
// Replace the entire compaction prompt
output.prompt = `
You are generating a continuation prompt for a multi-agent swarm session.
Summarize:
1. The current task and its status
2. Which files are being modified and by whom
3. Any blockers or dependencies between agents
4. The next steps to complete the work
Format as a structured prompt that a new agent can use to resume work.
`
},
}
}
```
When `output.prompt` is set, it completely replaces the default compaction prompt. The `output.context` array is ignored in this case.