Skip to content

Question Tool Keyboard Conflict and Agent Switch Issue #7496

Closed as not planned

Description

@Hipfox

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

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Jan 9, 2026
  2. github-actions commented on Jan 9, 2026

    @github-actions
    Contributor

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

    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.

  3. faileon commented on Feb 4, 2026

    @faileon

    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.

  4. Mishkun commented on Feb 13, 2026

    @Mishkun
    Contributor

    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

  5. Chocothin commented on Mar 12, 2026

    @Chocothin

    I have a fix for this and will open a PR shortly. It suspends command keybinds while modal prompts are active, using the existing pattern from autocomplete.tsx. Hope it helps!

  6. malventano commented on Apr 20, 2026

    @malventano

    I have a fix for this and will open a PR shortly. It suspends command keybinds while modal prompts are active, using the existing pattern from autocomplete.tsx. Hope it helps!

    With your PR, how does the user know the agent was switched when pressing tab during a question prompt?

  7. removed
    bugSomething isn't working
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on May 3, 2026
  8. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions