Registry Mirror
Skip to content

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Folds git worktrees into their main repository's Inbox project, the "separate small change" in the approval record .product/approved/inbox-project-menu/approval.md (DESIGN.md §5).

The problem

Each linked git worktree is its own --show-toplevel. That includes Claude Code's <repo>/.claude/worktrees/agent-…. So every subagent worktree became its own Inbox project, and the sidebar filled with rows like agent-aa0c12ba3edf0ee3f.

What changes

New messages from a linked worktree now land in the main repository's project.

One module decides where a path files: packages/server/inbox-project-root.ts. It has one cache (createInboxProjectRoots), and three places share it, so they always agree:

  • sends (resolveProject);
  • New message's live sessions;
  • the message-image route.

Resolution rules

  1. The folder. The path is taken by its realpath. If it is not an absolute path to an existing folder, the answer is validation_error, as before.
  2. One git call: git rev-parse --show-toplevel --git-dir --git-common-dir in that folder. If git refuses (not a work tree), the folder is the project, as before.
  3. Is it a linked worktree? This uses git's own layout: the git dir is <common dir>/worktrees/<id> (compared as realpaths). If it is not, the toplevel is the project, as before.
  4. Find the main worktree of the common dir, in this order:
    • <repo>/.git gives <repo>.
    • Otherwise, if rev-parse --is-bare-repository says the common dir is bare, the project is the bare repository itself. When it is named .bare or .git (a bare repo inside a container folder), the project is the folder that holds it.
    • Otherwise, the work tree git records for the common dir (core.worktree).
  5. Verify the candidate. git, run from the candidate, must name the candidate as its toplevel and must name the same common dir. If it does not, the worktree keeps its own toplevel.

Edge cases

Case Handling
Submodule Its git dir is its own common dir, so it is not a linked worktree and stays its own project. A linked worktree of the submodule's own repository folds into the submodule checkout, through its core.worktree. A superproject worktree folds into the superproject.
Bare repo with worktrees Folds into repo.git, or into the container folder for the repo/.bare and repo/.git layouts.
Main repo moved or deleted The worktree's .git link is dangling, so git cannot open the worktree. The folder (the worktree's toplevel) is the project, which is the behavior before this change. After git worktree repair, the worktree folds into the moved repo. If the main checkout was replaced, verification fails and the worktree keeps its toplevel.
--separate-git-dir Nothing in that git dir names its work tree, so nothing is guessed. The worktree keeps its toplevel.
Non-git folder, no git installed The folder, as before.
Symlinks Every path on both sides is a realpath: the worktree reached through a link, a worktree made through a symlinked spelling of the main repo, and macOS /tmp.
Old git (< 2.5, no --git-common-dir) rev-parse echoes the flag back. A line that starts with - is not a path, so the toplevel is the project.
Windows Only node:path (resolve, join, dirname, basename) and realpathSync are used, with no separator strings. git's C:/… output resolves normally. Not run on Windows here.
git hangs Each call is bounded at 3 s, with its process group killed and no prompts (interaction: "forbid", like inbox-repos.ts). An answer git could not give is used once and never cached.

Caching (git off hot paths)

  • Answers are cached per folder realpath, up to 512 folders, oldest out first.
  • An answer is fresh for 60 s. After that it is still returned at once while a background refresh runs. Only the first sight of a folder waits on git.
  • Two calls for the same folder at the same moment share one git run.
  • The session tracker's own cache, which kept an answer forever, is removed in favor of this one.
  • A linked worktree costs 2 git calls once. Unusual layouts cost 3 or 4.

Paths relative to the worktree

  • base_path. A message keeps the folder it was sent from as its base_path, even when that folder is outside the project's root (sendBasePath, through a new optional projectRootOf on the MCP context). Relative image refs and the window's attachment links therefore start where the agent works. Claude Code worktrees are inside the repo, so they already got a base_path before this change.
  • Image route. The route accepts images in the project root, or in the linked worktree the message came from. The worktree is checked again at serve time through the cache: the folder must still fold into this project. The route never trusts the stored record alone, so a stale or forged base_path gains nothing.
  • Attachments. These were already recorded by absolute realpath, relative to project_path, and they are unchanged. A test checks it.

Existing data and routing determinism

  • Nothing is rewritten, because the store is append-only.
  • Old worktree-keyed projects keep their threads. A reply_to into one of them stays there. Those projects hide once they are archived (the project-menu change).
  • Thread routing (sessionThreads and namedThreads, rebuilt by indexRoot) is keyed by project_id. That field is recorded on each message line, and a replay never resolves a path. So an older store routes exactly as before. The new test checks this by reopening a store that holds both kinds of project and routing into each one.

Known transitional effects (narrow):

  • A session that wrote into an old worktree project starts a new default thread in the main project with its next plain send.
  • read_thread and wait_for_reply called with a worktree project_path now list the main project.
  • An idempotent retry that spans the upgrade lands in the main project, because keys are per project.

