Skip to content

desktop: selecting a second clone of the same repository always redirects to the first checkout #67333

Backlog

Description

@YRLee999

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-cli 2.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.yml channel latest; update API reports 2.4.3 as current)
  • Active plugins: none

Reproduction

  1. 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-dir is /path/app-b/.git.

  2. Open /path/app-a in the desktop app and create one session there.

  3. Add /path/app-b through the project picker and select it.

  4. The app shows /path/app-a: the URL, the project name and the session list all belong to app-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 := canonical

That 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

Suggested fix

  1. 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. try projects.forDirectory(a)?.worktree (or the registered-directory lookup) before location.info(a).project.canonical, or simply return a when a equals a registered directory of the resolved project. The server already exposes those directories via GET /api/worktree?projectID=….
  2. In Project.sweep, also drop or merge project rows whose own id no longer matches the id Project.resolve produces for their canonical directory, 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

  1. added
    area/desktop
    type/bug
    version/v2
    on Nov 30, 2026
  2. opencodejr commented on Nov 30, 2026

    @opencodejr
    Contributor

    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 serve provides, which is the same front end as the desktop app):

    1. Made two plain clones of one repo with the same origin, app-a and app-b, and started opencode serve from app-a.
    2. Add project → app-a, then Add project → app-b, then New session.

    What happened: after app-b was picked, the Projects list still showed only app-a, and the session search read "Search sessions in app-a". The new-session draft's project chip and directory were app-a / /tmp/opencode/clones/app-a. The screenshots below show this on 2.4.3 and on dev, and the script below reproduces it.

    One difference from your analysis: here, GET /api/location for app-b returned "canonical":"/tmp/opencode/clones/app-b" on both versions. Only /api/project lists app-a as canonical. So in a fresh setup the redirect does not seem to come from location.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, the canonical path may still play a part. I could not recreate those rows here, or test the Windows desktop app.

    Related:

    Screenshot

    Screenshot

    Screenshot

    Reproduction script (repro.mjs)
    // Two plain clones of one repo (same origin) at /tmp/opencode/clones/{app-a,app-b};
    // `opencode serve --port 4096 --hostname 127.0.0.1` started from app-a; password in /tmp/opencode/pw.
    import { chromium } from "playwright"
    import fs from "fs"
    const url = process.env.SERVER ?? "http://127.0.0.1:4096"
    const ui = process.env.UI ?? url
    const out = process.env.OUT ?? "/workspace/repro"
    const pw = fs.readFileSync(process.env.PW ?? "/tmp/opencode/pw", "utf8").trim()
    const root = "/tmp/opencode/clones"
    const b = await chromium.launch()
    const ctx = await b.newContext({ viewport: { width: 1400, height: 900 } })
    const p = await ctx.newPage()
    await p.goto(ui); await p.waitForTimeout(5000)
    await p.getByText("Use password").click()
    await p.fill("#server-connect-url", url)
    await p.fill("#server-connect-password", pw)
    await p.getByRole("button", { name: "Connect" }).click()
    await p.waitForTimeout(6000)
    if (ui !== url) { await p.getByText(new URL(url).host, { exact: true }).first().click(); await p.waitForTimeout(2000) }
    await p.screenshot({ path: out + "/0-connected.png" })
    async function add(dir, tag) {
      await p.getByRole("button", { name: "Add project" }).last().click()
      await p.waitForTimeout(800)
      await p.getByPlaceholder(/enter ~\/path/).fill(dir)
      await p.waitForTimeout(800)
      await p.getByRole("button", { name: "Select folder" }).click()
      await p.waitForTimeout(3000)
      await p.screenshot({ path: `${out}/${tag}.png` })
      console.log(tag, "URL:", p.url())
      const body = await p.locator("body").innerText()
      console.log(tag, "mentions app-a:", body.includes("app-a"), "mentions app-b:", body.includes("app-b"))
    }
    await add(`${root}/app-a`, "1-after-add-a")
    await add(`${root}/app-b`, "2-after-add-b")
    // After picking app-b, start a new session and see which directory the draft uses.
    await p.getByRole("button", { name: "New session" }).first().click()
    await p.waitForTimeout(3000)
    await p.screenshot({ path: `${out}/3-new-session-after-b.png` })
    console.log("new session URL:", p.url())
    const body = await p.locator("body").innerText()
    console.log("draft mentions app-a:", body.includes("app-a"), "mentions app-b:", body.includes("app-b"))
    for (const line of body.split("\n")) if (/app-[ab]/.test(line)) console.log("  line:", line)
    await b.close()

    Run it: bun repro.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/desktopplatform/windowsreproducedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions