Skip to content
Nilay Kabariya

Entry No.041·Agents··4 min read

Fix: Claude Code "Prompt is too long"

Claude Code fails every message with Prompt is too long, or asks for usage credits. One oversized file did both in my tests, and Claude Code's guard missed it.

by Nilay#claude-code#anthropicAGENTS

The error, verbatim

Jump to the fix ↓
Prompt is too long

# in the debug log:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 326082 tokens > 200000 maximum"}}

# the same oversized request on a long-context model:
Usage credits are required for long context requests.
✓ Reproduced on Windows 11 Pro

Tested on

Claude Code
2.1.138
Models
default (long context) and claude-haiku-4-5
OS
Windows 11 Pro
Contents
  1. Find the cause first01
  2. 1. A big CLAUDE.md breaks every message02
  3. 2. Asking for credits instead: “Usage credits are required for long context requests”03
  4. 3. A huge paste is usually handled for you04
  5. 4. A long conversation05
  6. “Input is too long for requested model”?06
  7. What didn’t work07
  8. How this was tested08

“Prompt is too long” means one request to the model was bigger than the model accepts. In Claude Code, that request isn’t only what you typed: it’s the system prompt, your CLAUDE.md files, the conversation so far and any tool output, all sent together. The fix is to find which of those got big.

Find the cause first

Run one request with a debug log:

claude -p "hi" --debug-file debug.txt

Search debug.txt for API error. The real API message has the numbers:

API error (attempt 1/11): 400 {"type":"error","error":{"type":"invalid_request_error",
"message":"prompt is too long: 326082 tokens > 200000 maximum"}}

If a tiny prompt like hi is already too long, the problem is in what Claude Code sends before your message, and that’s almost always CLAUDE.md.

1. A big CLAUDE.md breaks every message

Claude Code loads CLAUDE.md into every request. I put 1.3 MB of text in a project’s CLAUDE.md and asked for nothing more than reply with just: ok:

Model Result
claude-haiku-4-5 Prompt is too long (API: 326082 tokens > 200000 maximum)
the default model Usage credits are required for long context requests.

Same file, same one-line prompt, two different errors. The second appears on models that accept long context: the request is too big for the normal limit, and long-context requests need usage credits on a Claude subscription. On a model without long context, the request simply fails.

This is the trap: Claude Code guards files it reads during a task, and that guard doesn’t apply to CLAUDE.md. When I asked it about the same 1.2 MB file with @docs/reference.txt, it refused to load it whole:

File content (1.2MB) exceeds maximum allowed size (256KB). Use offset and limit parameters
to read specific portions of the file, or search for specific content instead

and read it in parts instead. As CLAUDE.md, the same content went into every request unchecked.

Keep CLAUDE.md to instructions. Move reference material (logs, specs, data dumps, long docs) into normal files, and tell Claude where they are:

# Project notes

Long reference material lives in docs/reference.txt. Read it only when a task needs it.

2. Asking for credits instead: “Usage credits are required for long context requests”

That’s the same problem on a long-context model, as the table above shows. You have two ways out:

  • Make the request smaller (section 1, or start a fresh session). Nothing else changes.
  • Allow it: add usage credits to your account, if you really need that much context. The error’s own details said can_user_purchase_credits: true on my account.

3. A huge paste is usually handled for you

Piping 1.3 MB of text into claude -p did not fail. Claude Code hit the same long-context 429 on the first attempt, then saved the input to a file and read it in parts, and answered. That cost time (78 seconds here) and usage, but no error. If a paste does fail, the same rule applies: put it in a file and point Claude at it.

4. A long conversation

The conversation counts too. Claude Code compacts it automatically as it fills up, and /compact does it on demand. When even that fails with “Prompt is too long”, the session is past saving: start a new one with /clear and carry over only what you need. I didn’t reproduce this case, because filling 200,000 tokens of real conversation would burn a lot of usage for a known answer.

“Input is too long for requested model”?

That’s the same limit, worded by a different service. The string isn’t in Claude Code 2.1.138 at all. Of the GitHub issues that quote it, most involve Amazon Bedrock, where the cloud provider’s API words the rejection its own way. I couldn’t test Bedrock, but the cause is the same, a request bigger than the model’s context, so the same checks apply.

What didn’t work

How this was tested

Claude Code 2.1.138 on Windows 11, signed in with a Claude subscription, run with claude -p and --debug-file. The oversized content was 1.3 MB of generated text (about 326,000 tokens), used once each as CLAUDE.md, as an appended system prompt, as piped input and as an @-mentioned file, on the default model and on claude-haiku-4-5. Requests over the limit are rejected before any work is done; the piped-input run did complete and used normal usage. Error text is copied from the output and debug logs.

— N.K., end of entry No.041

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.037

    Fix: Claude Code "Invalid API key" and "Please run /login"

    A bad key can freeze Claude Code for 3 minutes before it errors. Every auth message reproduced, the Windows quoting trap, and what auth status hides.

    > Invalid API key · Fix external API key

    AGENTS4 min
  2. No.038

    Fix: Claude Code "not compatible with the version of Windows"

    Windows says claude.exe won't run right after an npm install of Claude Code. Your Windows is fine. Reproduced on npm 12, with the reinstall that fixed it.

    > This version of C:\...\claude-code\bin\claude.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

    AGENTS3 min
  3. No.032

    Fix: MCP error -32000 Connection closed / Failed to connect

    An MCP server fails with Connection closed or Failed to connect and never says why. Where the real error is hiding, and the fixes, tested in Claude Code.

    > MCP error -32000: Connection closed

    AGENTS3 min

Post card · Newsletter

Get the next fix in your inbox.

One short email when a new entry is published. No spam, never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text