Ask opencode (new session)
opencode_askAsk an AI agent to solve a coding question or task in a new session and receive its final answer. Works with free hosted models or your own API key, with optional project context.
Instructions
Ask opencode (opencode run) a question or task in a NEW session.
The one backend here that needs NO subscription: opencode's own free hosted
models (opencode/*-free, see opencode models) answer with zero credentials
configured, so this works on a machine that has never logged in to anything.
Add a key with opencode auth login for Claude/GPT-class models. Returns the
agent's final message, reconstructed from opencode's --format json events.
Point workspace at a project dir for context-aware answers.
⚠️ The free models are SLOW (queue-scheduled — a one-word answer has taken minutes), which is why timeout_s defaults to 300 here. Prefer a configured paid model for anything long, and don't mistake slowness for a hang.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | Optional model id (`-m`, "provider/model" — e.g. "opencode/nemotron-3.5-lightning-free"); validated against `opencode models` and rejected on a typo. Omit for opencode's configured default. | |
| watch | No | If true, open a live "watch" view streaming opencode's steps from the same `--format json` event stream. Same final text is returned. Best-effort. Default false. | |
| prompt | Yes | Question or instruction for opencode. | |
| sandbox | No | Permission policy, applied via opencode's OPENCODE_PERMISSION and enforced by the agent on every platform alike: "read-only" (default — no edit/bash/subagent/network tools, `.env` files denied), "workspace-write" (edit and shell inside the workspace; reaching outside it is denied), or "danger-full-access" (opencode's own `--auto`, no policy — avoid). ⚠️ Agent-enforced, NOT an OS boundary: a determined tool call is refused by opencode, not by the kernel. For a hard boundary, use codex. | read-only |
| timeout_s | No | Max seconds to wait for opencode to complete. Default 300. | |
| workspace | No | Working root (`--dir`). Defaults to the server cwd. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |