You can make ⌘+Left and ⌘+Right hotkeys navigate Claude Code and Codex terminal input to start and end of lines.
This post focuses on iTerm2 for macOS but this should work in virtually any terminal supporting keybindings.
iTerm2 → Preferences → Profiles → Key Bindings
- Click + and set the hotkey to: ⌘+Left
- Use the action: “Send Hex Code”
- Use hex code:
0x01
For ⌘+Right:
- Same sequence as above but set ⌘→ to use hex code:
0x05
Command Up and Down
⌘↑ and ⌘↓ are a bit of a hack but will work in most cases on Codex. If you know what needs to be sent to CC, please comment:
Map ⌘-Up arrow to 25 Up arrows plus Home, and vice-versa for ⌘-Down:
Same as before;
iTerm2 -> Preferences -> Profiles -> Key Bindings
– Click + and set: Cmd+Up
– Use the action: “Send Hex Code”
– Hex Code:
⌘↑
0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41
0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41
0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41
0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41
0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41 0x1B 0x5B 0x41
0x1B 0x5B 0x48
⌘↓
0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42
0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42
0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42
0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42
0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42 0x1B 0x5B 0x42
0x1B 0x5B 0x46
If you use more newlines in these CLI inputs than 25, just increase the repeated hex sequences or mash it. Any longer input I prefer to import from /tmp/.
If you use Claude Code and Codex a lot, please check out my project, Contextify.