Skip to content
Nilay Kabariya

Entry No.039·Agents·Updated ·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

The fix that worked

Find what's filling the context, starting with CLAUDE.md:

claude -p "hi" --debug-file debug.txt
Not it? Every cause, tested ↓

Tested on

Claude Code
2.1.138 (requests); 2.1.316 (binary checked)
Models
default (long context) and claude-haiku-4-5
OS
Windows 11 Pro

“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 wasn’t in Claude Code 2.1.138 at all. By 2.1.316 it is: Claude Code’s own error table files "Prompt is too long" / "Input is too long for requested model" under one error, prompt_too_long, so the two messages really are the same problem. 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.

November 1, 2026: I checked the Claude Code 2.1.316 binary for the strings above. The 256 KB file-read limit message is unchanged, the Large CLAUDE.md file detected warning is gone, and “Input is too long for requested model” is now listed as the same error as “Prompt is too long”. The oversized requests themselves were not re-run on 2.1.316; the results in the tables are from 2.1.138.

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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.035

    Fix: Claude Code "Invalid API key · Fix external API key"

    Invalid API key · Fix external API key, Please run /login and 401 in Claude Code: every auth message reproduced on 2.1.314, and the Windows quoting trap.

    > Invalid API key · Fix external API key

    AGENTS5 minWindows
  2. No.101

    Claude Code custom themes: five free ones, checked

    Custom themes are real, one JSON file each, and all five below load in the real /theme picker.

    AGENTS3 min
  3. No.036

    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.

    AGENTS5 minWindows

tip: paste the exact error text