Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
9452fcd
Add configurable context compaction threshold feature
ariane-emory Dec 17, 2025
43c9861
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 18, 2025
9830f8b
Merge remote-tracking branch 'origin/dev' into feat/global-compaction…
ariane-emory Dec 19, 2025
1ef31c3
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 19, 2025
206d160
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 20, 2025
f54f811
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 20, 2025
84d1747
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 21, 2025
120e344
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 21, 2025
9d06eff
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 22, 2025
bc594b8
Merge dev into feat/global-compaction-threshold
ariane-emory Dec 23, 2025
58b747a
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 23, 2025
1462e2b
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 23, 2025
70d5691
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 23, 2025
6b83cb0
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 23, 2025
75a576e
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 23, 2025
4322544
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 24, 2025
915c37a
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 24, 2025
6bc7fa6
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 24, 2025
b9ea49f
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 24, 2025
6a8574a
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 25, 2025
f9f63a4
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 25, 2025
7dc764c
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 25, 2025
fab1369
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 25, 2025
7e38e09
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 25, 2025
0231c9d
Merge branch 'feat/global-compaction-threshold' of github.com:ariane-…
ariane-emory Dec 25, 2025
18d6673
Merge branch 'feat/global-compaction-threshold' of github.com:ariane-…
ariane-emory Dec 25, 2025
f868e75
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 26, 2025
d243de6
Merge dev into feat/global-compaction-threshold
ariane-emory Dec 27, 2025
b09809f
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 27, 2025
d8ac987
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 27, 2025
d9e85e7
Fix merge conflicts: resolve duplicate Config imports and missing Fla…
ariane-emory Dec 27, 2025
701456f
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 28, 2025
55a5aae
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 28, 2025
90c97c1
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 28, 2025
9fabaca
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 28, 2025
af54054
Merge remote-tracking branch 'origin/dev' into feat/global-compaction…
ariane-emory Dec 29, 2025
8871ba6
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 29, 2025
228f848
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 29, 2025
c42fa4f
fix: use TextAttributes.UNDERLINE instead of underline prop for Link …
ariane-emory Dec 29, 2025
440c08f
revert: remove unwanted underline property fix in link.tsx
ariane-emory Dec 29, 2025
86f1d80
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 29, 2025
5802bb9
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 29, 2025
71490f2
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 29, 2025
05dae49
Merge branch 'feat/global-compaction-threshold' of github.com:ariane-…
ariane-emory Dec 29, 2025
6718e39
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 30, 2025
28437b0
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 30, 2025
2f3b6e1
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 30, 2025
3043f9c
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 30, 2025
2c76290
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 30, 2025
d10e3a7
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 30, 2025
260e4ef
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Dec 31, 2025
a056638
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 1, 2026
72b5402
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 1, 2026
e090dfb
Merge dev into feat/global-compaction-threshold
ariane-emory Jan 1, 2026
f228caa
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 2, 2026
b697726
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 3, 2026
40ccd89
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 3, 2026
fbb4b39
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 4, 2026
773e7ef
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 4, 2026
18a4846
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 4, 2026
4e8f0cf
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 5, 2026
b76642e
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 5, 2026
5789c54
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 5, 2026
823939c
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 5, 2026
6fbaeed
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 6, 2026
2bf2732
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 6, 2026
ac89577
Merge branch 'feat/global-compaction-threshold' of github.com:ariane-…
ariane-emory Jan 6, 2026
eb69b11
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 6, 2026
583fa7c
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 6, 2026
000cb63
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 6, 2026
98a97f2
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 6, 2026
8889c93
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 7, 2026
6713136
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 7, 2026
723a1d4
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 7, 2026
4ce6aec
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 7, 2026
8071856
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 8, 2026
c1f0433
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 11, 2026
6866e6c
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 13, 2026
6ecca24
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 13, 2026
0542c80
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 13, 2026
f94e754
Merge branch 'feat/global-compaction-threshold' of github.com:ariane-…
ariane-emory Jan 13, 2026
a99d04b
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 13, 2026
50aa24f
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 15, 2026
3886b9f
Merge dev into feat/global-compaction-threshold, preserving configura…
ariane-emory Jan 16, 2026
0cadcd0
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 17, 2026
607d16e
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 17, 2026
83a32d5
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 19, 2026
cb34a36
Merge branch 'dev' into feat/global-compaction-threshold
ariane-emory Jan 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ export namespace Config {
.optional()
.describe("Tools that should only be available to primary agents."),
continue_loop_on_deny: z.boolean().optional().describe("Continue the agent loop when a tool call is denied"),
context_compaction_threshold: z.number().min(10).max(100).optional().describe("Percentage of usable context space at which to trigger compaction (10-100)"),
mcp_timeout: z
.number()
.int()
Expand Down
13 changes: 11 additions & 2 deletions packages/opencode/src/session/compaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Identifier } from "../id/id"
import { Instance } from "../project/instance"
import { Provider } from "../provider/provider"
import { MessageV2 } from "./message-v2"
import { Config } from "../config/config"
import { Flag } from "../flag/flag"
import z from "zod"
import { SessionPrompt } from "./prompt"
import { Token } from "../util/token"
Expand All @@ -13,7 +15,6 @@ import { SessionProcessor } from "./processor"
import { fn } from "@/util/fn"
import { Agent } from "@/agent/agent"
import { Plugin } from "@/plugin"
import { Config } from "@/config/config"

export namespace SessionCompaction {
const log = Log.create({ service: "session.compaction" })
Expand All @@ -28,14 +29,22 @@ export namespace SessionCompaction {
}

export async function isOverflow(input: { tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
if (Flag.OPENCODE_DISABLE_AUTOCOMPACT) return false
const config = await Config.get()
if (config.compaction?.auto === false) return false
const context = input.model.limit.context
if (context === 0) return false
const count = input.tokens.input + input.tokens.cache.read + input.tokens.output
const output = Math.min(input.model.limit.output, SessionPrompt.OUTPUT_TOKEN_MAX) || SessionPrompt.OUTPUT_TOKEN_MAX
const usable = input.model.limit.input || context - output
return count > usable

// Get configurable threshold (default 100% to maintain current behavior)
const threshold = config.experimental?.context_compaction_threshold ?? 100
const thresholdMultiplier = threshold / 100
const thresholdedUsable = usable * thresholdMultiplier

log.debug("Checking overflow", { count, usable, thresholdedUsable, threshold })
return count > thresholdedUsable
}

export const PRUNE_MINIMUM = 20_000
Expand Down