Skip to content

Stop paying the multimodal tax. Your AI agent keeps every image it has seen but only sends the ones it needs: lighter chats, no endless reconnecting, no starting over. Works with Codex, Claude Code, Cline, Gemini CLI, OpenCode, WorkBuddy and more. Install once, forget it.

fix(claude): 最后改发原始请求时,也去掉改写期间产生、已对不上的思考记录

chipfighter393d92232adf
diff --git a/plugin/src/proxy.ts b/plugin/src/proxy.ts
index aa51206..b7aa157 100644
--- a/plugin/src/proxy.ts
+++ b/plugin/src/proxy.ts
@@ -379,9 +379,14 @@ export function rewriteClaudeBody(original: Buffer, encoding: string | undefined
return { body, report: { ...summary, ...extra, ...(asked ? { experiment: { blockBinding: experiment, beta: "thinking-binding-controls-2026-08-01" } } : {}), decodedBefore: decoded.length, decodedAfter: next.length, encodedBefore: original.length, encodedAfter: body.length } };
};
const attempts: ClaudeAttempt[] = [];
- if (!thinking?.strict) attempts.push({ ...encode(rewritten, {}), history: fit?.history ?? null, sent: fit ? (fit.left ? chainOf(rewritten) : fit.sent) : null });
- if (fit && (thinking?.strict || fit.left)) attempts.push({ ...encode(fit.messages, { thinking: { kept: fit.kept, left: fit.left }, ...(thinking?.strict ? {} : { retry: "thinking-signature" }) }), history: fit.history, sent: fit.sent });
- attempts.push({ body: original, report: { ...summary, fallback: "thinking-signature" }, history: fit?.history ?? null, sent: fit?.history ?? null });
+ const add = (list: Json[], extra: Json, history: string | null, sent: string | null) => attempts.push({ ...encode(list, extra), history, sent });
+ if (changed && !thinking?.strict) add(rewritten, {}, fit?.history ?? null, fit ? chainOf(rewritten) : null);
+ if (changed && fit && (thinking?.strict || fit.left)) add(fit.messages, { thinking: { kept: fit.kept, left: fit.left }, ...(thinking?.strict ? {} : { retry: "thinking-signature" }) }, fit.history, fit.sent);
+ // Then the original as Claude Code built it, without the thinking made while the engine had changed the history
+ // before it: on an account that checks thinking, that no longer fits the original either.
+ const back = !thinking ? null : changed ? fitThinking(json.messages, json.messages, thinking.sent) : fit;
+ if (back?.left) add(back.messages, { thinking: { kept: back.kept, left: back.left }, ...(changed ? { fallback: "thinking-signature" } : {}) }, back.history, back.sent);
+ attempts.push({ body: original, report: { ...summary, fallback: "thinking-signature" }, history: back?.history ?? null, sent: back?.history ?? null });
return { body: attempts[0].body, report: attempts[0].report, attempts };
}
diff --git a/spike/src/proxy.test.ts b/spike/src/proxy.test.ts
index 20945c4..f5f7a7a 100644
--- a/spike/src/proxy.test.ts
+++ b/spike/src/proxy.test.ts
@@ -273,6 +273,19 @@ test("an account that refuses thinking after an edited history gets the rewrite
const sent = JSON.parse(again.attempts[0].body.toString("utf8")).messages;
assert.deepEqual(sent[1].content.map((block: any) => block.type), ["thinking", "text"]);
assert.deepEqual(sent[9].content.map((block: any) => block.type), ["text"]);
+ // Another image unchecked: should that rewrite be refused, the original goes without the thinking made while the
+ // engine had changed the history (it no longer fits the original), and only then as Claude Code built it.
+ writeSelection({ threadId: session, unchecked: { [`${p1}#0`]: { id: "IMG-001", at: "2026-10-10T00:00:00Z" } } }, dir);
+ const other = rewriteClaudeBody(Buffer.from(JSON.stringify({ model: "claude-haiku-5-5", thinking: { type: "adaptive" }, messages: next })), undefined, session, dir, home, {}, record);
+ assert.deepEqual(other.attempts.map((attempt: any) => [attempt.report.fallback ?? null, attempt.report.thinking ?? null]), [
+ [null, { kept: 0, left: 2 }],
+ ["thinking-signature", { kept: 1, left: 1 }],
+ ["thinking-signature", null],
+ ]);
+ const back = JSON.parse(other.attempts[1].body.toString("utf8")).messages;
+ assert.equal(back.length, next.length);
+ assert.deepEqual(back[1].content.map((block: any) => block.type), ["thinking", "text"]);
+ assert.deepEqual(back[8].content.map((block: any) => block.type), ["text"]);
});
test("Anthropic refusing the thinking after an edited history is told apart from other 400s", async () => {