Repository navigation
Conversation
…rktrees are recoverable (stablyai#10324) Worktrees under <repo>/.claude/worktrees are classified agent-scratch and shouldShowWorktree hides them before the visibility branch, so the "Show non-Orca worktrees" toggle cannot reveal them by design (stablyai#9388). The only reveal path is an explicit import into importedExternalWorktreePaths, but nothing ever offered scratch for import, leaving them unreachable. Add isImportableExternalWorktree (excludes only orca-managed and the selected checkout) and getHiddenImportableExternalWorktrees, and use them in getNewExternalWorktreeInboxWorktrees so scratch reaches the inbox. Let scratch bypass both the visibility-mode gate and the first-run prompt gate: neither governs scratch, and the prompt flag is only written by the import card, which never renders for a scratch-only repo. Discovery suppression and the inbox baseline still apply. getHiddenExternalWorktrees, the import card and the visibility dialog are left untouched: the card's only action flips externalWorktreeVisibility, which by design can never reveal scratch.
Greptile SummaryThis PR fixes a bug where agent-scratch worktrees (created by Claude Code under
Confidence Score: 5/5Safe to merge. The change is minimal, well-contained to predicate logic, and the early-return placement correctly ensures discovery suppression still blocks scratch. The change is a focused predicate fix with no filesystem access, IPC, or UI modifications. All pre-existing tests remain green and six new tests pin the fixed behavior against the obvious revert failure mode. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/shared/external-worktree-inbox.ts | Core fix: adds isImportableExternalWorktree / getHiddenImportableExternalWorktrees, and rewires getNewExternalWorktreeInboxWorktrees so scratch bypasses the visibility-mode and first-run-prompt gates while remaining blocked by suppression and the inbox baseline. |
| src/shared/external-worktree-inbox.test.ts | Five new shared-layer tests cover all key behavioral branches for agent-scratch: both visibility modes, pre-prompt-dismissal, suppression/baseline authority, separation from user-facing hidden worktrees. |
| src/renderer/src/components/sidebar/new-external-worktrees-inbox-candidates.test.ts | One new renderer-layer integration test verifies buildNewExternalWorktreesInboxCandidates produces a real candidate for a scratch worktree in show mode. Pre-existing suppression tests are untouched and consistent. |
Reviews (1): Last reviewed commit: "fix(worktrees): make agent-scratch workt..." | Re-trigger Greptile
|
Closing this in favor of a consolidated PR. While building the UI that makes these worktrees recoverable, we found two other open PRs on the same surface:
Rather than land four overlapping changes on the same dialog and the same visibility rule, the work is consolidated into one branch. The replacement PR carries this commit, adds the screen that exposes it, and keeps the best parts of both other PRs: the field name and the rollback shape from #10560, the exception detection from #11275. It also fixes an interaction none of the three handled, where hiding a whole kind left individually shown worktrees visible because an explicit exception outranks the switch. The model is documented in The replacement PR is being opened from cc @AmethystLiang @brennanb2025 — apologies for the churn on the review assignment. The replacement PR supersedes this one and covers everything here plus the recovery UI. |
Keeping a discovered worktree hidden was a one-way door for agent scratch. The inbox baseline suppressed the notification, the repo-wide toggle can never reveal scratch by design (stablyai#9388), and the dialog reported nothing was there, so the worktree became unreachable from the UI. The visibility dialog now owns both kinds of non-Orca worktrees, each with the same anatomy: a repo switch that also covers worktrees created later, and a collapsible per-worktree list to show or hide one at a time. Agent worktrees answer to their own opt-in setting, so the non-Orca toggle still never reveals them; a shared test pins that guarantee. Hiding a whole kind drops that kind's explicit exceptions, otherwise an exception would outrank the switch that was just set, and both switches roll back if the refresh that follows them fails. Both switches also need an authoritative listing, because hiding derives the purge and the decision ledger from it. On a host Orca cannot reach, the dialog says so and offers a retry instead of purging against an empty list. Worktrees a legacy repo shows whatever the setting are left out of a kind's counts, since no switch on this screen can move them. A row counts as an exception when the visibility rule without imports would hide it, not when its path sits in the recorded list, because that list can lag behind reality. Row-level actions reuse the inbox import path so behavior and rollback stay identical, and the recovery list ignores the inbox baseline on purpose: the baseline suppresses a notification, it must not block recovery. The sidebar notices now speak the same vocabulary as the dialog and link straight into it instead of naming a menu. docs/non-orca-worktree-visibility.md writes down the model, the stablyai#9388 guarantee, and the exception rules. Supersedes stablyai#11730 and consolidates the overlapping work in stablyai#10560 (the agent visibility setting, whose field name and rollback shape are kept) and
Summary
Worktrees created by Claude Code under
<repo>/.claude/worktrees/became impossible to reveal from the sidebar. They are classifiedagent-scratch, andshouldShowWorktreehides that ownership before the visibility branch, so the "Show non-Orca worktrees" toggle cannot reveal them. That hide is intentional (#9388): scratch is agent plumbing, and the design is that it is revealed only by an explicit import or by being the selected checkout.The defect is that the explicit-import path was unreachable.
isUserFacingExternalWorktreeexcludedagent-scratch, so scratch was never offered as an import candidate, and the only mechanism that can reveal it (importedExternalWorktreePaths, whichshouldShowWorktreealready honors) could never be populated.This keeps the #9388 policy intact and makes the import path reachable instead:
isImportableExternalWorktree(excludes onlyorca-managedand the selected checkout, so it includesagent-scratch) plusgetHiddenImportableExternalWorktreesgetNewExternalWorktreeInboxWorktreesuses them, and lets scratch through regardless of visibility mode and regardless of the first-run prompt gateexternalWorktreeDiscoverySuppressedAtandexternalWorktreeInboxBaselinePathsstill applyTwo gates had to be bypassed for scratch only, because neither governs it:
'hide', so in a repo set to'show'no import affordance rendered at all.externalWorktreeVisibilityPromptDismissedAtis written in exactly one place,keepImportedWorktreesHiddenCard. That card never renders for a scratch-only repo, so the flag could never become true and the gate would have stranded the import permanently.getHiddenExternalWorktrees, the import card and the visibility dialog are deliberately untouched. The card's only positive action isshowImportedWorktreesCard, which flipsexternalWorktreeVisibility— by design that can never reveal scratch, so routing scratch through the card would render a button that provably does nothing. Its "Keep hidden" action also seeds the inbox baseline from that same selector, so widening it would have baselined scratch out of the inbox on dismissal: a second dead end.Fixes #10324.
Screenshots
No visual change— logic and candidate-builder level only. No JSX, styling or copy touched. The existing inbox row now has candidates to render where it previously always had none.Testing
pnpm lintpnpm typecheckpnpm testpnpm build— blocked locally by an unrelated pre-existing bug, see noteSix new tests covering: scratch offered in both
'show'and'hide'; offered before the first-run prompt is dismissed; still blocked by discovery suppression and by the inbox baseline; not leaking intogetHiddenExternalWorktrees; and the candidate builder producing a real inbox row for a scratch-only repo in'show'. The pre-existing assertions that scratch is not a "visible other", that the card builds no candidate for scratch-only, and thatshouldOfferNewExternalWorktreeInboxis false in'show'all remain green and unmodified.These tests were checked against the obvious failure mode of restating the implementation: reverting only
src/shared/external-worktree-inbox.tstoorigin/mainand re-running them fails 5 of the new cases, so they pin the fixed behavior rather than describing it.Note on how these were run:
pnpm testandpnpm typecheckcould not complete through their package scripts in this environment —ensure-native-runtimecannot rebuild node-pty for Node 24.18.1, andtsccannot writetsbuildinfo. Both were run directly instead (vitest run --config config/vitest.config.ts,tsc --noEmit --composite falseacross all three projects) with equivalent coverage. Allsrc/shared/andsrc/renderer/tests pass; the remaining failures aresrc/main/**integration tests failing on missing native modules, and nothing insrc/main,src/cliorsrc/relaycalls the functions this PR changes.pnpm buildcould not be completed either, for a reason that has nothing to do with this change:build:nativedies before ever reaching this PR's code, becauseconfig/scripts/build-native-for-platform.mjshands a native@pnpm/exebinary to Node. That is pre-existing onmainand is fixed separately in #11738. The other five build steps (typecheck,build:relay,build:cli,build:electron-vite,build:web-from-renderer) were each run individually and all pass, and CI runs the full build regardless. This is explanatory only — this PR does not depend on #11738 and shares no files with it.AI Review Report
Reviewed for correctness, minimality and end-to-end reachability. The main risk checked was whether the fix actually reaches the user or just moves a predicate, so the consumer chain was traced explicitly:
getNewExternalWorktreeInboxWorktrees→buildNewExternalWorktreesInboxCandidates(gates only onfilterRepoIds/isGitRepoKind) →worktree-list-groups.ts:1156,1303→buildNewExternalWorktreesInboxRow→handleImportNewExternalWorktree→importNewExternalWorktreeInboxPaths→importedExternalWorktreePaths→shouldShowWorktree. No separate visibility gate sits in the render path, so widening the selector is sufficient.The review flagged and rejected a broader variant that also widened
getHiddenExternalWorktreesand the import card, for the two dead ends described in Summary; the narrower change was taken instead.Cross-platform (macOS, Linux, Windows): explicitly checked. No new path handling — path comparison flows through the existing
normalizeRuntimePathForComparison, andcreateAgentScratchWorktreePathMatcheralready handles Windows drive roots. No keyboard shortcuts, shortcut labels, shell behavior or Electron platform APIs are touched by this PR.SSH / remote / local: the change is shared-layer predicate logic over already-detected worktrees, with no filesystem, process or network access, so it behaves identically for local, SSH and remote hosts.
Agent / integration / git-provider compatibility: no provider-specific or agent-specific branching added. The scratch path prefixes (
.claude/worktrees,.gsd-workspaces) are pre-existing and untouched.Performance: no new traversal. One extra
ownershipcomparison per already-iterated worktree, inside a selector that was already filtering the same list.UI quality: not applicable — no JSX, styling, tokens or copy are touched, so there is nothing to verify against
docs/STYLEGUIDE.md, light/dark mode or SSH latency. The change only supplies candidates to an inbox row that already exists and already renders.Folder workspaces: unaffected —
buildNewExternalWorktreesInboxCandidatesstill short-circuits onisGitRepoKind.Security Audit
Low risk, no new attack surface. No input handling, command execution, IPC, auth, secrets or dependency changes. Path handling is comparison-only and reuses existing normalization; no path is constructed, resolved or written.
The one security-relevant property reviewed is that this widens what can become visible, so it was verified that visibility still requires an explicit user action: the predicate only makes scratch an import candidate, and revealing it still requires the user to click import, which writes
importedExternalWorktreePaths. Two user opt-outs remain authoritative and are covered by tests —externalWorktreeDiscoverySuppressedAtand the inbox baseline. Nothing becomes visible automatically.No follow-up security work needed.
Notes
No platform-specific behavior in this change.
Behavior change worth calling out explicitly. Agent scratch worktrees are offered to the inbox with no quiescence filter, so a worktree an agent created seconds ago and is still using will surface a row, not only an abandoned one. This also now happens in
'show'mode, where the inbox previously never rendered at all. That is the direct consequence of making the import path reachable — the persistent, orphaned case is exactly what #10324 asks for, and there is no signal available here to distinguish "abandoned" from "in use". The two opt-outs are honest but coarse: "keep hidden" baselines individual paths, which is repetitive against uniquely-named scratch directories, andexternalWorktreeDiscoverySuppressedAtdisables discovery wholesale. If maintainers would rather trade recoverability for quiet, the natural knob is an age or activity threshold on scratch candidates ingetNewExternalWorktreeInboxWorktrees; that is deliberately not in this PR, which fixes reachability only.Reach limitation, pre-existing and not addressed here. The inbox row is only built under
groupBy === 'repo'(worktree-list-groups.ts:1155-1172and:1302-1306). The imported-worktrees card has a pinned-group fallback for other grouping modes (:487-489,:507-515); the inbox row has none. So a user grouping the sidebar by PR status still cannot reach the import affordance, and orphaned scratch stays as unrecoverable for them as before. The default grouping is'repo'(src/renderer/src/store/slices/ui.ts:1991), so this affects a minority of users. It is an inherited limitation of the inbox feature as a whole rather than anything this change introduces, which is why it is flagged rather than fixed here.