Error Fix · As of 2026-11-25

Claude Code "Prompt is too long": What Fills the Context, How to Use /context and /compact, and When 1M Models Help

In Claude Code, Prompt is too long means the full request for this turn (system prompt, tool definitions, CLAUDE.md, the whole conversation, file contents and images) is larger than the model's context window. The fastest order of operations: run /context to see which category fills the window, then /compact the history or /clear for a fresh session; if MCP tools, giant files or pasted logs are the cause, trim them at the source. As of 2026-11-25, Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.2 already run with a 1M window in Claude Code by default; only Opus 4.6 and Sonnet 4.6 need a [1m] variant.

QCode is an independent third-party API service. It is not affiliated with or endorsed by Anthropic. Error text, commands and environment variables below are quoted from code.claude.com and platform.claude.com (read 2026-11-25).

Updated 2026-11-26

Key facts

  • It is about tokens, not bytes. A byte overflow is a different error (413 Request too large). At the API level, "prompt is too long" is a 400 invalid_request_error.
  • The Claude Code messages, verbatim: Prompt is too long, Input is too long for requested model, Prompt is too long · automatic compaction failed:, Prompt is too long · this conversation is a single exchange, Context limit reached · /compact or /clear to continue, Context limit reached · /clear to continue.
  • Measure before you cut: /context shows usage by category with optimization suggestions; /context all shows the full breakdown.
  • 1M is the default for the Fable models, Sonnet 5 and later, Haiku 5.5, and Opus 4.7 and later, with auto-compaction at about 967K tokens. Opus 4.6 and Sonnet 4.6 stay at 200K unless you pick [1m].
  • Gateways: behind ANTHROPIC_BASE_URL, Claude Code can't detect a lower limit enforced by the gateway. Use CLAUDE_CODE_AUTO_COMPACT_WINDOW to compact earlier if you need to.
  • MCP output: Claude Code warns when one MCP tool result passes 10,000 tokens and caps it at 25,000 by default (MAX_MCP_OUTPUT_TOKENS).

Which variant are you seeing?

Message Meaning First move
Prompt is too long / Input is too long for requested model This request's tokens exceed the model's window /context, then /compact
Context limit reached · /compact or /clear to continue The session is full and auto-compaction didn't run or is off /compact; if that fails, /clear
Context limit reached · /clear to continue Compaction is no longer possible /clear, or /rewind to an earlier point
Prompt is too long · automatic compaction failed: Auto-compaction itself failed Read the reason after the colon; usually /rewind or /clear
Prompt is too long · this conversation is a single exchange / A single-exchange conversation cannot be compacted One turn, but that turn alone is too big (for example a pasted log) Shrink or split that input, or put it in a file
Context exceeds the ...-token limit by ... tokens (in /context) How far over the limit you are Find the category and trim it

If you see a 400 "prompt is too long" in the SDK or another client, our context length exceeded guide covers the general case. This page is specific to Claude Code.

What actually fills the context

Claude Code sends all of this again on every request; the model doesn't remember the previous turn:

  1. Startup content: the system prompt, CLAUDE.md, auto memory (the first 200 lines or 25KB of MEMORY.md), MCP tool names, one-line skill descriptions, output styles. It is in the window before you type anything.
  2. Conversation history: every prompt, reply and tool result. In long sessions this is usually the biggest share.
  3. File reads: once Claude reads a file, its content sits in history and is resent on every later turn. Build output, lock files, big JSON and logs are the usual culprits.
  4. MCP tools: by default, full MCP schemas are deferred; only tool names are listed and schemas load on demand through tool search. With ENABLE_TOOL_SEARCH=false, every schema loads up front. Large tool results go straight into context too.
  5. Images and PDFs: screenshots and PDF pages count as visual tokens. One request can carry up to 600 images or PDF pages (100 on 200K-window models).
  6. One huge input: pasting tens of thousands of log lines in one message produces the "single exchange" case that compaction can't fix.

Step 1: measure with /context

/context
/context all

