[BUG] Going to previous command in terminal editing loses current command (data loss)
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: v1.0.25
- Operating System: macOS Sonoma 14.7
- Terminal: iTerm2
Bug Description
As I was creating and editing a multiline command, I used Ctrl-P and Ctrl-N to move between displayed lines in the current command. Using Ctrl-P auto-repeat, I accidentally moved from the current, not-sent command, to the previously issued command. The command I was creating was no longer displayed or accessible with Ctrl-N. The command was about 10 lines long, and contained 3-4 minutes of concentration and careful creation, and it was lost.
Steps to Reproduce
- In the Claude Code terminal entry box, issue
/clear - Type a multiline prompt.
- Use Ctrl-P (and perhaps Ctrl-N) to move to different parts of the draft command to edit.
- Use Ctrl-P to back up to the
/clearcommand. - Use Ctrl-N to try to re-enter the draft command.
Expected Behavior
If I'm drafting a command and use Ctrl-P to move to the most recently performed command, I expect the terminal editor to preserve my draft command, and let me use Ctrl-N to move back down into it.
Actual Behavior
I used Ctrl-P within my draft command, and accidentally moved into the most recently performed command, /clear. At that point, I could no longer see my draft command, nor use Ctrl-N to move back to it. My draft command was lost.
Additional Context
My regular shell, zsh, works as I would expect. If I move from a partially completed draft command back in the history with Ctrl-P, I can use Ctrl-N to get back to the partially completed draft command.
I had previously run /terminal-setup in Claude Code to install Shift+Enter key binding for newlines in iTerm 2.
Clunky workaround: For a prompt/command that extends over more than one display line, draft it in a text editor instead of Claude Code, then copy/paste it into Claude Code.
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