Skip to content

Commit 4a6d615

Browse files
committed
perf: one-line system prompt for meta turns
Titles, summaries and generate ran on the full Claude Code preset, kept to match the fingerprint Anthropic once required of subscription requests (anomalyco/opencode#7456). A one-line prompt is accepted today: checked live on Haiku 4.5 and Opus 5.5 (title and generate through the proxy), 2-6k input tokens less per meta turn. Ported from upstream 1.1.0. claudeCodePreset becomes turnSystemPrompt (it no longer always returns the preset) and metaPresetAppend becomes metaInstructions.
1 parent e9da177 commit 4a6d615

6 files changed

Lines changed: 44 additions & 33 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
name; `repository`, `homepage` and `bugs` point at
3232
`JosueGalRe/opencode-claude`, and `scripts/update-plugin.sh` checks the new
3333
name. `@openchamber/opencode-claude` on npm stays upstream's package.
34+
- **Meta turns use a one-line system prompt** — titles, summaries and
35+
generate ran on the full Claude Code preset, kept to match the fingerprint
36+
Anthropic once required of subscription requests (anomalyco/opencode#7456).
37+
A one-line prompt is accepted today (checked live on Haiku 4.5 and Opus
38+
5.5) and cuts ~2-6k input tokens per meta turn (ported from upstream
39+
1.1.0).
3440

3541
### Security
3642

@@ -83,9 +89,6 @@
8389
tool Claude does not have); custom agent prompts, `Instructions from:`
8490
blocks and the skills list are still forwarded. Unrecognized V2 layouts
8591
forward nothing rather than risk the rejection.
86-
- **Meta requests keep the Claude Code preset** — title/summary turns used a
87-
custom `systemPrompt` string that replaced the preset entirely; they now
88-
append to it so the request fingerprint matches normal Claude Code turns.
8992

9093
- **Rate-limit gate**: a transient 429 or unparseable limit message could
9194
reuse an unrelated window's reset (e.g. weekly) and block every turn for

‎src/proxy.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
} from "./model-selection.js";
4646
import { resolveClaudeModelId } from "./models.js";
4747
import { collectSteeringText, withSteering } from "./steering.js";
48-
import { claudeCodePreset } from "./system-context.js";
48+
import { turnSystemPrompt } from "./system-context.js";
4949
import {
5050
bridgedToolAliases,
5151
bridgedToolName,
@@ -1071,7 +1071,7 @@ async function handleChatCompletions(
10711071
// checks are skipped; anything else is denied without prompting.
10721072
permissionMode: bridged ? "bypassPermissions" : "dontAsk",
10731073
allowDangerouslySkipPermissions: bridged,
1074-
systemPrompt: claudeCodePreset(metaKind, messages, bridged ? toolNames : null),
1074+
systemPrompt: turnSystemPrompt(metaKind, messages, bridged ? toolNames : null),
10751075
});
10761076
turn.attach(handle);
10771077

‎src/request-kind.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ export function requestKeyNamespace(kind: MetaRequestKind): string {
108108
}
109109

