Skip to content

SDK cannot handle question tool interaction (no way to respond to tool calls in serve mode) #19702

Closed as not planned

Description

@ZYT20001

Description

Problem

When using OpenCode via SDK (not CLI), there is no way to handle or respond to the question tool call triggered by the model.

In my setup, I built a custom frontend (web UI) and communicate with OpenCode through the SDK + backend service. However:

  • The model frequently triggers the question tool
  • The server enters a waiting state for user input
  • But the SDK does NOT expose any API to:
    • intercept the question tool call
    • provide the answer programmatically
    • continue the execution loop

This causes the request to hang indefinitely.


Expected Behavior

There should be a way in SDK / serve mode to:

  1. Detect when a question tool is triggered
  2. Retrieve the question payload (prompt, metadata, etc.)
  3. Send back the user's answer programmatically
  4. Resume the execution

Example (pseudo API):

client.onToolCall((tool) => {
  if (tool.name === "question") {
    return {
      answer: "user input from my UI"
    }
  }
})

### Plugins

_No response_

### OpenCode version

1.3.2

### Steps to reproduce

## CLI vs SDK Behavior

CLI:
- `question` is displayed
- user can input answer
- execution continues

SDK:
- `question` is triggered internally
- no way to respond
- execution hangs

This indicates the interaction layer exists in CLI but is not exposed in SDK.

### Screenshot and/or share link

_No response_

### Operating System

windows

### Terminal

_No response_

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 29, 2026
  2. github-actions commented on Mar 29, 2026

    @github-actions
    Contributor

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

    If your issue is not covered by either of those, please add clarifying details to differentiate.

  3. theredbluepill commented on Apr 15, 2026

    @theredbluepill

    This issue is indeed so annoying..

  4. theredbluepill commented on Apr 15, 2026

    @theredbluepill

    Can try custom tool:

    import { tool } from "@opencode-ai/plugin"
    
    export const ask_user = tool({
      description:
        "Ask the user a question with multiple-choice options. " +
        "This tool returns IMMEDIATELY — it does NOT block or wait for the answer. " +
        "The playground UI will show an interactive selection banner. " +
        "The user's answer will arrive as the next message in the conversation. " +
        "After calling this tool, STOP and wait for the user's reply before continuing.",
      args: {
        questions: tool.schema
          .array(
            tool.schema.object({
              id: tool.schema.string().describe("Unique question identifier"),
              prompt: tool.schema
                .string()
                .describe("The question text to display"),
              options: tool.schema
                .array(
                  tool.schema.object({
                    id: tool.schema.string().describe("Option identifier"),
                    label: tool.schema.string().describe("Option display text"),
                  }),
                )
                .describe("List of choices the user can pick from"),
              allow_multiple: tool.schema
                .boolean()
                .optional()
                .describe("If true, user can select multiple options"),
            }),
          )
          .describe("One or more questions to ask the user"),
      },
      async execute(args) {
        const summary = args.questions
          .map((q) => `${q.prompt} (${q.options.length} options)`)
          .join("; ")
        return `Asked the user: ${summary}. Waiting for their reply in the next message.`
      },
    })
    
    
  5. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. rekram1-node commented on Jun 23, 2026

    @rekram1-node
    Collaborator

    Automated: closing question issues.

    GitHub Issues are for bug reports and feature requests only — questions / support are no longer tracked here.

    If this is a bug or feature request, please open a new issue with the appropriate template.

  7. rekram1-node commented on Jun 23, 2026

    @rekram1-node
    Collaborator

    Reopening – this was incorrectly closed by automated question-issue cleanup. Sorry for the noise.

  8. sergiofspedro commented on Aug 9, 2026

    @sergiofspedro

    Corroborating evidence from direct runtime introspection (OpenCode 1.18.15): ctx.client.question is undefined inside a plugin, and ctx.client.session's actual prototype methods are:

    list, create, status, delete, get, update, children, todo, init, fork, abort, unshare, share, diff, summarize, messages, prompt, message, promptAsync, command, shell, revert, unrevert
    

    — nothing question-related. Confirmed via Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.client.session)), not just docs/types.

    As a stopgap for anyone hitting this in the meantime: we built a polling-based workaround (not a real fix, just documenting the pattern in case it helps someone before a real API ships) that watches session.list() + session.messages() for a session whose trailing message part is a still-pending question tool call, and after a configurable timeout calls session.abort() + session.prompt() to unstick the session with a "proceed with your best judgement" instruction — since there's no way to actually answer the question object itself through the plugin SDK today.

  9. github-actions commented on Oct 10, 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