anomalyco / anomalyco/opencode
Review panel diffs the session's original directory, not the worktree the agent is working in
@Hona is already working on this.
Since Sep 8, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
What happened
I opened a project at its main checkout (~/project/) and asked the agent to work in a linked git worktree (~/project-feature/). The agent correctly created and edited files inside the worktree.
However, the review panel (the "changes" pane) shows the working-tree changes for ~/project/ — the directory I originally opened — instead of ~/project-feature/ where the work actually happened.
What I expected
The review panel should surface the changes the agent actually made. When the agent does its work in a worktree/sandbox, the panel should show that directory's diff (or the session's own per-turn diff), not the diff of the directory that happened to be opened at session start.
Root cause (from a code read)
The review panel is scoped to the session's directory, which is fixed at creation and never tracks where the agent is actually working:
- The web/app panel fetches
GET /vcs/diff?directory=<sdk().directory>&mode=git.sdk().directorycomes from the session record (packages/app/src/pages/session.tsx). - On the server,
Session.Info.directoryis set once fromctx.directoryat creation and never updated (packages/opencode/src/session/session.ts,create/fork). - When the agent works in a worktree, it does so transiently via the tool's
workdirparam (packages/opencode/src/tool/shell.ts~L612:params.workdir ? resolvePath(params.workdir, instanceCtx.directory, shell) : instanceCtx.directory). That working directory is never persisted back to the session, so nothing downstream knows the work moved. - The "turn" mode has the same blind spot:
summary.diffsis computed from snapshots, and the snapshot service is scoped toctx.directory/ctx.worktreeof the session's instance (packages/opencode/src/snapshot/index.ts~L68-75). So it also captures main, not the worktree.
In short: every diff source (/vcs/diff in git mode, and the snapshot-backed turn mode) is keyed off the directory the session was opened in, not the directory the agent is editing in.
Suggested directions
Any of these would resolve it, in increasing scope:
- Make the review panel auto-switch to (or default to) the turn mode when the session's edits land outside
sdk().directory— if turn mode can be made worktree-aware. - Track the session's effective working directory / active worktree (mutable on the session, or a first-class worktree-session concept) and scope
/vcs/diff, the snapshot, and the review panel to it. - When a worktree is created for a session, treat that worktree as the session's directory for review/diff purposes.
Environment
- opencode
devbranch (commitecbc6ccac8) - Web review panel (also affects desktop, which shares
ReviewPanelV2) - OS: Linux
- Setup: main git checkout with a linked worktree created via
git worktree add
OpenCode version
opencode dev branch (commit ecbc6ccac8)
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.