Claude Code Prompt Is Too Long: Causes and Fixes

Fix Claude Code's Prompt is too long error: what fills the context window, when to run /compact or /clear, auto-compact settings and model limits for 2026.

GoiAPI · · 14 min read

Ask AI and more
View as Markdown

Cover showing a terminal with the Claude Code error Context limit reached and the /compact fix, next to a context window bar split into system prompt, tools, history and files

"Prompt is too long" in Claude Code means the request Claude Code built for the model, your conversation plus its system prompt, tool definitions, memory files and attachments, no longer fits the model's context window. In an interactive session it shows up as Context limit reached · /compact or /clear to continue. The fix is usually one command: run /compact to summarize the conversation and keep going, or /clear to start fresh. If it keeps coming back, run /context to see what is filling the window and cut that.

This guide covers every variant of the message, a step-by-step fix, why auto-compact sometimes doesn't save you, the settings that matter when you run Claude Code through a custom ANTHROPIC_BASE_URL, current context window sizes by model, and what a full context costs. All facts were checked on December 5, 2026 against the Claude Code error reference and the model makers' docs.

What "Prompt is too long" means in Claude Code

Every Claude Code turn is one API request that carries everything the model needs: the system prompt, the tool definitions, your CLAUDE.md files, every earlier message and tool result, and any files or images you attached. The model's context window is the cap on that total, measured in tokens. When the request goes over it, the API rejects it with a 400 invalid_request_error and the text "prompt is too long".

Claude Code normally prevents this by compacting (summarizing) the conversation before it fills up. You see the error when compaction is off, when compaction itself fails, or when a single turn is too big to fit.

Every variant of the message

From the Claude Code error reference, checked on December 5, 2026:

You seeWhat it means
Context limit reached · /compact or /clear to continueThe conversation filled the window (interactive session)
Prompt is too longSame error in -p mode and in transcripts
... · auto-compact is off · /config to turn it onYou turned auto-compact off in /config
Prompt is too long · automatic compaction failed: <error>Compaction ran but failed on another error, such as an auth failure or an unavailable model
Prompt is too long · this conversation is a single exchange and cannot be compacted ...There is only one turn, so there is nothing earlier to summarize
Context exceeds the 200k-token limit by 94k tokens — run /compact or /clear to continue.Warning at the top of /context output
Input is too long for requested model.The Amazon Bedrock wording of the same error
Request too large (max 32MB) ...The request body is too big in bytes (usually images or PDFs), a separate limit from the context window

If you call an OpenAI-compatible API directly instead of using Claude Code, the same situation returns error code context_length_exceeded, with a message along the lines of "This model's maximum context length is N tokens", as reported in OpenAI developer forum threads. We have not reproduced that one through GoiAPI.

How to fix it, step by step

Work down the list and stop when the error is gone:

  1. See what is using the window. Run /context. It draws a grid of context usage and breaks it down into system prompt, tools, memory files and messages.
  2. Compact. Run /compact. You can steer the summary, for example /compact keep the API changes and the names of failing tests.
  3. If /compact says Not enough messages to compact., the conversation is a single oversized turn. Run /clear and resend with less pasted text or smaller attachments.
  4. Remove what rides along with every request. Disable MCP servers you aren't using with /mcp disable <name>, which drops their tool definitions from context. Trim long CLAUDE.md files, and move folder-specific instructions into rules with paths: frontmatter so they load only when relevant.
  5. Reference files by path instead of pasting them. Claude reads files in chunks. By default a single file read is capped at 25,000 tokens (CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS) and an MCP tool result at 25,000 tokens (MAX_MCP_OUTPUT_TOKENS), per the Claude Code environment variable list checked on December 5, 2026. Don't raise these if you keep hitting the limit.
  6. Turn auto-compact back on if you disabled it: use /config, or unset DISABLE_AUTO_COMPACT.
  7. Step back past the turn that broke it. Press Esc twice or run /rewind to return to the point before the huge paste.
  8. Update Claude Code with claude update. The error reference lists several stuck-session cases with this error that later versions fixed, the latest in v2.1.306, so run v2.1.306 or later.

When the message ends in automatic compaction failed: ..., read the part after the colon. Compaction is itself a model request, so a wrong API key, an empty balance or an unreachable model makes it fail. Fix that error first, then run /compact. The Claude Code API error guide covers each of those codes.

What fills the context window

Before you type anything, Claude Code already loads its system prompt, tool definitions, MCP tool names, skill descriptions, auto memory and your CLAUDE.md files. On December 3, 2026 we ran a one-line question through Claude Code with ANTHROPIC_MODEL=claude-haiku-5-5 and ANTHROPIC_BASE_URL=https://api.goiapi.com: it reported 10,679 input tokens and 15,574 cache-write tokens, so over 26,000 tokens went out before any real work.

