anomalyco / anomalyco/opencode
CLI prompt argument's quotes/newlines get corrupted before being sent as the user message to the LLM provider
@nexxeln is already working on this.
Since Aug 21, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
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)
Operating System
macOS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.