A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.
TypeScript ai-agentsclaude-codeclaude-code-plugincodexcodex-plugincontext-managementdeveloper-toolsimage-generationmcpmultimodal
fix(claude): 面板的"上一次请求"只记会话的主对话请求,不记桌面版的附带请求
chipfighter2f06c890c327
diff --git a/plugin/src/proxy.ts b/plugin/src/proxy.tsindex 4b76bb7..3bb4621 100644--- a/plugin/src/proxy.ts+++ b/plugin/src/proxy.ts@@ -180,11 +180,18 @@ export function describeBody(path: string, json: Json): Json {}};for (const message of messages) visit(message?.content);- return { kind: "messages", model: json.model ?? null, messages: messages.length, images, imageBytes, thinkingBlocks, thinking: json.thinking?.type ?? null, stream: json.stream ?? null };+ return { kind: "messages", model: json.model ?? null, messages: messages.length, images, imageBytes, thinkingBlocks, thinking: json.thinking?.type ?? null, stream: json.stream ?? null, tools: Array.isArray(json.tools) ? json.tools.length : 0 };}return { kind: "other" };}+// v0.4: the requests the panel's "last request" line is about: the session's conversation as the model works on it,+// Claude Code's main loop, which always carries its tools. Claude Desktop also sends side requests in the session (a+// status summary while the user is away, auto mode's safety check): no tools and none of the conversation's images.+// They are rewritten like the rest; only the line leaves them out (2026-10-10: it said "nothing replaced" after a turn+// whose four images had all been left out).+export const claudeConversationRequest = (details: Json): boolean => details.kind === "messages" && details.tools > 0;+function log(entry: Json): void {const dir = proxyLogDirOf();mkdirSync(dir, { recursive: true });@@ -596,7 +603,7 @@ async function main(): Promise<void> {log(entry);// Image keys go to the per-thread statistics only, not to the log.if (/\/responses$/.test(path)) recordRequest(identity.threadId, imageSizes ? { ...entry, imageSizes } : entry);- if (claudeSession) recordRequest(claudeSession, imageSizes ? { ...entry, imageSizes } : entry, claudeRequestStatsDirOf());+ if (claudeSession && claudeConversationRequest(details)) recordRequest(claudeSession, imageSizes ? { ...entry, imageSizes } : entry, claudeRequestStatsDirOf());};// body === null streams the request through unchanged. v0.4: with `fallback` (the original body of a rewritten// Claude Code request), Anthropic refusing the rewritten history under its thinking (thinkingRejected) sends thediff --git a/spike/src/proxy.test.ts b/spike/src/proxy.test.tsindex e6945b7..99c6830 100644--- a/spike/src/proxy.test.ts+++ b/spike/src/proxy.test.ts@@ -182,13 +182,26 @@ test("Messages metadata counts images in user messages and tool results, and thi],};const described = describeBody("/v1/messages", body);- assert.deepEqual(described, { kind: "messages", model: "claude-haiku-5-5", messages: 3, images: 2, imageBytes: data.length * 2, thinkingBlocks: 1, thinking: "adaptive", stream: true });+ assert.deepEqual(described, { kind: "messages", model: "claude-haiku-5-5", messages: 3, images: 2, imageBytes: data.length * 2, thinkingBlocks: 1, thinking: "adaptive", stream: true, tools: 0 });assert.ok(!JSON.stringify(described).includes("secret"));const redacted = JSON.stringify(redactImages({ ...body, messages: [{ role: "user", content: [{ type: "image", source: { type: "base64", data: "A".repeat(400) } }] }] }));assert.ok(!redacted.includes("A".repeat(300)));assert.match(redacted, /<sha256:[0-9a-f]{16} chars:400>/);});+test("the panel's last request is the session's conversation, not Claude Desktop's side requests in it", async () => {+ const { claudeConversationRequest } = await import("../../plugin/src/proxy.ts");+ const tool = { name: "Read", description: "", input_schema: { type: "object" } };+ // Claude Code's main loop: the conversation, with its tools.+ const main = describeBody("/v1/messages", { model: "claude-sonnet-5-5", stream: true, tools: [tool, tool], messages: [{ role: "user", content: "hi" }] });+ assert.equal(main.tools, 2);+ assert.equal(claudeConversationRequest(main), true);+ // The desktop's status summary while the user is away, or auto mode's safety check: no tools, no images.+ const summary = describeBody("/v1/messages", { model: "claude-sonnet-5-5", max_tokens: 3072, messages: [{ role: "user", content: "Current state: done" }] });+ assert.equal(claudeConversationRequest(summary), false);+ assert.equal(claudeConversationRequest(describeBody("/backend-api/codex/responses", { input: [] })), false);+});+test("a Claude Code request is rewritten from the session's transcript and selection; nothing to do keeps the bytes", async () => {const { usualSession, usualRequest } = await import("./claude-fixtures.ts");const { claudeNeedsRewrite, rewriteClaudeBody, claudeImageSizes } = await import("../../plugin/src/proxy.ts");