After that, the window grows with every turn:

  • File reads. Each file Claude opens stays in the conversation.
  • Command output. Test runs, build logs and git diff output all land in context.
  • Thinking. On current Claude models, thinking blocks from earlier turns are kept and count as input in later requests, according to Anthropic's context window docs (checked on December 5, 2026).
  • Images and PDFs. These cost tokens and also count toward the separate request-size limit.

Subagents help: a subagent does its research in its own context window and only its summary comes back to yours, as the Claude Code context window page explains.

/compact vs /clear vs /rewind

CommandWhat it doesWhat you keepUse it when
/compact [instructions]Replaces the history with a summaryThe summary; CLAUDE.md and memory reload from disk; up to 5 recently read or edited files are re-readYou are mid-task and want to keep the thread
/clearStarts a new conversation with empty contextProject memory; the old conversation is reachable with /resumeYou are switching to a different task
/rewind (or Esc twice)Rolls code and conversation back to a checkpointEverything before that checkpointOne turn added far too much

Sources: Claude Code commands and the context window page, checked on December 5, 2026. After compaction, a re-read file larger than 5,000 tokens comes back only as a path reference. For habits that keep sessions small and cheap, see how to reduce Claude Code token usage.

Why auto-compact didn't prevent it

Auto-compact is on by default. According to the Claude Code model configuration docs (checked on December 5, 2026), on models with a native 1M window, which includes Claude Opus 5.5 and Claude Haiku 5.5, the default auto setting compacts near 400K tokens (in practice at about 367K) rather than waiting for 1M, because smaller later requests cost less. Run /autocompact with no value to see your session's window, or pass a size such as /autocompact 500k.

You still get "Prompt is too long" when:

  • auto-compact is off (/config, DISABLE_AUTO_COMPACT, or a project or managed setting);
  • compaction failed on another error (the automatic compaction failed: form);
  • one turn is too large on its own (the single exchange form);
  • the real limit is lower than the window Claude Code assumes, which is the gateway case below.

Using your own API key or a gateway (ANTHROPIC_BASE_URL)

When ANTHROPIC_BASE_URL points at an LLM gateway such as https://api.goiapi.com, the model configuration docs say Claude Code gives every model it recognizes the same context window it has on the Anthropic API. For claude-opus-5-5 and claude-haiku-5-5 that is 1M, with compaction near 400K as usual.

What Claude Code cannot do is detect a lower limit enforced by the gateway. If you hit "Prompt is too long" while /context shows you well below 400K, tell Claude Code to compact earlier. Run /autocompact 200k in the session, or set the variable in ~/.claude/settings.json:

JSON
{
  "env": {
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "200000"
  }
}

The value must be 100,000 or more. A bare 200 means 200 tokens here, not 200K, and Claude Code warns and falls back to the 100K minimum.

If you use a custom ANTHROPIC_BASE_URL and the message starts with Prompt is too long · automatic compaction failed, update Claude Code to v2.1.299 or later, or give Claude Code the model's real window (CLAUDE_CODE_MAX_CONTEXT_TOKENS, below). Earlier versions ended the turn near an assumed 200K window instead of sending the request (Claude Code error reference, checked on December 5, 2026).

If you run a model ID Claude Code doesn't recognize, for example a non-Claude model, it prints a warning and assumes a window. On December 3, 2026, a deliberately fake model ID produced the warning Claude Code doesn't recognize the model "<id>", so it assumes a context window of 1m tokens... (the ID is replaced with a placeholder here). If your model's real window is smaller, set CLAUDE_CODE_MAX_CONTEXT_TOKENS to that number. To run GPT, DeepSeek or GLM models from Claude Code, see the Claude Code Router guide.

Setup for the base URL and key is in the Claude Code integration guide and the Claude Code API key walkthrough. We have not run a full Claude Code session up to the context limit through GoiAPI, so the settings in this section follow the Claude Code docs and are not tested end to end.

One more limit: GoiAPI accepts request bodies up to 20 MB (limits and balance), lower than the 32 MB Claude Code checks for. A conversation full of screenshots or PDFs can be rejected for size before it reaches the context window. /compact drops accumulated images and attachments. We have not reproduced this case.

Big files, images and PDFs

From the error reference, checked on December 5, 2026:

  • Request too large is about bytes, not tokens. Run /compact to drop old attachments, or press Esc twice to step back past the turn that added them.
  • Images are accepted up to 8,000 pixels on the longest edge for a single image, or 3,000 pixels when more than 20 images are in context. Crop screenshots to the part that matters.
  • Large files should be referenced by path so Claude can read the parts it needs, instead of pasted whole into the prompt.

Context window sizes by model (December 2026)

The model makers' published limits for their own APIs, checked on December 5, 2026. The model ID is the name you use on GoiAPI.

