Question Tool Keyboard Conflict and Agent Switch Issue #4535

Open
opened 2026-02-16 17:44:30 -05:00 by yindo · 3 comments
Owner

Originally created by @Hipfox on GitHub (Jan 9, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

QuestionPrompt displays "tab" hint but doesn't handle tab key, causing unintended agent switch

When using the Question tool with a custom primary agent that has question: allow permission, pressing Tab in the QuestionPrompt UI causes the system to unexpectedly switch to another primary agent (e.g., build).

Root Cause

Two issues were identified:

  1. Keyboard Binding Conflict

The QuestionPrompt component displays ⇆ tab as the hint for switching between question tabs, but:

  • The actual implementation uses left/right or h/l keys (not tab)
  • The tab key event is not consumed (evt.preventDefault() is not called)
  • The global agent_cycle keybind defaults to tab
  • When user presses Tab, the event bubbles up and triggers agent switching

Relevant code:

packages/opencode/src/cli/cmd/tui/routes/session/question.tsx:150-162

// Only handles left/right/h/l, NOT tab
if (evt.name === "left" || evt.name === "h") {
  evt.preventDefault()
  const next = (store.tab - 1 + tabs()) % tabs()
  setStore("tab", next)
  setStore("selected", 0)
}

if (evt.name === "right" || evt.name === "l") {
  evt.preventDefault()
  const next = (store.tab + 1) % tabs()
  setStore("tab", next)
  setStore("selected", 0)
}

But the UI hint at line 346 shows:

<text fg={theme.text}>
  {"⇆"} <span style={{ fg: theme.textMuted }}>tab</span>
</text>
  1. Agent Reset on Component Remount (Secondary Issue)

After answering a question, the Prompt component may be remounted due to session() briefly becoming undefined during data sync. This causes:

  • syncedSessionID (a closure variable) to reset to undefined
  • The createEffect in prompt/index.tsx:132-150 re-executes
  • Agent is set based on lastUserMessage().agent, which may be a different agent

Plugins

No response

OpenCode version

1.1.8

Steps to reproduce

  1. Create a custom primary agent with question: allow permission
  2. Switch to the custom agent
  3. Send a prompt that triggers the Question tool
  4. When QuestionPrompt appears, press Tab key
  5. Observed: System switches to build agent (or next primary agent)
  6. Expected: Tab should switch between question tabs (or at minimum, not trigger agent switch)

Screenshot and/or share link

No response

Operating System

CachyOS x86_64

Terminal

alacritty 0.16.1

Originally created by @Hipfox on GitHub (Jan 9, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description QuestionPrompt displays "tab" hint but doesn't handle tab key, causing unintended agent switch When using the Question tool with a custom primary agent that has question: allow permission, pressing Tab in the QuestionPrompt UI causes the system to unexpectedly switch to another primary agent (e.g., build). Root Cause Two issues were identified: 1. Keyboard Binding Conflict The QuestionPrompt component displays ⇆ tab as the hint for switching between question tabs, but: - The actual implementation uses left/right or h/l keys (not tab) - The tab key event is not consumed (evt.preventDefault() is not called) - The global agent_cycle keybind defaults to tab - When user presses Tab, the event bubbles up and triggers agent switching Relevant code: packages/opencode/src/cli/cmd/tui/routes/session/question.tsx:150-162 ``` // Only handles left/right/h/l, NOT tab if (evt.name === "left" || evt.name === "h") { evt.preventDefault() const next = (store.tab - 1 + tabs()) % tabs() setStore("tab", next) setStore("selected", 0) } if (evt.name === "right" || evt.name === "l") { evt.preventDefault() const next = (store.tab + 1) % tabs() setStore("tab", next) setStore("selected", 0) } ``` But the UI hint at line 346 shows: ``` <text fg={theme.text}> {"⇆"} <span style={{ fg: theme.textMuted }}>tab</span> </text> ``` 2. Agent Reset on Component Remount (Secondary Issue) After answering a question, the Prompt component may be remounted due to session() briefly becoming undefined during data sync. This causes: - syncedSessionID (a closure variable) to reset to undefined - The createEffect in prompt/index.tsx:132-150 re-executes - Agent is set based on lastUserMessage().agent, which may be a different agent ### Plugins _No response_ ### OpenCode version 1.1.8 ### Steps to reproduce 1. Create a custom primary agent with question: allow permission 2. Switch to the custom agent 3. Send a prompt that triggers the Question tool 4. When QuestionPrompt appears, press Tab key 5. Observed: System switches to build agent (or next primary agent) 6. Expected: Tab should switch between question tabs (or at minimum, not trigger agent switch) ### Screenshot and/or share link _No response_ ### Operating System CachyOS x86_64 ### Terminal alacritty 0.16.1
yindo added the opentuibug labels 2026-02-16 17:44:30 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 9, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #7441: TypeScript error with KeyEvent stopPropagation (related to preventing event propagation in keyboard handlers)
  • #5820: Autocomplete dropdown conflicts with permission dialog - keyboard event capture conflicts
  • #7384: TUI Commands modal passes Esc key through to other handlers (event propagation issue)
  • #4727: Subagent switching is buggy and laggy (related UI component switching issues)

Additionally, since this issue involves keyboard shortcuts (Tab key), please also check our pinned keybinds documentation: #4997

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 9, 2026): This issue might be a duplicate of existing issues. Please check: - #7441: TypeScript error with KeyEvent stopPropagation (related to preventing event propagation in keyboard handlers) - #5820: Autocomplete dropdown conflicts with permission dialog - keyboard event capture conflicts - #7384: TUI Commands modal passes Esc key through to other handlers (event propagation issue) - #4727: Subagent switching is buggy and laggy (related UI component switching issues) Additionally, since this issue involves keyboard shortcuts (Tab key), please also check our pinned keybinds documentation: #4997 Feel free to ignore if none of these address your specific case.
Author
Owner

@faileon commented on GitHub (Feb 4, 2026):

I think in general the question tool is very annoying to work with mainly due to the agent switching - often i am in plan mode, and i would like to switch to build mode during the question tool, but i cannot do that - or i havent found a way to do that... Tab for me swiches between the question tabs.

@faileon commented on GitHub (Feb 4, 2026): I think in general the question tool is very annoying to work with mainly due to the agent switching - often i am in plan mode, and i would like to switch to build mode during the question tool, but i cannot do that - or i havent found a way to do that... Tab for me swiches between the question tabs.
Author
Owner

@Mishkun commented on GitHub (Feb 13, 2026):

I think in general the question tool is very annoying to work with mainly due to the agent switching - often i am in plan mode, and i would like to switch to build mode during the question tool, but i cannot do that - or i havent found a way to do that... Tab for me swiches between the question tabs.

I guess the issue here that question tool does not consume tab key and it is passed further to agent switching

@Mishkun commented on GitHub (Feb 13, 2026): > I think in general the question tool is very annoying to work with mainly due to the agent switching - often i am in plan mode, and i would like to switch to build mode during the question tool, but i cannot do that - or i havent found a way to do that... Tab for me swiches between the question tabs. I guess the issue here that question tool does not consume tab key and it is passed further to agent switching
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4535