Repository navigation
Description
Description
Summary
When one repository is cloned twice (two independent clones, separate .git directories, identical origin), the second clone cannot be opened in OpenCode Desktop. Selecting it opens the first checkout instead — wrong path, wrong session list, wrong project name. It is a permanent redirect: every new session started from the second clone is rewritten to the first.
The redirect is not caused by the stored worktree (the cause tracked in #50821). On 2.4.3 the client's route→project-root resolver prefers location.info().project.canonical, and the server reports canonical as the first-registered checkout for both clones.
Environment
- opencode version: 2.4.3 (OpenCode Desktop 2.4.3, bundled
opencode-cli2.4.3) - Client: desktop app (Electron), Windows
- Model and provider: Not relevant
- OS: Windows 11 10.0.26100 (win32 x64)
- Terminal: Not applicable (desktop)
- Shell:
C:\Windows\system32\cmd.exe - Install/channel:
latest(app-update.ymlchannellatest; update API reports 2.4.3 as current) - Active plugins: none
Reproduction
-
Clone one repository into two sibling directories, as two plain clones:
git clone git@git.example.com:group/repo.git /path/app-a git clone git@git.example.com:group/repo.git /path/app-b
Both have their own
.git; they are not worktrees of each other and not symlinks.git -C /path/app-b rev-parse --git-common-diris/path/app-b/.git. -
Open
/path/app-ain the desktop app and create one session there. -
Add
/path/app-bthrough the project picker and select it. -
The app shows
/path/app-a: the URL, the project name and the session list all belong toapp-a.
Expected Behavior
After selecting /path/app-b, the app stays on /path/app-b. A new session runs there, and the project row shows the checkout that was picked.
Actual Behavior
The picked directory is discarded during route resolution and replaced by the other checkout.
Server: two clones are one project, and canonical is the first checkout
GET /api/location?location[directory]=/path/app-b
{"directory":"/path/app-b",
"project":{"id":"<shared id>",
"directory":"/path/app-b",
"canonical":"/path/app-a"}}
directory is app-b, canonical is app-a. The id is derived from the remote, so both clones always share one project row:
// packages/core/src/project.ts (shipped in opencode-cli)
projectID = Hash.fast(`git-remote:${host}/${path}`
.replace(/^\/+/, "").replace(/\.git\/?$/, ""))I confirmed this directly: creating a temp clone whose origin is ssh://u@hostone.example:29418/grp/proj makes /api/location return project.id = 0c01bdd76fce…, which equals sha1("git-remote:hostone.example/grp/proj"). Changing only the host in origin yields a different id. So the shared-project part is by design (#36219), but the canonical that follows from it is what breaks navigation.
Client: project.canonical wins over the directory the user picked
From the shipped renderer (app.asar → out/renderer/assets/main-*.js), the resolver that maps a route to a project root:
function man(e,t,n,r){
let i = t.type===`session` ? e?.data.session.get(r??t.routeSessionId??t.sessionId) : void 0,
a = t.type===`draft` ? t.directory : i?.location.directory ?? n;
if(a) return i && e?.projects.forSession(i)?.worktree
|| e?.data.location.info({directory:a})?.project.canonical // ← taken first
|| e?.projects.forDirectory(a)?.worktree
|| a
}For a new draft (t.type === "draft") there is no session, so the expression evaluates location.info(a).project.canonical and returns app-a. The tab's remembered target is then rewritten:
let a = e.route(),
o = man(t.serverCtx(i.server), i, n.info[wU(i)]?.directory,
a.type===`session` ? a.sessionId : void 0);
F(() => n.rememberTarget(i.server, o)); // target := canonicalThat is the redirect: draft.directory was app-b, the stored target becomes app-a.
Note projects.forDirectory(a) already resolves app-b correctly — the canonical branch simply runs before it, so the correct value is never reached.
Stale project rows make it look like the project "jumps by itself"
On this machine GET /api/project returns several rows for the same two directories, left over from earlier identity resolutions:
{"id":"<A>","canonical":"/path/app-b","vcs":"git"}
{"id":"<B>","canonical":"/path/app-b"}
{"id":"<C>","canonical":"/path/app-a","vcs":"git"} ← current shared project
{"id":"<D>","canonical":"/path/app-a","vcs":"git"}
{"id":"<E>","canonical":"/path/app-a"}
Rows A/B are the sidebar entries labelled app-b. Selecting one is not a no-op: the client resolves the directory again, gets the shared project C, and man() rewrites the target to app-a. So the sidebar lists a project that can never be opened.
Those rows are never cleaned up. Project.sweep only removes a project whose stored canonical directory no longer exists on disk:
// Project.sweep
let se = (J) => d.exists(J).pipe(qe(() => !0));
yield* W(F, u(function*(J){
if (yield* se(J.canonical)) return; // directory exists → keep the row forever
...A row whose resolved identity changed (but whose directory still exists) is kept indefinitely, which is why this state persists across restarts and re-opening the folder.
Additional Context
Why this is not one of the existing reports
- Opening a second checkout of the same repository redirects to the stored worktree #50821 — closed as completed, with "if you still see this on the latest OpenCode, please open a new issue". That issue's redirect came from the stored worktree (
projectRoot()/navigateToProject()/rootFor()mapping ontoproject.worktree). Here the redirect comes fromproject.canonicalreplacing the picked directory during route resolution, withprojects.forDirectory()available and correct. - desktop: new-session project chip never reflects sibling directories of the same git repo #55351 — new-session project chip label and checkmark stay on the canonical row. There
sandboxesis non-empty and the bug isfind(e => e.worktree === dir || e.sandboxes?.some(...))in the chip. Heresandboxesis[]for every row and the redirect happens during navigation, before any chip is rendered. - desktop v2: new session in a git worktree (sandbox) project binds to the project canonical (main worktree) directory instead of the selected worktree #51992 — new sessions in a worktree/sandbox project bind to canonical. No worktree or sandbox is involved here; both directories are separate clones.
- Desktop: two clones of same repo permanently show wrong project name/path - restart does not fix (identity from git remote) #44101 / Desktop app merges separate directories of the same Git repo into one project #29869 / Desktop app redirects to wrong project when multiple directories share the same git remote #35714 — same root cause family. They were closed against the v1→v2 launch fix (fix(app): keep new local sessions in the selected directory #46713), but the canonical substitution is still present in the 2.4.3 renderer.
Suggested fix
- In
man()(and any other place that resolves a project root), treat the picked directory as authoritative when it is a directory the project already knows about — i.e. tryprojects.forDirectory(a)?.worktree(or the registered-directory lookup) beforelocation.info(a).project.canonical, or simply returnawhenaequals a registered directory of the resolved project. The server already exposes those directories viaGET /api/worktree?projectID=…. - In
Project.sweep, also drop or merge project rows whose own id no longer matches the idProject.resolveproduces for theircanonicaldirectory, so stale rows stop appearing in the picker.
Workaround (not a fix, but it unblocks the workflow): give the second clone an origin that maps to the same server under a different hostname, for example an SSH alias, so it resolves to its own project id:
Host git-alias.example.com
HostName git.example.com
Port 29418
User <user>
then git -C /path/app-b remote set-url origin ssh://<user>@git-alias.example.com:29418/group/repo and remove the stale project rows for app-b from the database while the service is stopped.
Frequency: 100% reproducible for any repository with two or more registered clones. Confirmed on 2.4.3 with three independently created clones in %TEMP%.
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot
No response
Operating System
No response
Terminal
No response
Activity
opencodejr commentedon Nov 30, 2026
Thanks for the detailed report. I could reproduce the redirect on 2.4.3, and it still happens on the latest
dev(8e9826e).What I did (Linux, using the web UI that
opencode serveprovides, which is the same front end as the desktop app):origin,app-aandapp-b, and startedopencode servefromapp-a.app-a, then Add project →app-b, then New session.What happened: after
app-bwas picked, the Projects list still showed onlyapp-a, and the session search read "Search sessions in app-a". The new-session draft's project chip and directory wereapp-a//tmp/opencode/clones/app-a. The screenshots below show this on 2.4.3 and ondev, and the script below reproduces it.One difference from your analysis: here,
GET /api/locationforapp-breturned"canonical":"/tmp/opencode/clones/app-b"on both versions. Only/api/projectlistsapp-aas canonical. So in a fresh setup the redirect does not seem to come fromlocation.info().project.canonical. It looks more like the Home selection path in #64644, which open PR #64672 addresses. On your machine, with the stale project rows you describe, thecanonicalpath may still play a part. I could not recreate those rows here, or test the Windows desktop app.Related:
Reproduction script (repro.mjs)
Run it:
bun repro.mjs