Tests

  • packages/server/inbox-project-root.test.ts (18 tests) uses real git repos in temp folders. It covers:
    • a plain folder, a subfolder, a sibling worktree and a folder deep inside it, and a Claude Code agent worktree;
    • symlinks on both sides;
    • submodules (separate), the submodule's own worktrees, and a superproject worktree;
    • a bare repo.git and the .bare container;
    • a moved main repo, before and after git worktree repair;
    • a deleted main repo, and --separate-git-dir;
    • validation;
    • old git and no git, through a scripted runner;
    • the cache: one call per folder, stale-while-revalidate, unsettled answers not cached, the size limit.
  • packages/server/inbox-worktree-projects.test.ts (5 tests) runs a real Inbox, the MCP SDK client and real git worktrees. It covers:
    • a send from the worktree lands in the main project, with base_path;
    • images relative to the worktree serve, an escape is 403, and after git worktree remove the image is 404;
    • relative attachments;
    • New message's live sessions;
    • a pre-fold store replays and routes unchanged.
  • bun test packages/server/inbox packages/shared/inbox: 570 pass, 0 fail. This run includes the store property tests (store.test.ts, the generated-sequence and routing-determinism properties).
  • tests/never-touch-the-real-inbox.test.ts, apps/hook/server/inbox-cli.test.ts and apps/hook/hooks/mod/inbox.test.ts: 48 pass.
  • tsc passes for the server, shared and hook-server projects.

Docs

  • CLAUDE.md (AGENTS.md): the Inbox Store's project paragraph, the New message live-session rule, and the message-image rule.
  • The marketing Inbox reference: Projects.

backnotprop and others added 2 commits October 14, 2026 16:07
A message sent from a linked git worktree (git worktree add, including
Claude Code's .claude/worktrees/agent-...) now lands in the main
repository's project instead of a project of its own. One module,
packages/server/inbox-project-root.ts, decides where a path files, with
one cache shared by sends, New message's live sessions and the
message-image route.

The message keeps the worktree folder as its base_path, so relative
images and attachment links resolve where the agent works; the image
route re-checks that folder at serve time. Existing worktree projects
are never rewritten; routing reads only recorded project ids, so a
replay routes as before.

Co-Authored-By: Claude <noreply@anthropic.com>
- wait_for_reply and read_thread's list cover the project an older Inbox
  kept for the agent's worktree (threadReadScope), so an agent that asked
  from a worktree before the upgrade still finds the person's reply.
- A git that ran past its time limit never makes a project: the nearest
  existing project holding the folder, else project_unresolved (try again).
- Project-root gits clear GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE and
  GIT_COMMON_DIR; no git installed is an answer, not a retry.
- AGENTS.md: the upgrade's effect on reads and new projects.

Co-Authored-By: Claude <noreply@anthropic.com>
@backnotprop

Copy link
Copy Markdown
Owner Author

Review fixes in b8b5c97 (one new commit, no force-push):

  1. Lost reply after the upgrade. read_thread's list and wait_for_reply without ids now read through threadReadScope. It covers the resolved project plus the project an older Inbox kept for that same worktree (store.projectByRoot(<worktree toplevel>)).
    • I chose this over scoping by session alone. Session-only would change what a session sees when it passes another repository's project_path, and it does nothing for asked_by: "anyone".
    • The legacy project joins only for paths inside that worktree, so a read from the main checkout is unchanged.
    • Test: the reviewer's repro. An old worktree-keyed project holds a question and the person's reply. wait_for_reply {project_path: worktree, agent_session} returns the reply, and read_thread lists the thread.
  2. A guess after a timeout becoming a permanent project.
    • InboxProjectRoot.settled now reaches resolveProject. When it is unsettled, the send uses an existing project at that root, else the nearest project whose root holds the folder. Otherwise it fails with project_unresolved ("…git did not answer in time. Nothing was sent or saved; try the same call again."), or 503 on a window route.
    • Every MCP tool returns this as an isError result. The shim, the mod (deny) and the Pi/OpenCode connections pass the text through to the agent unchanged.
    • A missing git binary (ENOENT) counts as an answer (the folder is the project). Without that, machines without git could never get a new project.
    • Tests:
      • a fake git on PATH that sleeps, killed by the real runner at 200 ms;
      • an empty PATH;
      • through the server's new projectRootGit seam: refused with nothing written, the same idempotent retry landing once, a subfolder of a known project landing in it.
  3. Git environment. The runner now spawns rev-parse itself, with GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE and GIT_COMMON_DIR cleared and GIT_TERMINAL_PROMPT=0. A test exports all four pointing at another repository.
  4. AGENTS.md (CLAUDE.md). It now covers the effect on read_thread/wait_for_reply and the new-project behaviour after the upgrade.

bun test packages/server/inbox packages/shared/inbox tests/never-touch-the-real-inbox.test.ts: 595 pass, 0 fail. bun run typecheck passes.

The fallback after a git timeout took the nearest existing project
holding the folder, which could be a folder project at ~: a new worktree
under it was filed there for good. It now accepts a holder only when its
root is a repository (.git exists, read from disk without git), and
refuses with project_unresolved otherwise.

Also clear GIT_CONFIG_PARAMETERS, GIT_CONFIG_COUNT and the
GIT_CONFIG_KEY_<n> / GIT_CONFIG_VALUE_<n> variables for project-root gits.

Co-Authored-By: Claude <noreply@anthropic.com>
@backnotprop
backnotprop merged commit 157ec1a into main Oct 14, 2026
32 checks passed
@backnotprop
backnotprop deleted the inbox-worktree-projects branch October 14, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant