Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export namespace Config {
.default("ctrl+x")
.describe("Leader key for keybind combinations"),
app_help: z.string().optional().default("<leader>h").describe("Show help dialog"),
app_exit: z.string().optional().default("ctrl+c,<leader>q").describe("Exit the application"),
app_exit: z.string().optional().default("ctrl+d,ctrl+c,<leader>q").describe("Exit the application"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated all locations the exit commands are enumerated

editor_open: z.string().optional().default("<leader>e").describe("Open external editor"),
theme_list: z.string().optional().default("<leader>t").describe("List available themes"),
project_init: z.string().optional().default("<leader>i").describe("Create/update AGENTS.md"),
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/python/src/opencode_ai/models/keybinds_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class KeybindsConfig:
Attributes:
leader (Union[Unset, str]): Leader key for keybind combinations Default: 'ctrl+x'.
app_help (Union[Unset, str]): Show help dialog Default: '<leader>h'.
app_exit (Union[Unset, str]): Exit the application Default: 'ctrl+c,<leader>q'.
app_exit (Union[Unset, str]): Exit the application Default: 'ctrl+d,ctrl+c,<leader>q'.
editor_open (Union[Unset, str]): Open external editor Default: '<leader>e'.
theme_list (Union[Unset, str]): List available themes Default: '<leader>t'.
project_init (Union[Unset, str]): Create/update AGENTS.md Default: '<leader>i'.
Expand Down Expand Up @@ -67,7 +67,7 @@ class KeybindsConfig:

leader: Union[Unset, str] = "ctrl+x"
app_help: Union[Unset, str] = "<leader>h"
app_exit: Union[Unset, str] = "ctrl+c,<leader>q"
app_exit: Union[Unset, str] = "ctrl+d,ctrl+c,<leader>q"
editor_open: Union[Unset, str] = "<leader>e"
theme_list: Union[Unset, str] = "<leader>t"
project_init: Union[Unset, str] = "<leader>i"
Expand Down
4 changes: 2 additions & 2 deletions packages/tui/internal/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ func LoadFromConfig(config *opencode.Config, customCommands []opencode.Command)
Description: "last message",
Keybindings: parseBindings("ctrl+alt+g"),
},

{
Name: MessagesCopyCommand,
Description: "copy message",
Expand All @@ -388,7 +387,8 @@ func LoadFromConfig(config *opencode.Config, customCommands []opencode.Command)
{
Name: AppExitCommand,
Description: "exit the app",
Keybindings: parseBindings("ctrl+c", "<leader>q"),
// NOTE: ctrl+c requires a double press to exit while ctrl+d requires a single press
Keybindings: parseBindings("ctrl+c", "ctrl+d", "<leader>q"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be pulled directly into the user-facing UI for available commands, another reason I decided to continue using the existing AppExitCommand:

Screenshot 2025-10-31 at 11 24 52 AM

Trigger: []string{"exit", "quit", "q"},
},
}
Expand Down
21 changes: 15 additions & 6 deletions packages/tui/internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,14 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

// 8. Handle exit key debounce for app exit when using non-leader command
// 8. Handle immediate exit command both for empty and non-empty editor
exitCommand := a.app.Commands[commands.AppExitCommand]
if exitCommand.Matches(msg, a.app.IsLeaderSequence) {
if exitCommand.Matches(msg, a.app.IsLeaderSequence) && keyString == "ctrl+d" && a.editor.Length() == 0 {
return a, util.CmdHandler(commands.ExecuteCommandMsg(exitCommand))
}

// 9. Handle exit key debounce for app exit when using non-leader command
if exitCommand.Matches(msg, a.app.IsLeaderSequence) && keyString != "ctrl+d" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided a separate block was cleanest. exitCommand is now defined here and used in this block and just below.

switch a.exitKeyState {
case ExitKeyIdle:
// First exit key press - start debounce timer
Expand All @@ -324,22 +329,26 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

// 9. Check again for commands that don't require leader (excluding interrupt when busy and exit when in debounce)
// 10. Check again for commands that don't require leader (excluding interrupt when busy and exit when in debounce)
matches := a.app.Commands.Matches(msg, a.app.IsLeaderSequence)
if len(matches) > 0 {
if len(matches) > 0 && keyString != "ctrl+d" {
// Skip interrupt key if we're in debounce mode and app is busy
if interruptCommand.Matches(msg, a.app.IsLeaderSequence) && a.app.IsBusy() && a.interruptKeyState != InterruptKeyIdle {
return a, nil
}
// Skip ctrl+d immediate exit key if the editor has content. Allow editor update commands to handle it as forward delete.
if exitCommand.Matches(msg, a.app.IsLeaderSequence) && keyString == "ctrl+d" && a.editor.Length() > 0 {
return a, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows the later fall through on next cycle into step 12 further below.

}
return a, util.CmdHandler(commands.ExecuteCommandsMsg(matches))
}

// Fallback: suspend if ctrl+z is pressed and no user keybind matched
// 11. Fallback: suspend if ctrl+z is pressed and no user keybind matched
if keyString == "ctrl+z" {
return a, tea.Suspend
}

// 10. Fallback to editor. This is for other characters like backspace, tab, etc.
// 12. Fallback to editor. This is for other characters like backspace, tab, etc.
updatedEditor, cmd := a.editor.Update(msg)
a.editor = updatedEditor.(chat.EditorComponent)
return a, cmd
Expand Down