File paths are randomly interpreted in subagents.
It seems the most reliable way to specify file paths is "bare", ie without any markup, such as path/to/some/where.
Using the following sometimes get it right but sometimes the characters are escaped and folders are created with round brackets, backtick, etc:
- {file:path/to/some/file.txt}
folder_name(backticks -> github doesn't show the backticks)- {folder_name}
- "folder_name"
I tested it in subagents and it would just take each of these file paths literally, rather than stripping the special characters.
Is this due to Grok or due to Opencode?
This issue might be a duplicate of existing issues. Please check:
- #797: CLI argument parsing fails with unescaped special characters (?, ', (, etc.) - deals with how special characters in file paths are interpreted by the shell/system
- #2311: Pasting in a relative path to a folder results in an error - specifically about how paths with special formatting are handled
- #2799: ENOENT error when referencing file paths in OpenCode AI CLI (windows) - similar file path resolution issues in subagents/agents
- #1583: On windows, referencing a file puts linux root
/before it - another case of file paths being incorrectly interpreted
Feel free to ignore if none of these address your specific case with subagents treating markup literally instead of stripping special characters.
I tested it in subagents and it would just take each of these file paths literally, rather than stripping the special characters.
I just wanna make sure I am following you correctly, how are you testing this with subagents? Are you including file paths in their .md definitions? Or in the opencode.json file? Or are you saying you can't get them to read files correctly? I am just trying to make sure I understand correctly
I was setting up a workflow with subagents. I want them to read and write to certain folders, so I wrote tests. Sometimes the agent correctly parses file paths, other times it creates folders including the special characters (the shell showed it escaped these characters with backslash). The behavior was random/intermittent. Claude Code exhibited the same behavior. Generally writing file paths without any markup worked best, but that will cause problems if file paths includes spaces.
Sample content below.
Shell: do agent-Subagent1
Subagent1.md content:
- do agent-Subagent2
- do agent-Subagent3
- do agent-Subagent4 etc
Subagent2.md content: put file test.txt in folder @Folder1 ==> creates folder @Folder1 (ie. folder name includes @ sign)
Subagent3.md content: put file "test.txt" in folder "Folder2" ==> creates folder "Folder2" (includes quotes in folder name)
Subagent4.md content: put file test.txt in {file:Folder3} ==> creates folder {file:Folder3}
i mean to me this just looks like prompting, if you want it to create specific files then just tell it how to name and what to do given specific characters, this doesnt seem like an opencode problem necessarily especially given your comment about this also happening in claude code.
Not sure if there is anything to do on our end but it doesnt seem like there is
In Linux shell, if I say mkdir "Folder1", it will create the folder Folder1 without the double quotes.
This is useful when the folder has spaces. For example, if I write mkdir This is my folder, this will create 4 folders, which is not what I want. To me, it seems to be a convention that the quotes are not part of the folder name unless it is escaped with a backslash, ie. \"Folder1\".
The other issue is that the behavior is not deterministic. The outcome changes from one run to the next.
The third issue is that online examples of subagent markdown files use the notation I wrote above. That's going to cause confusion/problems for people.
Maybe you're right, this could be an LLM problem. The LLM doesn't have a convention for file paths, so its interpretation varies. In any case, I haven't seen any subagent code examples where they specify what the convention for file paths are, they just use one of the methods I gave. I'll try adding instructions in the prompt regarding the file path and see how it goes.
if you continue having prompting issues lmk