anomalyco / anomalyco/opencode
write/edit/apply_patch filePath argument not trimmed — local models create files with trailing whitespace in names
@neriousy is already working on this.
Since Aug 17, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Bug
The write, edit, and apply_patch tools pass the filePath argument through verbatim without trimming surrounding whitespace. Local models (e.g. Ollama Gemma) that emit a trailing \n inside the JSON string argument end up creating files whose names literally contain a newline character, e.g. ruleset.md\n instead of ruleset.md.
Reproduction
Config: Ollama provider with gemma-4-12B-code:latest, general subagent model override, LitRPG skill setup that writes 10 state files.
Model emitted a tool call resembling:
{"name": "write", "arguments": {"filePath": "/tmp/opencode/litrpg-gemma-test/ruleset.md\n", "content": "..."}}
Result — all 10 files created with a trailing \n in their names:
$ ls -lab /tmp/opencode/litrpg-gemma-test/
-rw-r--r-- 1237 Aug 17 ruleset.md\n
-rw-r--r-- 392 Aug 17 stats.md\n
... (all 10 files affected)
Hex of a filename tail confirms the literal newline:
$ printf '%s' "ruleset.md\n" | tail -c 5 | od -An -c
r . m d \n
opencode's own log shows the un-trimmed path at write time:
message="touching file" file="/tmp/opencode/litr_gemma_test/inventory.md\n"
message=evaluated permission=edit pattern="../../../../tmp/opencode/litr_gemma_test/inventory.md\n"
The files are effectively invisible to normal ls/cat/editors and to subsequent read/edit calls that use the trimmed name, so the model thinks its writes succeeded but the files are unreachable.
Expected behavior
Trim leading/trailing whitespace (including \n, \r, \t, spaces) from filePath before resolving the path, in write, edit, and apply_patch. A model emitting "filePath": "ruleset.md\n" should write to ruleset.md.
Why this matters
- Affects all local OpenAI-compatible models, not just Gemma — small models commonly include stray whitespace in JSON string args.
- Silent failure: the model reports success, files exist, but are unreachable by name. Very hard to debug without hex inspection of filenames.
- Cloud-hosted models (Claude, GPT) don't hit this because their tool-call args are clean, so the bug is invisible to most users.
Environment
- opencode: latest (1.x)
- Provider: Ollama (local),
@ai-sdk/openai-compatible - Model:
gemma-4-12B-code:latest(Q4_K_M) - OS: Linux
Workaround
Skill authors can add a "path hygiene" instruction to their skill's system prompt (see LitRPG SKILL.md ### When to Write → Path hygiene) telling the model not to include trailing whitespace. This helps but is a skill-level patch for what should be a tool-level invariant.
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.