Skip to main content
Claudebeginner

Fix "Prompt is too long" in Claude Code — Context Window & Token Limit Errors

Resolve the `Prompt is too long` error in Claude Code. Clear the context with /compact, trim MCP tool definitions, and stop oversized file reads from filling the window.

8 min readUpdated August 2026

You send a message to Claude Code and the request fails immediately with:

Prompt is too long

Depending on the model and the request, the same condition can surface as Input is too long for requested model, or as an HTTP 413 response naming the model's context window. Claude Code treats all three as the same case internally, and the fix is the same for all of them.

This is a size error. It is not a rate limit, not a billing failure, and not an outage. The request Claude Code assembled was larger than the model's context window, so the API rejected it whole rather than silently truncating your instructions.

Why This Happens

Every message you send carries far more than what you typed. A single Claude Code request contains:

  • The system prompt and tool definitions for built-in tools
  • Every connected MCP server's tool list — name, description and full JSON schema for each tool
  • Your CLAUDE.md files (project and user scope)
  • The entire conversation so far, including previous responses
  • The full text of every file that has been read and every command's output
  • Your new message

The context window is the ceiling on that total. Four things push you into it:

  1. A long session. Context accumulates monotonically. Fifty exchanges of reading files and running builds will fill any window.
  2. One oversized read. A minified bundle, package-lock.json, a log file or a CSV export can exceed the window by itself.
  3. Chatty tool output. A test suite that prints thousands of lines, or an MCP tool returning a large API payload, lands in context in full.
  4. Fixed overhead. MCP tool schemas and CLAUDE.md are prepended to every request. If they are large enough, you can hit the ceiling on the first message of a brand-new session.

That last case is the one that confuses people most: the error appears before you have done anything.

Fix 1: Compact the Conversation

If the error appeared partway through a working session, this is almost always the answer:

/compact

Claude Code replaces the detailed history with a summary and frees most of the window. You keep working in the same directory, with the same task context, and Claude can re-read any file it needs.

To discard history entirely and start clean:

/clear

Use /compact when you want to continue the current task, and /clear when you are moving to a new one. Files already written to disk are untouched by either — only the in-memory conversation changes.

Fix 2: Check Where the Context Is Going

Before guessing, look:

/context

This renders current context usage as a colored grid, broken down by what is consuming it. It is the fastest way to tell whether your problem is conversation history (fix with /compact), MCP tool definitions (fix by disconnecting servers), or a single enormous file read.

If /compact does not meaningfully reduce usage, your problem is fixed overhead, and the next two fixes are the relevant ones.

Fix 3: Trim MCP Servers

Every connected MCP server contributes its full tool schema to every request, whether or not you use it. A project with six servers connected can carry tens of thousands of tokens of overhead before you type a word.

List what is connected:

/mcp

Then remove servers this project does not need:

# See configured servers and their scope
claude mcp list

# Remove one
claude mcp remove <server-name>

Scope matters here. A server added at user scope loads in every project you open; one added at project or local scope loads only where it is relevant. Moving rarely-used servers out of user scope is usually the single biggest win. See how to set up MCP servers for how the three scopes work.

You can also cap what MCP tools are allowed to return:

export MAX_MCP_OUTPUT_TOKENS=10000

This prevents one verbose API response from consuming the window.

Advertisement

Fix 4: Shrink CLAUDE.md

CLAUDE.md is prepended to every request, so length there is paid repeatedly. A file that has grown to several thousand words of history and edge cases is a permanent tax on every message.

Check the sizes:

wc -w CLAUDE.md ~/.claude/CLAUDE.md

Keep the file to the instructions that genuinely change Claude's behaviour, and move detailed reference material into linked documents that get read only when needed. The CLAUDE.md configuration guide covers the pattern.

Fix 5: Stop the Oversized Read

If the error fires the moment a specific file is touched, that file is the cause. Rather than reading it whole:

  • Ask for a line range: "read lines 400-500 of src/bundle.js"
  • Search instead of reading: grep -n "handleAuth" src/**/*.ts
  • Exclude generated and vendored paths from the project so they are never candidates

Lock files, dist/ and build/ output, minified assets, node_modules, database dumps and log files are the usual offenders. Excluding them helps on every subsequent session too. For strategies on keeping big repositories workable, see working with large codebases.

Fix 6: Switch to a Larger Window

Different models have different context windows:

/model

A larger-window model will accept a request that a smaller one rejects, which is useful when you genuinely need a lot of material in context at once. Treat it as a workaround: it costs more per request, and if a single tool result overflows one window it will often overflow the next one as well. Switching models covers the trade-offs.

Verify the Fix

After applying any of the above, confirm you have room:

/context

Then send a small message. If it goes through, the window is no longer the constraint. If the error persists on a fresh session with no history at all, the overhead is still too large — go back to /mcp and CLAUDE.md, since those are the only things loaded before you type.

Prevention

  • Keep sessions task-scoped. Start a new session when you switch tasks instead of running one all day. This is the single most effective habit.
  • Compact proactively. Running /compact at a natural break point is cheaper than hitting the wall mid-operation.
  • Connect MCP servers per project. Reserve user scope for servers you genuinely want everywhere.
  • Keep CLAUDE.md lean. Instructions, not documentation.
  • Exclude generated files. Lock files, build output and logs should never be read in full.
  • Cap noisy output with MAX_MCP_OUTPUT_TOKENS, and pipe verbose commands through head or tail when you only need the tail of a build log.

Frequently Asked Questions

Find answers to common questions

It means the request Claude Code assembled — system prompt, CLAUDE.md files, MCP tool definitions, conversation history and any file contents — exceeds the model's context window. The API rejects the whole request rather than truncating it, so nothing is sent. It is a size error, not a rate limit or a billing problem.

Run /compact to summarize the conversation and free most of the window, or /clear to start a fresh session with no history. /compact keeps a summary of what you were doing; /clear discards everything. If the error appears on the very first message of a session, /compact will not help — the fixed overhead is too large and you need to trim MCP servers or CLAUDE.md.

Because the fixed overhead is already too big before you type anything. Connected MCP servers inject every tool's name, description and JSON schema into each request, and CLAUDE.md files are prepended too. A handful of large MCP servers can consume tens of thousands of tokens. Run /context to see the breakdown, then disconnect servers you are not using.

It replaces the detailed conversation history with a summary, so specific quoted output and exact file contents are gone from context. Claude keeps working in the same directory and can re-read any file it needs. Files already written to disk are unaffected — only the in-memory conversation is condensed.

Sometimes. Switching models with /model changes the window, and a larger-window model will accept a request a smaller one rejects. It is a workaround rather than a fix: if a single tool result is large enough to overflow one window it will usually overflow the next one too, and larger windows cost more per request.

A single large file — a minified bundle, a lock file, a log, a CSV export, a generated schema — can be bigger than the entire context window on its own. Reading it in one operation overflows the request. Ask Claude to read a specific line range, grep for the relevant section, or exclude the file from the project entirely.

They are the same underlying condition reported slightly differently. Claude Code maps both — along with a 413 response naming the model's context window — to the same prompt_too_long case. The fix is identical in all three cases: reduce what is being sent.

Keep sessions task-scoped and start a new one when you change tasks, keep CLAUDE.md short, connect only the MCP servers a project actually needs, and cap noisy tool output with the MAX_MCP_OUTPUT_TOKENS environment variable. Checking /context occasionally tells you where the space is going before you hit the wall.