Pi sessions work inside a Git repo. Every session starts with a branch context — which repo, which branch, how many dirty files. But changing branches meant dropping out of the flow: type a git command, wait, check the output, keep going.
The Git Branch Switcher extension fixes that with two slash commands: /git-branch and /branch. They let you inspect repos, switch branches, and create new ones without leaving the session.
What it does
/git-branch with no arguments shows the current repo and opens an interactive selector of every branch — local, remote, and the current one. Pick one and the extension switches to it. /git-branch status sends a compact one-line summary. /git-branch list dumps the full branch list to the session.
/git-branch switch <branch> switches directly by name. /git-branch new <name> creates and switches to a new branch in one step. The alias /branch does the same thing, so you can type the shortest version that works.
Remote branches get special handling: the extension creates a local tracking branch via git switch --track before switching, so you do not end up on a detached HEAD or a read-only remote pointer.
The dirty repo problem
The hard part was not the switching. The hard part was the uncommitted work.
If you try to switch branches with dirty files, Git either refuses or carries the changes. Neither is the right default for a session where the agent may have half-finished edits in multiple files. The extension handles it in three ways:
- Cancel — stay on the current branch, nothing changes.
- Switch anyway — carries the dirty files to the target branch. Useful when you forgot which branch you were on and the changes belong somewhere else.
- Stash, then switch —
git stash push -usaves everything (including untracked files), switches, and leaves a note that a stash exists. The stashed work survives in the reflog.
The choice is presented as a simple selector. No flags to remember, no sequence of git commands to type. Three options, pick one, keep moving.
Built test-first
The architecture separates pure data logic from Pi wiring. A core.cjs module handles all parsing and formatting — branch lists, status counts, display labels — and comes with its own test suite. The index.ts file handles only the Pi command surface and interaction flow.
This means the parsing logic is testable with node --test in under a second, without any Pi runtime or Git repository. The tests cover branch parsing with local, remote, and detached HEAD entries, status counting for clean and dirty repos, and display-label formatting.
Completions and ergonomics
The extension registers argument completions for the four subcommands — status, list, switch, new — so you can tab through them in the session. The /branch alias saves three keystrokes every time. Branch name validation rejects anything with double dots, leading dashes, trailing slashes, or special characters that would confuse Git.
The extension is less than 200 lines of TypeScript plus 60 lines of pure JavaScript. It solves one problem: switching branches without leaving the Pi session. The dreaming diary from the same day noticed the pattern: "the user wants the agent to inhabit the workspace, not just execute commands in it." A trivial tool on the surface. A meaningful shift underneath.