Troubleshooting Claude Code: Fixing the “/context” Prompt Too Long Error

Are you encountering a frustrating Error: 400 while using the /context command in the Claude Code CLI? You aren’t alone. A recent bug report suggests that many developers are hitting token limits when attempting to add context to their sessions, particularly when using the Sonnet model.In this post, we’ll break down what this error means, why it’s happening, and look at the current status of the issue.

The Error: “Prompt is too long”

The specific issue arises when running the /context command. Instead of successfully adding your files or directory to the LLM’s context window, the CLI crashes with a JSON error message similar to this:


Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 206453 tokens > 200000 maximum"}}

What Does This Mean?

Simply put, the amount of data you are trying to feed Claude exceeds its context window. In the error above, the user attempted to send 206,453 tokens, but the model (likely Claude 4.5 Sonnet) has a hard limit of 200,000 tokens for this specific endpoint or tier.

Alongside this token error, logs from the issue also show an EISDIR: illegal operation on a directory error. This suggests the tool might be mistakenly trying to read a directory as if it were a single file, or recursively adding too much content without filtering, causing the token count to explode.

Root Causes Identified in GitHub Issue #11430

According to GitHub Issue #11430 in the anthropics/claude-code repository, this behavior has been flagged as a bug.

  • Environment: The issue appears prevalent on macOS environments.
  • Model: It is specifically noted with sonnet[1m].
  • Trigger: Using the /context command, which is supposed to help Claude understand your codebase.

The presence of the EISDIR error in the logs indicates that the CLI might be failing to correctly exclude directories or is attempting to read them directly, contributing to the massive token count that crashes the request.

Potential Workarounds

While the issue is currently Open and awaiting a fix from the Anthropic team, here are a few steps you can take to mitigate the error:

  1. Be Selective with Context: Avoid running /context on your entire root directory. Instead, add specific files or smaller folders that are relevant to the task at hand.
  2. Check Your Ignore Files: Ensure you have a robust .gitignore or .claudeignore (if applicable) to prevent the CLI from picking up massive dependencies like node_modules, build artifacts, or large assets.
  3. Restart the Session: Sometimes token counts can accumulate in a long-running session. Restarting the CLI might clear the buffer.

See more about this here:👉 GitHub Issue: [Bug] /context command not functioning with sonnet #11430

Scroll to Top