Editor temp file deleted prematurely - content lost on typo in vim save command

Resolved 💬 3 comments Opened Apr 2, 2026 by Hancks Closed Apr 6, 2026

Bug description

When using the external editor (opened via Ctrl+G) with vim, if the user makes a typo in the save/quit command (e.g., :W or :Wq instead of :w or :wq), and then corrects it, the content can be lost. Only the first line of the prompt remains.

It appears the temporary file (claude-prompt-*.md in the system temp folder) is being deleted or truncated prematurely, before the user has successfully saved and closed the editor.

Steps to reproduce

  1. In Claude Code, press Ctrl+G to open the external editor (vim)
  2. Write a long, multi-line prompt
  3. Attempt to save with a typo, e.g., :W (capital W) or :Wq
  4. Correct the command with :wq
  5. The prompt submitted to Claude is missing most of the content (only the first line remains)

Expected behavior

The temp file should persist until the editor process exits successfully and the content has been read back by Claude Code. The file should not be deleted or modified while the editor is still open.

Actual behavior

The prompt content is lost — only the first line is submitted. The temp file is deleted immediately and cannot be recovered (no swap files, no undo history).

Impact

This caused loss of ~30 minutes of work writing a detailed prompt. There is no way to recover the content since:

  • The temp file is deleted
  • No vim swap/undo files are preserved
  • The content is not logged in conversation history

Environment

  • macOS (Darwin 25.3.0)
  • Claude Code CLI v2.1.90
  • Vim 9.1
  • Editor opened via Ctrl+G

Suggested fix

Consider one or more of:

  1. Don't delete the temp file until the content has been successfully read back
  2. Keep a backup of the last N editor temp files (e.g., in ~/.claude/editor-history/)
  3. Only accept editor content on clean exit (exit code 0)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