/context breaks usage down by category (system prompt, tools, memory files, messages and so on) and suggests optimizations; all gives the full list. Pair it with /memory to see which CLAUDE.md and auto-memory files loaded at startup. Measuring first usually shows the real culprit: one MCP server, one file that should never have been read, or an old discussion that no longer matters.

Step 2: compact or clear

  • /compact replaces the conversation with a structured summary that keeps your requests, key concepts, modified files and important snippets, errors and fixes, and pending tasks. Give it a focus, for example /compact focus on the auth bug fix, so the summary keeps what you chose rather than what the automatic pass guesses.
  • /clear when you switch to unrelated work. Old conversation crowds out the files the next task needs and costs tokens on every message. /resume brings an earlier session back.
  • /rewind to step back before the turn that pulled in a giant file.
  • Subagents for wide reading or searching: the file content stays in the subagent's own context, and only a summary returns.

After compaction Claude Code reloads the system prompt and output style, the project-root CLAUDE.md and unscoped rules, auto memory, up to five recently modified files, and the bodies of skills you invoked (capped at 5,000 tokens per skill and 25,000 in total). Rules with paths: and nested CLAUDE.md files return only when a matching file is read again; the skill listing does not reload.

For compaction that happens after a long idle period, see Claude Code idle compaction.

Step 3: trim at the source

MCP servers: open /mcp and toggle off servers this project doesn't need. Disabling keeps the config; the state is stored in ~/.claude.json under disabledMcpServers. Leave tool search on rather than setting ENABLE_TOOL_SEARCH=false. If a tool returns huge payloads, add paging or filters instead of raising MAX_MCP_OUTPUT_TOKENS again and again. For tool search behind a gateway, see Claude Code 2.1.304 tool search and gateways.

Big files and folders: deny reads of build output and dependencies in .claude/settings.json so Claude doesn't open them by accident:

{
  "permissions": {
    "deny": [
      "Read(./dist/**)",
      "Read(./node_modules/**)",
      "Read(./coverage/**)",
      "Read(./logs/**)"
    ]
  }
}

CLAUDE.md: Anthropic recommends keeping it under 200 lines and moving reference material into skills or path-scoped rules that load only when needed.

Images: crop to the region you need instead of pasting a dozen full-resolution screenshots. Once they are no longer needed, /compact or /rewind takes them out of history.

Logs: filter with tail -n 200 or grep first, or let Claude read the file with its tools as needed.

Step 4: use 1M context and the auto-compact window correctly

Per Claude Code's model configuration docs (read 2026-11-25):

  • 1M by default, no suffix: Fable 5.1 and 5, Sonnet 5 and later, Haiku 5.5, Opus 4.7 and later. So claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5 and claude-fable-5-2 are already 1M and compact at about 967K tokens.
  • Needs a [1m] variant: Opus 4.6 and Sonnet 4.6, which otherwise run at 200K. Examples: /model claude-sonnet-4-6[1m] or /model opus[1m] (the suffix has no effect when opus already resolves to Opus 4.7 or later).
  • Switching models: /model claude-sonnet-5-5 inside a session, or claude --model claude-opus-5-5 at launch.

QCode's /models page (read 2026-11-22) lists every Claude model with a 1M window, plus a few [1m] entries such as claude-sonnet-5-5[1m] at the same price as the base model. For the 5.5 models, the base ID is enough; check QCode's docs for what the [1m] entries change. More detail: 1M context with a custom base URL.

If your gateway has a lower limit: Claude Code gives each model it recognizes the same window it has on the Anthropic API and can't detect a lower limit enforced by the gateway or the server behind it. If requests above a certain size get rejected, set the auto-compact window in the environment that starts Claude Code:

export ANTHROPIC_BASE_URL=https://api.qcode.cc/api
export ANTHROPIC_AUTH_TOKEN=cr_your_key
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000   # compact at 200K on every model
claude --model claude-sonnet-5-5

CLAUDE_CODE_AUTO_COMPACT_WINDOW accepts 100,000 to 1,000,000 and takes precedence over the /autocompact command, the --autocompact flag and the autoCompactWindow setting. The docs say k and M suffixes work from v2.1.304, but a bare number is read as tokens, so 200 means 200 tokens. Inside a session, /autocompact 500k sets the window for the current model.