ModelModel IDContext windowMax outputSource
Claude Opus 5.5claude-opus-5-51M128KAnthropic models overview
Claude Haiku 5.5claude-haiku-5-51M128KAnthropic models overview
DeepSeek V4 Prodeepseek-v4-pro-08131M384KDeepSeek pricing
DeepSeek V4.1 Flashdeepseek-v4.1-flash1M384KDeepSeek pricing
GPT-6 Lunagpt-6-luna1.05M128KOpenAI model page
GPT-6.1 Solgpt-6.1-sol1.05M128KOpenAI model page
GPT-6.2 Solgpt-6.2-sol1.05M128KOpenAI model page
GLM 5.3glm-5.31M128KZ.ai docs
GLM 5.3 Flashglm-5.3-flash1M128KZ.ai docs

GPT-6.2 Sol's page also caps input at 922,000 tokens within its 1.05M window. GoiAPI's model pages currently show the maximum context as "not yet available", so the limit you get through GoiAPI may differ from these figures. If your work depends on very long inputs, send one real request at that length before you scale up. The full list of models your key can call is on the models page.

The context window, explained in one minute

The context window is the model's working memory for one request: the maximum number of tokens it can take in and write out in a single call. Input and output share it, so a model with a 1M window and 128K max output cannot take 1M tokens of input and then write 128K more. Tokens read from the prompt cache still take up space; caching changes what you pay, not how much room you have.

Anthropic puts 1M tokens at roughly 555,000 English words, and 200K tokens at about 150,000 words, on its current tokenizer (models overview, checked on December 5, 2026). Bigger is not automatically better: the same Anthropic docs note that accuracy and recall degrade as the token count grows, which they call context rot. A tight context with the right files usually beats a huge one. For how tokens are counted and billed, read AI API tokens and pricing.

What a full context costs

Every turn resends the whole history as input, so turn 50 of a long session pays for the 49 before it. Here is the input cost of one request on Claude Opus 5.5 by context size, calculated from the GoiAPI pricing page on December 5, 2026 ($0.442 per 1M input tokens, $0.0221 per 1M cache-read tokens, $0.8775 per 1M cache-write tokens). These are calculations from list prices, input only, not measured requests:

Context per requestNo cache90% cache read, 10% cache write
20K tokens$0.0088$0.0022
100K tokens$0.0442$0.0108
400K tokens$0.1768$0.0431
900K tokens$0.3978$0.0969

The cache column assumes 90% of the context was cached on an earlier turn and the new 10% is written to cache, which is how Claude Code usually sends requests.

Fifty uncached requests at 400K tokens come to about $8.84 in input alone; the same fifty at 50K tokens come to about $1.11. That gap is why Claude Code compacts near 400K by default. To run the numbers for your own model and volume, use the cost calculator.

Two more cost notes:

  • On Anthropic's own API, Claude Haiku 5.5 charges higher rates for prompts over 100,000 tokens (Anthropic pricing, checked on December 5, 2026). The GoiAPI pricing page on the same date lists a single rate per model, with no split by prompt length.
  • Long contexts can trigger a 402. GoiAPI places a temporary hold based on the estimated input tokens plus max_tokens before each request, then charges only what was used. Bigger requests need a bigger hold, so a long session on a low balance is more likely to see a 402 (limits and balance).

Top-ups are in USDT (TRC20 or BEP20) or Binance Pay, with no credit card and no monthly fee. Top-ups are final and cannot be refunded, so only add what you plan to use. If you are weighing pay-per-token against a subscription, see Claude Code Max vs API: which costs less, and if your plan stops you mid-session, see Claude Code usage limit reached.

FAQ

Does auto-compact delete my work?

No. It replaces the conversation history with a summary. Your files on disk are untouched, CLAUDE.md and memory reload, and up to five recently used files are re-read. Details from early in the session can be lost in the summary, so pass instructions to /compact when something must survive.

Why do I get "Prompt is too long" on a short message in a new session?

Most of the request is not your message. The system prompt, tool definitions from MCP servers, and large CLAUDE.md files go out with every turn. Run /context, disable MCP servers you don't need, and trim memory files. Claude Code's single exchange variant of the message tells you when this is the case.

What is the context window in Claude Code?

It is the window of the model you are running: 1M tokens for Claude Opus 5.5 and Claude Haiku 5.5, per Anthropic. By default Claude Code compacts those models near 400K tokens to keep long sessions cheaper. Run /autocompact to see the value for your session.

Am I charged for a request that failed with "Prompt is too long"?

On GoiAPI, a request that fails without returning content is not charged. The /compact that follows is a real model request and is billed normally.

Does prompt caching give me a bigger context window?

No. Cached tokens still count toward the window. Caching only makes those tokens cheaper.

Next steps

Check model names and prices on the pricing page, and keep the error codes reference open for anything else Claude Code reports. To try it with your own key, create a GoiAPI account, top up a small amount in USDT, and watch the token count of every request on the Request history page.

GoiAPI sells API access to the models mentioned in this article.

Related posts