[BUG] CRITICAL: Claude aborts code edits mid-process when tokens run out, leaving irreparably broken code
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
🚨 Whenever the model runs out of tokens during an answer, it abruptly stops editing code in the middle of the process, without warning, rollback, or any form of recovery. The result is partially edited, syntactically invalid, and completely unusable code.
This behavior is catastrophic in a code-editing context. An assistant that modifies files must never abandon an edit halfway through execution. Doing so actively corrupts the user’s codebase and can waste significant time or cause real damage in production environments.
This is not a minor UX issue — it is a fundamental reliability flaw.
Claude must not:
- Stop editing files mid-operation
- Leave code in an inconsistent or uncompilable state
- Abort silently due to token exhaustion
Explicitly refuse to start the edit if it cannot be completed safely
Allowing partial edits to be written and then abandoned is grossly negligent behavior for a coding agent. It breaks the core trust assumption that automated code tools must be safe by default.
It is genuinely alarming that this has not been addressed or reported earlier. In its current state, this behavior makes Claude unsafe for any non-trivial code editing workflow.
What Should Happen?
At an absolute minimum, the agent must:
- Finish the current edit atomically, or
- Revert all partial changes, or
- Explicitly refuse to start the edit if it cannot be completed safely
Error Messages/Logs
Steps to Reproduce
- Ask for anything that involves editing some files just before running out of tokens
- Claude starts editing code normally.
- Tokens run out? STOPS EDITING MID-PROCESS.
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.20
Platform
Other
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
This is the Claude Code for VS Code extension.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