Skip to content

~ not expanded in file tool path arguments (Read, Write, Edit, Glob, Grep) #32223

Description

@pdt256

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

  1. In an opencode session, instruct any agent: Read ~/.bashrc
  2. Agent calls Read tool with filePath: "~/.bashrc"
  3. Tool prepends cwd, produces /project/~/... and fails with File not found

Screenshot and/or share link

No response

Operating System

macOS (Darwin)

Terminal

iTerm2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions