From 24430287c5a304ee35ad0089bad1907d7917dee2 Mon Sep 17 00:00:00 2001
From: Joel Hooks <joel@egghead.io>
Date: Wed, 17 Dec 2025 11:57:09 -0800
Subject: feat(plugin): add experimental.session.compacting hook for
 pre-compaction context injection (#5698)

Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
---
 packages/web/src/content/docs/plugins.mdx | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

(limited to 'packages/web/src/content/docs/plugins.mdx')

diff --git a/packages/web/src/content/docs/plugins.mdx b/packages/web/src/content/docs/plugins.mdx
index 58673d46d..6982b4c93 100644
--- a/packages/web/src/content/docs/plugins.mdx
+++ b/packages/web/src/content/docs/plugins.mdx
@@ -205,3 +205,31 @@ The `tool` helper creates a custom tool that opencode can call. It takes a Zod s
 - `execute`: Function that runs when the tool is called
 
 Your custom tools will be available to opencode alongside built-in tools.
+
+---
+
+### Compaction hooks
+
+Customize the context included when a session is compacted:
+
+```ts title=".opencode/plugin/compaction.ts"
+import type { Plugin } from "@opencode-ai/plugin"
+
+export const CompactionPlugin: Plugin = async (ctx) => {
+  return {
+    "experimental.session.compacting": async (input, output) => {
+      // Inject additional context into the compaction prompt
+      output.context.push(`
+## Custom Context
+
+Include any state that should persist across compaction:
+- Current task status
+- Important decisions made
+- Files being actively worked on
+`)
+    },
+  }
+}
+```
+
+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.
-- 
cgit v1.2.3

