Repository navigation
Description
Description
When running opencode serve, the question tool is not exposed to web interface clients on initial connection. However, after attaching a TUI client (opencode attach), the tool becomes available to all clients including web.
Root Cause Analysis
Root Cause
The ToolRegistry in packages/opencode/src/tool/registry.ts evaluates the question tool's availability at cache initialization time (in the all() function) rather than at request time (in ids() and tools() methods).
The all() function uses Effect's InstanceState scoped caching mechanism. When the first web client connects, the tool list is cached with the Flag.OPENCODE_CLIENT evaluation occurring during this initialization. Due to how the web client's request context is established, this flag evaluation happens incorrectly or in an incomplete context, causing the question tool to be excluded from the cached tool list.
When a TUI client attaches via opencode attach, it triggers Instance.provide() with proper InstanceBootstrap, which refreshes or invalidates the cache. Subsequent requests then receive the correct tool list including question.
Problematic Code Location
File: packages/opencode/src/tool/registry.ts (lines 119-120)
const all = Effect.fn('ToolRegistry.all')(function* (custom: Tool.Info[]) {
const cfg = yield* config.get();
const question =
['app', 'cli', 'desktop'].includes(Flag.OPENCODE_CLIENT) || Flag.OPENCODE_ENABLE_QUESTION_TOOL;
// ^ Evaluated at cache init time, not per-request!
return [
InvalidTool,
...(question ? [QuestionTool] : []), // Cached incorrectly for web clients
// ... other tools
];
});Plugins
OpenCode version
v1.3.12
Steps to reproduce
- Start OC in server mode
opencode serve --port 1234 - Open web interface in a browser (do not yet attach TUI)
- Create a new session and ask: "Do you have the question tool available?" and verify no question tool available
- Attach TUI to same server
opencode attach http://localhost:1234 - Ask same question in the same session and now question tool is magically available
Screenshot and/or share link
Debug session with Kimi: https://opncd.ai/share/tg0yhnpM
Operating System
Ubuntu 24.04 LTS
Terminal
Windows Terminal
Activity
gund commentedon Apr 1, 2026
If you are interested: Suggested Fix
Suggested Fix
Move the
questiontool filtering from cache-time to request-time:File:
packages/opencode/src/tool/registry.ts1. Modify
all()function (lines ~119-148)Remove the conditional and always include
QuestionTool:2. Modify
ids()function (around line ~165)Add dynamic filtering at request time:
3. Modify
tools()function (around line ~173)Add dynamic filtering at request time:
Summary of Changes
Flag.OPENCODE_CLIENTevaluation happens atInstanceStateinitialization → cached → wrong result for early web clientsFlag.OPENCODE_CLIENTevaluation happens at each API request → always fresh → correct result for all clientsNOTE: This was analyzed and generated by Kimi K2.5 without any manual cross checking
rekram1-node commentedon Jun 23, 2026
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.
rekram1-node commentedon Jun 23, 2026
Reopening – this was incorrectly closed by automated question-issue cleanup. Sorry for the noise.
github-actions commentedon Aug 23, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.