[BUG] Editor exiting with nonzero status after ctrl+g leads to data loss
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?
When an editor exits in any unclean manner during a ctrl+g operation -- even if :w or similar was used to write back to the original file prior to that exit -- content is irrevocably lost.
About a deviation from the letter of the preflight checklist: This was first reported as #19306, which was closed and locked due to inactivity and has been used as a duplicate target afterwards (f/e by #26350 and #35146). Because it's locked, it can't be 👍's by people experiencing the issue, so if one honors the letter of the preflight checklist there's currently no mechanism for people experiencing this bug to report it (which, as it costs human input/thinking -- manual editor use is generally done when building complicated prompts or feedback -- is genuinely both expensive and disruptive). Accordingly, I'm interpreting "have searched existing issues and this hasn't been reported yet" as "hasn't been reported yet on any ticket that is open or available to :+1:".
What Should Happen?
My ideal outcome is that if the original prompt state was empty, and after the child-process exits the editor state is _not_ empty, that content should be kept, rather than returning to an entirely empty state.
If this is considered suboptimal because it discards human intent when humans use editor features that force a nonzero outcome, then I would propose as an alternative that there be a well-known location where this content be available for recovery -- akin to how git stores .git/COMMIT_EDITMSG after editing, making it available for recovery/retrieval.
Error Messages/Logs
Steps to Reproduce
- Use an EDITOR with a bug that causes nonzero exits, _or_ (for testing purposes) an editor with an explicit unclean-exit (in
hx, for example,:cqdoes this. - Press ctrl+g in Claude Code to enter this editor.
- Enter some text. Save it (in
hx, via:w). - Trigger an unclean exit (as with
:cq). - Observe that the text that was entered and saved has been discarded.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.220 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