You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CLI prompt argument's quotes/newlines get corrupted before being sent as the user message to the LLM provider #43923
The CLI prompt argument (opencode run "...") is corrupted before being sent as the user message to the LLM provider, when it contains internal double-quotes and/or newlines. This appears to reliably break tool-calling for at least some local (Ollama, OpenAI-compatible) models, and may be a contributing factor in other reports of "model outputs tool calls as text instead of executing them" (e.g. #33959, #37543, #21181, #29757) — those reports show the same class of symptom, though I haven't verified they share this exact root cause.
Captured the real outgoing wire request via a transparent logging proxy in front of an OpenAI-compatible Ollama provider. The user message content opencode actually transmits is wrapped in a literal leading/trailing ", with every internal " backslash-escaped — but embedded newlines are left as raw literal newlines, not escaped as \n. This isn't valid JSON string content (real JSON.stringify would also escape \n); it looks like a hand-rolled "escape quotes for embedding" step that's missing newline handling. The system message (agent prompt config) in the same request was NOT corrupted — this is specific to how the CLI prompt argument becomes the user-turn message, not a general serialization bug.
Causal verification
Built matched payloads (real captured system prompt, same tool schema, temperature: 0.15, stream: false) and sent them directly to Ollama's native /api/chat, varying only the user message content:
User message
Trials
Tool-call success
Corrupted (exactly as opencode sent it)
7
0/7
De-corrupted (same text, quoting/wrapper fixed)
6
6/6
Every real opencode run dispatch against this same prompt failed outright; the exact same prompt text sent uncorrupted via raw curl/direct API succeeds reliably. This also explains why "the model works fine when I test the API directly, but not through opencode" shows up in several other issues in this repo — testing the API directly naturally uses clean, uncorrupted prompt text.
Steps to reproduce
opencode run --agent <any> "text with \"internal quotes\" and
newlines"
Capture the outgoing request to the provider (e.g. via a logging reverse proxy in front of an OpenAI-compatible baseURL) and inspect the user message's content field — it will contain a stray wrapping ", escaped internal quotes, but raw unescaped newlines.
OpenCode version
1.18.18 (compiled Bun binary — could not locate readable source locally to pinpoint the exact code path; this may be in the CLI arg → message-part construction, or in provider message serialization)
Confirming on v2.0.10 (Sep 2026): the wrapping " around the opencode run prompt argument is still present. Reproduced by inspecting the stored user message in opencode.db — the CLI argument arrives as "prompt text" while the interactive TUI does not.
Workaround for scripts invoking opencode run: pipe the prompt via stdin (printf '%s' "$PROMPT" | opencode run --auto) instead of passing it as an argument — the stdin path stores and sends the prompt verbatim (no quotes, no trailing newline added when using printf).
Activity
kjetilhartveit commentedon Sep 20, 2026
Confirming on v2.0.10 (Sep 2026): the wrapping
"around theopencode runprompt argument is still present. Reproduced by inspecting the stored user message inopencode.db— the CLI argument arrives as"prompt text"while the interactive TUI does not.Workaround for scripts invoking
opencode run: pipe the prompt via stdin (printf '%s' "$PROMPT" | opencode run --auto) instead of passing it as an argument — the stdin path stores and sends the prompt verbatim (no quotes, no trailing newline added when usingprintf).thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊
fix(opencode): optionally pass the prompt to opencode run verbatim
fix(opencode): optionally pass the prompt to opencode run verbatim