110110
/**
111-
* Text appended to the Claude Code preset for a meta request. Meta turns keep
112-
* the preset so the request fingerprint matches normal turns: Anthropic
113-
* rejects subscription credentials on requests that don't look like Claude
114-
* Code (anomalyco/opencode#7456).
111+
* Task instructions of a meta request, after its one-line system prompt.
112+
* `system` is the host's system prompt when it carries the task (V1 summary
113+
* agents), else "".
115114
*/
116-
export function metaPresetAppend(
115+
export function metaInstructions(
117116
kind: Exclude<MetaRequestKind, null>,
118117
system: string,
119118
): string {

‎src/system-context.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
metaPresetAppend,
2+
metaInstructions,
33
metaSystemPrompt,
44
type MetaRequestKind,
55
} from "./request-kind.js";
@@ -121,25 +121,35 @@ export type ClaudeCodePreset = {
121121
};
122122

123123
/**
124-
* System prompt of a turn: always the Claude Code preset, with the meta
125-
* instructions, the bridged-tool rules and the forwarded OpenCode context
126-
* appended as they apply. `bridgedToolNames` is null when the turn runs
127-
* without bridged tools.
124+
* Meta turns need none of Claude Code's coding instructions. A non-preset
125+
* system prompt is accepted on subscription credentials (checked on Haiku 4.5
126+
* and Opus 5.5), and this one is 2-6k tokens smaller than the preset.
128127
*/
129-
export function claudeCodePreset(
128+
const UTILITY_SYSTEM_PROMPT =
129+
"You are a text generation helper running through the Claude Code harness. Return only the requested output.";
130+
131+
/**
132+
* System prompt of a turn. Meta turns: the one-line utility prompt with
133+
* their instructions. Other turns: the Claude Code preset, with the
134+
* bridged-tool rules and the forwarded OpenCode context appended as they
135+
* apply. `bridgedToolNames` is null when the turn runs without bridged tools.
136+
*/
137+
export function turnSystemPrompt(
130138
metaKind: MetaRequestKind,
131139
messages: MessageLike[],
132140
bridgedToolNames: string[] | null,
133-
): ClaudeCodePreset {
134-
const preset: ClaudeCodePreset = { type: "preset", preset: "claude_code" };
141+
): ClaudeCodePreset | string {
135142
if (metaKind) {
136143
// V2 sends its summary instructions in the user turn; its system prompt is
137144
// the agent's own, whose "# Your Model"/<env> sections get the request
138145
// rejected as third-party usage.
139146
const system = metaSystemPrompt(messages);
140-
preset.append = metaPresetAppend(metaKind, V2_MODEL_MARKER.test(system) ? "" : system);
141-
return preset;
147+
return [
148+
UTILITY_SYSTEM_PROMPT,
149+
metaInstructions(metaKind, V2_MODEL_MARKER.test(system) ? "" : system),
150+
].join("\n\n");
142151
}
152+
const preset: ClaudeCodePreset = { type: "preset", preset: "claude_code" };
143153
const context = systemContextForwardingEnabled()
144154
? openCodeSystemContext(messages)
145155
: "";

‎test/smoke.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -985,14 +985,13 @@ async function main() {
985985
// requests must not forward the selected effort.
986986
assert.equal(titleOptions!.effort, undefined);
987987
assert.equal(titleOptions!.resume, undefined);
988-
// Meta requests must keep the claude_code preset (Anthropic rejects
989-
// subscription credentials on non-Claude-Code-looking requests);
990-
// the utility instruction rides along as an append.
991-
assert.deepEqual(titleOptions!.systemPrompt, {
992-
type: "preset",
993-
preset: "claude_code",
994-
append: "You generate short session titles. Follow the requested output format exactly.",
995-
});
988+
// Meta turns get a one-line system prompt, not the Claude Code preset,
989+
// with the utility instruction after it.
990+
assert.equal(typeof titleOptions!.systemPrompt, "string");
991+
assert.match(
992+
String(titleOptions!.systemPrompt),
993+
/Claude Code harness[\s\S]*You generate short session titles/,
994+
);
996995
assert.match(String(titleOptions!.prompt), /<request>\nExplain how binary search trees work\n<\/request>/);
997996
} finally {
998997
setClaudeQueryStarter(null);

‎test/system-context-regression.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const INSTRUCTIONS = "Instructions from: /repo/AGENTS.md\n# Rules\n- Run tests s
2323
const SKILLS = "<available_skills>\n <skill><name>pdf</name></skill>\n</available_skills>";
2424

2525
async function main() {
26-
const { claudeCodePreset, openCodeSystemContext } = await import(
26+
const { turnSystemPrompt, openCodeSystemContext } = await import(
2727
"../src/system-context.ts"
2828
);
2929

@@ -113,22 +113,22 @@ async function main() {
113113
// V2 compaction carries its instructions in the user turn: the agent's
114114
// system prompt, third-party fingerprint included, stays out. V1 summary
115115
// agents carry theirs in the system prompt, which is kept.
116-
const v2Summary = claudeCodePreset(
116+
const v2Summary = String(turnSystemPrompt(
117117
"summary",
118118
[
119119
{ role: "system", content: `You are a pirate tester.\n${v2Env}\n${INSTRUCTIONS}` },
120120
{ role: "user", content: "Summarize the conversation above." },
121121
],
122122
null,
123-
).append ?? "";
123+
));
124124
assert.ok(!v2Summary.includes("Your Model"), "v2 compaction drops the system prompt");
125125
assert.ok(!v2Summary.includes("pirate tester"));
126126
assert.match(v2Summary, /single-turn text transformation/);
127-
const v1Summary = claudeCodePreset(
127+
const v1Summary = String(turnSystemPrompt(
128128
"summary",
129129
[{ role: "system", content: "You are a helpful AI assistant tasked with summarizing conversations." }],
130130
null,
131-
).append ?? "";
131+
));
132132
assert.match(v1Summary, /tasked with summarizing conversations/);
133133

134134
// Through the proxy: appended to the preset, and switchable off.

0 commit comments

Comments
 (0)