feat(read_file): opt-in DC_NO_IMAGE_STRUCTURED_BASE64 to omit duplicate image base64 from structuredContent#522
Conversation
…te image base64 from structuredContent The image base64 is currently emitted twice in read_file's image response: - in content[1] as the MCP image block (so the host model can see the image) - in structuredContent.content / .imageData (for the preview widget) For MCP clients that serialize structuredContent into the model's text input alongside the rendered image block, this duplicate becomes large per-call context bloat. This adds an opt-in env var (DC_NO_IMAGE_STRUCTURED_BASE64=true) that omits content/imageData from structuredContent's image branch. The content[image] block and all other structuredContent metadata stay intact; default behavior is unchanged. Refs wonderwhy-er#521
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangesImage base64 structuredContent toggle
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Refs #521 (server-side opt-in path).
When
read_filereturns an image, the image bytes are currently emitted twice:content[1]as the MCP image block (so the host model can see the image natively)structuredContent.contentandstructuredContent.imageData(intended for the preview widget)MCP clients that serialize
structuredContentinto the model's text input alongside the rendered image block end up paying for ~100 KB of duplicate base64 per image read (see #521 for a measured ~2.7× context bloat with Claude Code CLI). The image block already conveys the image; the structuredContent-side base64 is duplicate.This PR adds an opt-in env var
DC_NO_IMAGE_STRUCTURED_BASE64=truethat omits thecontent/imageDatafields fromstructuredContentinhandleReadFile's image branch. The MCPcontent[image]block and all otherstructuredContentmetadata (fileName,filePath,fileType,sourceTool,mimeType) stay intact, so:#521 lists four possible directions; this PR takes the smallest one (a config-flag opt-in). The other directions (
resource_link,audienceannotations,currentClient-based adaptation) remain viable — if the review prefers one of them, the PR can be reshaped accordingly.Changes
src/handlers/filesystem-handlers.ts: read the env var in the image branch ofhandleReadFile, conditionally spreadcontent/imageDataintostructuredContenttest/test-image-structured-content-toggle.js(new): three subtests — default keeps base64,=trueomits it (while keepingcontent[image]and metadata), only the literal string"true"enables the opt-inTest plan
npm run buildcleannode test/test-image-structured-content-toggle.js— all three subtests passnode test/test-file-handlers.js— existing image read test (Test 9) still passes (no regression)Related
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
Summary by CodeRabbit
New Features
Tests