claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[Bug] Context Truncation: Claude Sonnet Loses Context Prematurely

Open non-stop-dev opened this issue 3 months ago • 2 comments

Bug Description I note that inside the same coding chat (without compress chat neither clear chat) Claude Sonnet 4 forgets context somewhere in between 50% and 80% of the context size before it fills up (a rough approximation). I need to stop the chat and explain the correct context again because it likely forgets

Environment Info

  • Platform: darwin
  • Terminal: vscode
  • Version: 1.0.120
  • Feedback ID: 02836c70-57ad-4551-a31c-8e8f6cd3607a

Errors

[{"error":"Error: EISDIR: illegal operation on a directory, read\n    at Module.readFileSync (node:fs:440:20)\n    at Object.readFileSync (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:719:6848)\n    at x9B (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3563:9983)\n    at Object.call (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1724:978)\n    at call.next (<anonymous>)\n    at VJ5 (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3350:21057)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async WNB (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3350:17339)\n    at async f9B (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1729:3422)\n    at async rJB (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1972:1631)","timestamp":"2025-09-20T06:10:03.696Z"},{"error":"Error: Language not supported while highlighting code, falling back to markdown: \n    at iV (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:1184)\n    at file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:912\n    at Array.map (<anonymous>)\n    at TX (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:903)\n    at cNB (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3368:13746)\n    at QC (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:84:19415)\n    at Jp (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:42814)\n    at W9 (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38355)\n    at Hh (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38283)\n    at zC (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38137)","timestamp":"2025-09-20T06:13:05.539Z"},{"error":"Error: Language not supported while highlighting code, falling back to markdown: \n    at iV (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:1184)\n    at file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:912\n    at Array.map (<anonymous>)\n    at TX (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:903)\n    at cNB (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3368:13746)\n    at QC (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:84:19415)\n    at Jp (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:42814)\n    at W9 (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38355)\n    at Hh (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38283)\n    at zC (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38137)","timestamp":"2025-09-20T06:13:05.553Z"},{"error":"Error: Language not supported while highlighting code, falling back to markdown: \n    at iV (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:1184)\n    at file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:912\n    at Array.map (<anonymous>)\n    at TX (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1794:903)\n    at cNB (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3368:13746)\n    at QC (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:84:19415)\n    at Jp (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:42814)\n    at W9 (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38355)\n    at Hh (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38283)\n    at zC (file:///Users/leonardoleon/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:86:38137)","timestamp":"2025-09-20T06:13:05.553Z"},{"

Note: Error logs were truncated.

non-stop-dev avatar Sep 20 '25 19:09 non-stop-dev

Still experiencing this on October 16. Silent truncation at random capacity, no validation errors as documented. Sometimes it happens in as few as 20 messages from conversation start. This is causing significant disruption to my workflow. Can we get an update on whether this is expected behavior or a bug? If expected, the documentation at https://docs.claude.com/en/docs/build-with-claude/context-windows should be updated to reflect actual behavior, as it explicitly says that context is NOT truncated. Testing on Opus to see if the bug shows up there as well, so far so good. Sonnet 4.5, however, is completely unusable for actual workloads. The recent downsizing of the Opus caps combined with this issue are putting me between a rock and a hard place in justifying the cost of a Pro subscription.

giovinazzo-kevin avatar Oct 16 '25 19:10 giovinazzo-kevin

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 07 '25 10:12 github-actions[bot]