Watch CLAUDE_CODE_DISABLE_1M_CONTEXT=1. It makes even native-1M models behave as 200K. With auto-compaction off as well, sessions stop at the 200K boundary with the context-limit error instead of compacting. That explains many "I'm on a 1M model but still get Prompt is too long" reports.

Prevention checklist

  1. /clear before each new task, or close the previous one with /compact <focus>.
  2. Run /context now and then; watch the tools and messages categories.
  3. Enable only the MCP servers this project needs, and keep tool search on.
  4. Deny reads of build output, dependency folders and logs with permissions.deny.
  5. Keep CLAUDE.md under 200 lines, with no timestamps or other per-session values (this also helps prompt-cache hits).
  6. Hand wide reading to subagents.
  7. Set CLAUDE_CODE_AUTO_COMPACT_WINDOW if your gateway has a lower ceiling.

What it means for cost

The longer the context, the more each turn costs, because Claude Code resends all of it. A stable prefix (system prompt, CLAUDE.md, tool definitions) can hit the prompt cache: Sonnet 5.5 cache reads are $0.10 per million tokens, 5% of its $2 input price. On Claude 4.6 and later, 1M context is billed at standard rates. The exception is Haiku 5.5: when one prompt exceeds 100K tokens, the whole request is billed at $0.50 / $2.50 instead of $0.10 / $0.50. QCode bills official price × 1.0; live rates are on /models.

FAQ

What is the difference between "Prompt is too long" and 413 "Request too large"?

"Prompt is too long" means tokens exceed the context window, usually from long sessions and many file reads. A 413 means the request body is too many bytes, usually from large images or PDFs. You fix the first by compacting history and the second by shrinking attachments.

What does /compact throw away?

Full tool outputs and intermediate reasoning are replaced by a summary that keeps your requests, key snippets, errors and fixes, and pending tasks. The system prompt, root CLAUDE.md and auto memory reload automatically, and up to five recently modified files are read again.

Why did /compact fail too?

If the conversation is a single turn and that turn is itself too large, you get A single-exchange conversation cannot be compacted. Shrink or split that input, or start over with /clear.

I'm on Opus 5.5. Why do I still hit the limit?

Opus 5.5 runs with 1M by default and Claude Code compacts at about 967K tokens. You can still hit the limit if CLAUDE_CODE_DISABLE_1M_CONTEXT=1 is set, your gateway has a lower ceiling, or one turn pulls in something enormous. /context shows the real window and usage.

How much context do MCP servers use?

With tool search on (the default), only tool names load at startup, which is small; full schemas load on demand. With tool search off, every schema loads up front, which adds up with many tools. Large tool results also count toward context.

How do I pick a 1M-context model in Claude Code?

The 5.5 models and Fable 5.2 are 1M with their base IDs, for example /model claude-sonnet-5-5. Opus 4.6 and Sonnet 4.6 need the [1m] suffix, such as /model claude-sonnet-4-6[1m]. Behind a third-party gateway, first check that the gateway supports that variant.

Do I need extra settings when using QCode?

Usually only ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. If you keep hitting errors at the same size, set CLAUDE_CODE_AUTO_COMPACT_WINDOW to compact earlier and send the full error to QCode support.

Recommended plan

Long-context sessions resend a lot of tokens every turn, so heavy daily Claude Code users usually do better on a daily quota than on ad-hoc top-ups. The Daily-35 plan ($53.57 per 30 days, $35 of usage per day at official price × 1.0) fits steady daily development, and you can add a pay-as-you-go pack if you run out on a busy day. See /pricing for current terms.

Recommended plan

One key for both the Anthropic Messages API and OpenAI-compatible APIs. Claude and GPT are billed at the official price ×1.0; live rates are on /models.

Not sure where to start?

Try it for a week

Small Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $9.00/month with $5 of quota every day — just $0.060 per $1 of quota, vs about $0.113 for the Medium Pack