Last updated: · Applies to: Claude Code context and compaction errors; CLI guidance, with VS Code and Desktop notes

Claude Code compact: Context limit reached and Prompt is too long

For Claude Code context limit or prompt too long errors, update to the latest release first: the CHANGELOG lists several compact fixes. Then follow the error’s /compact or /clear guidance. If automatic compaction is off, the message points to /config. Check whether the prompt reports failed compaction or a single exchange.

Claude Code /compact command

The costs documentation gives this focused compaction example:

/compact Focus on code samples and API usage

Context limit and prompt too long messages

Context limit reached · /compact or /clear to continue

Source: Official error reference.

Context limit reached · /compact or /clear to continue · auto-compact is off · /config to turn it on

Source: Official error reference.

Prompt is too long

Source: Official error reference.

Prompt is too long · automatic compaction failed: …

Source: Official error reference.

Prompt is too long · the request is ~N tokens (limit …)

Source: Official error reference.

Prompt is too long · this conversation is a single exchange and cannot be compacted

Source: Official error reference.

The ellipses and N above represent variable details in the documented variants, not a fixed token count.

Numbered fixes: CLI

  1. Update to the latest release

    Start by updating Claude Code to the latest release. The CHANGELOG lists compact fixes in versions 2.1.284, 2.1.288, 2.1.306 and 2.1.310.

  2. Follow the context limit message

    For the context limit error, use /compact or /clear to continue, as directed by the error reference. If the message says automatic compaction is off, it points to /config to turn it on.

  3. Match the prompt too long variant

    Check whether the message reports automatic compaction failure, the request size, or a single exchange that cannot be compacted. For the single-exchange variant, do not assume another /compact attempt can compact that exchange. See the documented variants.

  4. Give compaction a focus

    For focused compaction, use the /compact Focus on code samples and API usage example from the costs documentation.

Numbered fixes: VS Code

  1. Start with the release fixes

    If you encounter these Claude Code messages while working in VS Code, start with the update-to-latest step above and its linked CHANGELOG versions.

  2. Use the matching error guidance

    Match the message to the errors above. For a CLI session used with VS Code, follow the CLI steps. The cited sources do not provide a separate VS Code compaction procedure.

Numbered fixes: Desktop app

  1. Check the release fixes first

    Start with the update-to-latest guidance and the linked compact fixes above.

  2. Match the displayed message

    Use the error reference above to identify the context limit or prompt too long variant. The cited sources do not provide a separate Desktop compaction procedure.

FAQ

What should I try first when /compact fails?

Update to the latest Claude Code release. The CHANGELOG lists compact fixes in versions 2.1.284, 2.1.288, 2.1.306 and 2.1.310.

What does Context limit reached tell me to do?

The error directs you to use /compact or /clear to continue. If automatic compaction is off, it also points to /config to turn it on.

Can a single exchange always be compacted?

No. The error reference includes a Prompt is too long variant stating that the conversation is a single exchange and cannot be compacted.

How can I give /compact a focus?

Use /compact Focus on code samples and API usage, as shown in the costs documentation.

Sources

This is an independent, unofficial help site. It is not affiliated with or endorsed by Anthropic or OpenAI. Check the linked documentation and reports for your environment.