Skip to content

Switch sessions between git worktrees from the top bar - #80

Merged
m4rocks merged 8 commits into
mainfrom
worktree-sessions
Nov 1, 2026
Merged

m4rocks merged 8 commits into
mainfrom
worktree-sessions

Conversation

@m4rocks

@m4rocks m4rocks commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Summary

A session switches between the git worktrees of its repository the way it switches branches. New sessions start in the main checkout.

top-bar worktree menu / branch menu row / "New worktree…" dialog
└─ switch_shown                      skeleton "Switching to <worktree>…" appears on the click
   └─ inspect (background)           idle? uncommitted files? transcript?
      └─ uncommitted files → ask first
         └─ prepare (background)     git worktree add, if new
         │                           null worktree-state line, if Claude Code recorded a worktree
         └─ move_into                record folder = target
                                     relaunch: the new view replaces the old one, which ends its process
                                     shell restarts there, open files follow
  • app/switch.rs is new: the switch. app/worktrees.rs is new: the menu, the dialog and removal. git/worktree.rs is new: names, folders, add, remove, .gitignore.
  • claude::worktree_recorded and clear_recorded_worktree append the line Claude Code's ExitWorktree writes. Only a session that claude --worktree put in a worktree needs it.
  • Workspace::start gives a new terminal view the grid of the view it replaces, or of the one shown. Before, its first frame was drawn on a 120x32 grid.
  • The hand-off skeleton takes its message from the caller.
  • Worktree rows have an x that removes the worktree, and its branch once merged. The branch menu deletes local branches and lists branches held by other worktrees.
  • A wheel notch scrolls the terminal by 0.8 instead of 1.6.

Evidence

The headless test switching_between_worktrees checks at every step of a switch that the session stays shown and running behind its skeleton, and that a restarted terminal starts on the pane's grid. Before the fixes:

mid-switch the session is not running with its skeleton
assertion `left == right` failed: the new terminal starts on another grid
  left: Some((120, 32))

After:

cargo test                                          276 passed; 0 failed; 18 ignored
cargo test switching_between_worktrees -- --ignored 1 passed
cargo test removing_a_worktree -- --ignored         1 passed

A scratch repo was used with the real claude -p. claude --resume <id>, run in a fresh git worktree add folder and then in the main checkout, kept the same session id and transcript file, and wrote no worktree-state line.

Not checked in the app:

  • whether a new worktree folder shows Claude's trust prompt
  • whether the history appears after an interactive switch
  • whether a session from claude --worktree lands in main when switched back. The line is appended while its idle process still runs.

Risk

Easy to undo: this branch is one commit. The worktree folders and branches it makes stay on disk and in git until removed.

What could break:

  • The transcript append is Claudiu's first write into Claude Code's data that isn't a setting. README says so.
  • "Main" as a base runs git fetch origin, so creating a worktree from main fails offline.
  • Removing a worktree deletes its branch once merged. A name that only an existing branch has is refused, so that is always a branch Claudiu made, or one Claude Code made under the earlier design.

Refs #79

A session moves into another worktree of its repository, or back to the main checkout, the way it switches branches. The worktree button in the top bar lists the working trees, and picking one ends the session's process and resumes the same conversation there with `claude --resume`. "New worktree…" makes one with `git worktree add` in `.claude/worktrees/<name>` on a new branch of that name, started from origin's default branch or the current commit. A name that only an existing branch has is refused. New sessions always start in the main checkout.

- Before a session moves, Claudiu checks that it is idle and asks when uncommitted files stay behind. The shell restarts in the new folder, and open files follow when the new folder has them.
- A session that `claude --worktree` put in a worktree has that worktree recorded in its transcript, and Claude Code restores it over the launch folder. Claudiu appends the null `worktree-state` line that Claude Code's ExitWorktree writes. It is the only write Claudiu makes to a transcript.
- The hand-off skeleton takes its message from the caller and says "Switching to <worktree>…". The old view stays up behind it while the target is readied, and the new view replaces it in the same update, so the sidebar never shows the session as ended and the pane is never empty.
- A new terminal view starts on the grid of the view it replaces, or of the one shown. Its first frame is drawn before layout, so on the default 120x32 grid the skeleton's prompt jumped to the middle of the pane for a frame.
- Worktree rows have an x that removes the worktree, and its branch once merged. Ending the last session in a worktree offers to remove it. The branch menu has a title, an x that deletes a local branch after counting the commits it would lose, and rows for branches another worktree holds, which switch the session there.
- A wheel notch scrolls the terminal by 0.8 of the system's notch instead of the panels' 1.6.

Refs #79
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
claudiu Ready Ready Preview Nov 1, 2026 10:34pm UTC

New worktrees go to <data dir>/worktrees/<repo>-<hash>/<name> instead of
<repo>/.claude/worktrees, so git status never lists them and the
.gitignore offer is gone. Worktrees already in .claude/worktrees keep
working as session folders but are no longer removable from Claudiu.

Settings has a Worktrees page listing the folders by repository, each
with Show in file manager and Remove. Remove asks inside the page. A
folder whose repository is gone can be deleted after a confirmation.

Refs #79
…rktree

Covers tabs moving with the session (and staying when edited or missing),
the file tree's root, the replaced shell, the skeleton's message, and
cancelling the uncommitted-files question.
A running session's row now shows the project and age, the title with
its status dot, and the branch of the session's own working tree. Recent
and older rows are unchanged.
The path hint was flex_none, so a long path took the whole row and
squeezed the project name to nothing. Menu items now take a `detail`
that renders on a second line, and the new-session menu passes the
path there.
On a running row the close button slides in from the right on hover and
pushes the age to the left, and slides back out when the pointer leaves.
The row is 60 px tall with explicit line heights, which fixes the
uneven padding above and below its three lines.

The status dot is now a Lucide circle: a rotating circle-dot-dashed
while Claude works, circle-small when idle, circle-check when it
finished while unwatched, and circle-question-mark when Claude Code is
waiting for the user. A change of state turns, shrinks and fades the old
icon out while the new one does the reverse.

The waiting state comes from the "waiting" status in Claude Code's
session registry, so a permission prompt shows it as well as a question.
The not-running ring is unchanged.
Show running sessions on three lines, and fix the new-session menu for long paths
# Conflicts:
#	README.md
#	src/app/headless.rs
#	src/app/mod.rs
@m4rocks
m4rocks merged commit f8e6279 into main Nov 1, 2026
5 checks passed
@m4rocks m4rocks mentioned this pull request Nov 1, 2026
42 tasks done
@m4rocks
m4rocks deleted the worktree-sessions branch November 2, 2026 13:47

This branch was successfully deployed

1 active deployment
Preview — 2d31f0f0 Deployed Nov 1, 2026 by vercel[bot]
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