Repository navigation
Description
What happens
/init and /review substitute their ${path} placeholder with project.directory (the git/hg worktree root, found by walking up to the nearest .git/.hg), not with the session's location.directory.
When a session is created with a location.directory that lives in a subdirectory of a larger git repository, the commands therefore target the repository root instead of the directory the session is working in. The same root is reported as Workspace root folder: in the environment prompt.
Version
opencode v2.0.21 (also reproduced conceptually on the v2 server API).
Reproduction
- Create a git repo, e.g.
/repowith/repo/subinside it. - Create a session whose location directory is
/repo/sub(v2 server:POST /api/sessionwithbody.location.directory = "/repo/sub"). - Run
/init.
The injected prompt contains:
If
AGENTS.mdalready exists at/repo, improve it in place rather than rewriting blindly.
and the agent edits /repo/AGENTS.md instead of /repo/sub/AGENTS.md.
Evidence from the v2.0.21 binary
The opencode.command plugin registers the built-in command with the project directory:
c.add({ name: "init", description: "guided AGENTS.md setup",
execute: (l) => e.session.prompt({ ...l.prompt, sessionID: l.sessionID,
text: p4(initTemplate.replace("${path}", a.project.directory), l.prompt.text), ... }) })and Project.resolve resolves the root by walking up:
let l = yield* e.up({ targets: [".git", ".hg"], start: f, mode: "first" })
...
return yield* x({ ..., directory: m.worktree, canonical: ue, vcs: { type: "git", ... } })The environment prompt also distinguishes them:
Working directory: ${f.directory} // the session location
Workspace root folder: ${f.project.directory} // the git worktree root
Expected
Project-scoped commands (/init, /review) and AGENTS.md discovery should honor the session's location.directory, or at least not escape it upward into an unrelated ancestor repository. A session explicitly scoped to /repo/sub should not create or modify /repo/AGENTS.md.
This matters for hosts that embed opencode and place each user project in a subdirectory of their own repository (so the subdirectory is not itself a git root): the embedded agent ends up editing the host's own AGENTS.md and receiving the host's project instructions.
Notes
A workaround on the host side is to make every session directory its own git root (so project.directory stops there) and/or inject a session instruction pinning the directory, but that requires the host to know this behavior. It would be great if location.directory were authoritative for project-scoped commands.
Activity
github-actions commentedon Oct 2, 2026
This issue might be a duplicate of existing issues. Please check:
r266-tech commentedon Oct 2, 2026
The current
v2command code still useslocation.project.directory. Its existingpackages/core/test/plugin/command.test.tsalready sets the location to/repo/packages/appand the project to/repo, then explicitly expects both built-ins to interpolate/repo. I ran that test: 1 pass. Both source/test blobs match currentv2(eb1a9ea4). This captures prompt construction, without invoking a model or editing any AGENTS.md.@rekram1-node, should
/inittarget the session directory while/reviewkeeps repository-wide git semantics? The current init template says “this repository”, and the test encodes that scope, so changing both commands together would also change existing behavior. Instruction discovery is a separate path and is not covered by this test. AI-assisted investigation.opencodejr commentedon Oct 27, 2026
Thanks for the detailed write-up, @ToguDV!
This is currently by design.
/initand/reviewfill in${path}with the project's VCS root (location.project.directory) on purpose, and AGENTS.md handling is also tied to the project root, so a session opened in a subdirectory still treats the whole repository as the project. That's why the agent goes to/repo/AGENTS.md.So I've filed this as a feature request: let the session's
location.directorydecide where project-scoped commands like/initand/review(and AGENTS.md discovery) apply, or at least stop them from reaching up into an unrelated ancestor repository. The embedding case you describe is a clear reason for it, and maintainers will consider it.Until then, your workarounds (making each session directory its own git root, or pinning the directory in a session instruction) are the reliable options. Another option is a custom command with your own AGENTS.md prompt that names the subdirectory explicitly.
Related issues:
fix(core): build /init prompt with the session directory