[BUG] After exiting claude in the wsl terminal, an input error occurred
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?
In WSL (Windows Subsystem for Linux), after enabling claude in the terminal and exiting, entering ctrl+c in the terminal will change it to 9;5u9
What Should Happen?
ctrl+c can work success
Error Messages/Logs
Steps to Reproduce
这是一个经典的终端转义序列污染问题。Claude Code 退出后没有正确恢复终端状态,导致终端进入了某种特殊的键盘输入模式(具体是 "kitty keyboard protocol" 或类似的增强键盘模式)。
原因: Claude Code 启用了扩展键盘协议(如 \033[?2004h bracketed paste 或 \033[>4;1m kitty keyboard protocol),退出时没有正确禁用,导致 Ctrl+C 等按键被编码成 9;5u 这样的序列。
立即修复(在当前损坏的终端中):
printf '\033[?2004l' # 禁用 bracketed paste
printf '\033[>4;0m' # 禁用 kitty keyboard protocol
printf '\033[<u' # 退出 kitty keyboard mode
printf '\033=\033>' # 重置 keypad 模式
stty sane # 恢复 stty 设置
reset # 终极重置
或者直接运行:
reset
如果 reset 也无效(因为 Ctrl+C 打印乱码),可以盲打:
reset
然后回车(不需要看到输出)。
根本解决方案:
这是 Claude Code 的已知 bug。可以在 shell 的配置文件(~/.bashrc 或 ~/.zshrc)里加一个退出后自动修复的函数:
# 在 ~/.bashrc 末尾添加
claude() {
command claude "$@"
printf '\033[?2004l\033[>4;0m\033[<u'
stty sane 2>/dev/null
}
这样每次 claude 命令退出后都会自动清理终端状态。
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.83
Platform
Other
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
4 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
i just got claude enterprise from my company and this is really annoying.
Workaround to restore your terminal
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.