Description
When an agent passes a path starting with ~ (e.g. ~/.bashrc) to any file tool, the tilde is treated as a literal directory name rather than expanded to the home directory.
Affected tools: read (filePath), write (filePath), edit (filePath), glob (pattern, path), grep (path). bash works incidentally (shell expands ~).
Expected Behavior
Read ~/.bashrc resolves to /Users/username/.bashrc.
Actual Behavior
Resolves relative to cwd — path.resolve() joins the raw ~/.bashrc string with the working directory, producing a path that does not exist.
File not found: /home/user/~/...bashrc
Root Cause
The shared path resolution in packages/opencode/src/filesystem.ts uses:
const absolute = path.resolve(location.directory, input.path)
Node.js path.resolve() does not expand ~ — it treats it as a literal directory name. No tilde expansion exists anywhere in the file tool path resolution pipeline.
Suggested Fix
Expand ~ before passing to path.resolve():
const expanded = input.path.startsWith("~")
? path.join(homedir(), input.path.slice(1))
: input.path
const absolute = path.resolve(location.directory, expanded)
Or use untildify (zero-dependency, 16M+ weekly downloads). Applied to the shared resolve() function in filesystem.ts, this fixes all file tools in one place (~3 lines).
Related
Plugins
none
OpenCode version
1.17.4
Steps to reproduce
- In an opencode session, instruct any agent: Read ~/.bashrc
- Agent calls Read tool with filePath: "~/.bashrc"
- Tool prepends cwd, produces /project/~/... and fails with File not found
Screenshot and/or share link
No response
Operating System
macOS (Darwin)
Terminal
iTerm2
Description
When an agent passes a path starting with
~(e.g.~/.bashrc) to any file tool, the tilde is treated as a literal directory name rather than expanded to the home directory.Affected tools:
read(filePath),write(filePath),edit(filePath),glob(pattern,path),grep(path).bashworks incidentally (shell expands~).Expected Behavior
Read ~/.bashrcresolves to/Users/username/.bashrc.Actual Behavior
Resolves relative to cwd —
path.resolve()joins the raw~/.bashrcstring with the working directory, producing a path that does not exist.Root Cause
The shared path resolution in
packages/opencode/src/filesystem.tsuses:Node.js
path.resolve()does not expand~— it treats it as a literal directory name. No tilde expansion exists anywhere in the file tool path resolution pipeline.Suggested Fix
Expand
~before passing topath.resolve():Or use
untildify(zero-dependency, 16M+ weekly downloads). Applied to the sharedresolve()function infilesystem.ts, this fixes all file tools in one place (~3 lines).Related
~/in plugin config paths, narrower scope, OPEN~/expansion don't work in instructions configuration #3289 —~/in instructions glob config, FIXEDtool.execute.beforehook arg mutation has no effect #31680 —tool.execute.beforearg mutation broken, blocks plugin workaroundPlugins
none
OpenCode version
1.17.4
Steps to reproduce
Screenshot and/or share link
No response
Operating System
macOS (Darwin)
Terminal
iTerm2