Skip to content

Commit 4812d9b

Browse files
anandgupta42claude
andcommitted
fix: reduce context bloat and surface observation masks after pruning
Three generic context efficiency improvements: 1. Surface `observation_mask` for pruned tool outputs in `toModelMessages` instead of opaque "[Old tool result content cleared]". The mask was already computed by `SessionCompaction.prune()` but never used — gives the model post-compaction awareness of what it previously read. 2. Remove dead `<directories>` block from `SystemPrompt.environment()`. The tree was permanently disabled via `&& false`, leaving an empty XML tag wasting ~30 tokens per API call. 3. Compact skill descriptions in tool schema from 4-line XML per skill to single-line `<skill name="...">description</skill>`. Drops unused `<location>` URLs. Cuts skill listing size by ~60%. Includes 8 e2e tests validating all three changes without mocking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 053e635 commit 4812d9b

5 files changed

Lines changed: 545 additions & 23 deletions

File tree

packages/opencode/src/session/message-v2.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,9 @@ export namespace MessageV2 {
634634
if (part.type === "tool") {
635635
toolNames.add(part.tool)
636636
if (part.state.status === "completed") {
637-
const outputText = part.state.time.compacted ? "[Old tool result content cleared]" : part.state.output
637+
const outputText = part.state.time.compacted
638+
? (part.state.metadata?.observation_mask ?? "[Old tool result content cleared]")
639+
: part.state.output
638640
const attachments = part.state.time.compacted || options?.stripMedia ? [] : (part.state.attachments ?? [])
639641

640642
// For providers that don't support media in tool results, extract media files

packages/opencode/src/session/system.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Ripgrep } from "../file/ripgrep"
2-
31
import { Instance } from "../project/instance"
42

53
import PROMPT_ANTHROPIC from "./prompt/anthropic.txt"
@@ -38,16 +36,6 @@ export namespace SystemPrompt {
3836
` Platform: ${process.platform}`,
3937
` Today's date: ${new Date().toDateString()}`,
4038
`</env>`,
41-
`<directories>`,
42-
` ${
43-
project.vcs === "git" && false
44-
? await Ripgrep.tree({
45-
cwd: Instance.directory,
46-
limit: 50,
47-
})
48-
: ""
49-
}`,
50-
`</directories>`,
5139
].join("\n"),
5240
]
5341
}

packages/opencode/src/tool/skill.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
3535
"Invoke this tool to load a skill when a task matches one of the available skills listed below:",
3636
"",
3737
"<available_skills>",
38-
...accessibleSkills.flatMap((skill) => [
39-
` <skill>`,
40-
` <name>${skill.name}</name>`,
41-
` <description>${skill.description}</description>`,
42-
` <location>${pathToFileURL(skill.location).href}</location>`,
43-
` </skill>`,
44-
]),
38+
...accessibleSkills.map(
39+
(skill) => ` <skill name="${skill.name}">${skill.description}</skill>`,
40+
),
4541
"</available_skills>",
4642
].join("\n")
4743

0 commit comments

Comments
 (0)