[BUG] `claude -p` with piped stdin counts the input ~1.78× toward the context limit ("attachment content"), halving the usable window for large prompts
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment: Claude Code CLI 2.1.259 and 2.1.261 (auto-updated
between observations), Ubuntu 24.04, model claude-opus-5 (1M
context), OAuth login (Max subscription). Invocation: claude -p
reading the prompt from stdin, run from a throwaway empty
directory with tools disallowed.
Observed: every over-limit refusal reports a request size ≈ 1.78 ×
the conversation size + ~16k, at three input sizes and two input
forms (plain stdin and stream-json):
1,014,989 request / 566,880 conversation
1,452,075 / 821,184 (a doubled packet)
2,057,985 / 1,153,965 (a 4.64 MB control)
2,060,987 / 1,152,395 (same input via stream-json)
The refusal text attributes the remainder to "system prompt, tool
definitions, and attachment content." Measured the fixed overhead
at ~16k tokens (a one-word prompt from an empty cwd vs a cwd
holding large files: a 5-token difference), so cwd is not the
cause and the surplus scales with the input — the piped input
appears to be composed into the request twice.
Impact: a 2.26 MB text prompt (~641k tokens by o200k, ~567k by the
CLI's own count) is refused on a 1M-token model; the effective
window for piped input is ~560k tokens. --bare avoids it but
drops OAuth, so it's not an option.
What Should Happen?
Piped input counted once, so the usable window is the
model's window minus the CLI's fixed overhead.
Error Messages/Logs
Prompt is too long · the request is ~1,014,989 tokens (limit 1,000,000) but this conversation is only ~566,880 tokens — the rest is system prompt, tool definitions, and attachment content.
Steps to Reproduce
- Make a ~2.2 MB plain-text file:
python3 -c "print('lorem ipsum ' * 200000)" > big.txt - From an EMPTY directory, tools disallowed, OAuth (subscription) login:
cat big.txt | claude -p --output-format json --model claude-opus-5
- Observe the refusal: "Prompt is too long: the request is ~N tokens
(limit 1,000,000) but this conversation is only ~M tokens — the rest
is system prompt, tool definitions, and attachment content."
N ≈ 1.78 × M + ~16k.
- Halve the file; it completes, and the reported usage shows the same
ratio. Repeat with --input-format stream-json: same ratio.
- Control: a one-word prompt from the empty directory vs from a
directory containing big.txt differs by ~5 tokens — cwd is not it.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.259 and 2.1.261
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Non-interactive/CI environment
Additional Information
Related: #12312 (same symptom, no mechanism identified there). --bare avoids the ratio but drops OAuth. Question: is stdin composed as both prompt and attachment by design? If so, a flag to pass it once under OAuth would resolve this for subscription users running automated review.