[BUG] custom base URLs skip attachment pruning and hit 32MB
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
image and attachment pruning works when Claude Code talks directly to the Claude API, but it does not seem to run when ANTHROPIC_BASE_URL points to an Anthropic-compatible gateway
this makes long 1M-context sessions fail much earlier than their token window suggests
my session was still useful and nowhere near needing a 100k-style compact, but accumulated images pushed the serialized request past the raw 32MB limit and Claude Code stopped every turn with:
Request too large (max 32MB). Accumulated images and attachments in the conversation pushed the request over the limit. Run /compact, or double press esc to go back and remove attachments.
same workflow using Claude Code directly with Opus keeps working because older images and attachments are dropped before the request exceeds the limit
this also matches the current docs, which specifically say that pruning happens "when Claude Code sends requests directly to the Claude API"
lowering token-based auto-compaction is not a good workaround for 1M sessions because images are byte-heavy but token-light, so it throws away useful text context to solve a separate HTTP body-size limit
What Should Happen?
apply the same oldest-image and attachment pruning for compatible custom base URLs before serializing the request
ideally pruning should depend on estimated request body size, not whether the destination hostname is the first-party API
this would preserve the useful text portion of a 1M context while keeping the request below the 32MB transport limit
Error Messages/Logs
Request too large (max 32MB). Accumulated images and attachments in the conversation pushed the request over the limit. Run /compact, or double press esc to go back and remove attachments.
Steps to Reproduce
- set
ANTHROPIC_BASE_URLto an Anthropic-compatible gateway - use a model/profile with a 1M context window
- keep a long session and read or attach enough screenshots for their accumulated base64 payload to exceed 32MB
- send another text-only prompt
- Claude Code rejects it locally with the error above
- run the equivalent workflow directly against the Claude API and older attachments are pruned instead
Claude Model
1M-context model through an Anthropic-compatible custom base URL
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.221 (Claude Code)
Platform
Other
Operating System
Other Linux
Terminal/Shell
Xterm
Additional Information
this is related to the general oversized-session reports in #8092 and the custom-base-url diagnostics in #82931, but neither reports this specific behavior difference: direct API requests prune old attachments while custom base URL requests keep carrying them until the 32MB limit
an early token compact is not equivalent here because it defeats a main reason for using a 1M context window
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