Skip to content

Commit f5e9f65

Browse files
committed
fix(proxy): keep the claude_code preset on meta requests
Title/summary turns replaced the preset with a custom systemPrompt string, changing the request fingerprint Anthropic uses to recognize Claude Code; on V2 these meta turns reach the Claude credential because there is no small_model routing anymore. Append the utility instruction to the preset instead (anomalyco/opencode#7456).
1 parent 2fee23e commit f5e9f65

3 files changed

Lines changed: 39 additions & 23 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
### Fixes
2222

23+
- **Meta requests keep the Claude Code preset** — title/summary turns used a
24+
custom `systemPrompt` string that replaced the preset entirely; they now
25+
append to it so the request fingerprint matches normal Claude Code turns.
26+
2327
- **Rate-limit gate**: a transient 429 or unparseable limit message could
2428
reuse an unrelated window's reset (e.g. weekly) and block every turn for
2529
days. Only a recent rejection's reset is reused, otherwise the 10-minute

‎src/proxy.ts‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,32 @@ async function handleChatCompletions(
11191119
"This is a single-turn text transformation. Return only the requested summary. Do not inspect files, execute commands, or use tools.",
11201120
].filter(Boolean).join("\n\n")
11211121
: undefined;
1122+
const claudeCodeSystemPrompt: {
1123+
type: "preset";
1124+
preset: "claude_code";
1125+
append?: string;
1126+
} = { type: "preset", preset: "claude_code" };
1127+
if (isMetaRequest) {
1128+
// Meta turns keep the Claude Code preset so the request fingerprint
1129+
// matches normal turns: Anthropic rejects subscription credentials on
1130+
// requests that don't look like Claude Code (anomalyco/opencode#7456).
1131+
// OpenCode V2 generates titles with the session model, so these turn
1132+
// reach the Claude credential in v2 where v1 routed them to small_model.
1133+
claudeCodeSystemPrompt.append = utilitySystemPrompt;
1134+
} else if (bridgeOpenCodeTools) {
1135+
claudeCodeSystemPrompt.append =
1136+
[
1137+
"You are running inside OpenCode. Built-in Claude Code tools are disabled. Use only the mcp__opencode__* tools provided for this turn; they execute via OpenCode.",
1138+
"Batch independent tool calls into a single turn instead of calling them one at a time.",
1139+
...(hasTodoWrite
1140+
? [
1141+
"For any multi-step work, ALWAYS write the plan with the mcp__opencode__todowrite tool and keep it updated as you progress. A plan that only exists in your text is lost when the session is restored or handed to another agent.",
1142+
]
1143+
: []),
1144+
].join(" ") + (openCodeContext ? `\n\n${openCodeContext}` : "");
1145+
} else if (openCodeContext) {
1146+
claudeCodeSystemPrompt.append = openCodeContext;
1147+
}
11221148
handle = await queryStarter({
11231149
prompt: queryPrompt,
11241150
cwd,
@@ -1145,25 +1171,7 @@ async function handleChatCompletions(
11451171
// checks are skipped; anything else is denied without prompting.
11461172
permissionMode: bridgeOpenCodeTools ? "bypassPermissions" : "dontAsk",
11471173
allowDangerouslySkipPermissions: bridgeOpenCodeTools,
1148-
systemPrompt: utilitySystemPrompt || {
1149-
type: "preset",
1150-
preset: "claude_code",
1151-
...(bridgeOpenCodeTools
1152-
? {
1153-
append: [
1154-
"You are running inside OpenCode. Built-in Claude Code tools are disabled. Use only the mcp__opencode__* tools provided for this turn; they execute via OpenCode.",
1155-
"Batch independent tool calls into a single turn instead of calling them one at a time.",
1156-
...(hasTodoWrite
1157-
? [
1158-
"For any multi-step work, ALWAYS write the plan with the mcp__opencode__todowrite tool and keep it updated as you progress. A plan that only exists in your text is lost when the session is restored or handed to another agent.",
1159-
]
1160-
: []),
1161-
].join(" ") + (openCodeContext ? `\n\n${openCodeContext}` : ""),
1162-
}
1163-
: openCodeContext
1164-
? { append: openCodeContext }
1165-
: {}),
1166-
},
1174+
systemPrompt: claudeCodeSystemPrompt,
11671175
});
11681176

11691177
const bridge: ParkedBridge = {

‎test/smoke.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,14 @@ async function main() {
961961
// requests must not forward the selected effort.
962962
assert.equal(titleOptions!.effort, undefined);
963963
assert.equal(titleOptions!.resume, undefined);
964-
assert.equal(
965-
titleOptions!.systemPrompt,
966-
"You generate short session titles. Follow the requested output format exactly.",
967-
);
964+
// Meta requests must keep the claude_code preset (Anthropic rejects
965+
// subscription credentials on non-Claude-Code-looking requests);
966+
// the utility instruction rides along as an append.
967+
assert.deepEqual(titleOptions!.systemPrompt, {
968+
type: "preset",
969+
preset: "claude_code",
970+
append: "You generate short session titles. Follow the requested output format exactly.",
971+
});
968972
assert.match(String(titleOptions!.prompt), /<request>\nExplain how binary search trees work\n<\/request>/);
969973
} finally {
970974
setClaudeQueryStarter(null);

0 commit comments

Comments
 (0)