Add git integration to let users start new threads from a specific branch, optionally creating a git worktree for isolated agent work.
- Left click "+ New thread" → immediately creates a thread (current behavior, unchanged)
- Right click "+ New thread" → opens a context menu with git options:
- List of local branches → clicking one creates a thread on that branch (uses project cwd)
- Each branch has a "worktree" sub-option → creates a worktree, then creates thread with worktree as cwd
- When thread has a worktree, the agent session uses the worktree path as its cwd
- If git fails (not a repo), context menu shows "Not a git repository" disabled item
New Zod schemas and types:
gitListBranchesInputSchema—{ cwd: string }gitCreateWorktreeInputSchema—{ cwd: string, branch: string, path?: string }gitRemoveWorktreeInputSchema—{ cwd: string, path: string }gitBranchSchema—{ name: string, current: boolean }- Result types for each
- Add 3 IPC channels:
git:list-branches,git:create-worktree,git:remove-worktree - Add
gitnamespace toNativeApiwithlistBranches,createWorktree,removeWorktree
- Add
export * from "./git"
Add 3 IPC handlers + helper functions:
listGitBranches()— runsgit branch --no-color, parses output into{ name, current }[]createGitWorktree()— runsgit worktree add <path> <branch>, defaults path to../{repo}-worktrees/{branch}removeGitWorktree()— runsgit worktree remove <path>
Reuses existing runTerminalCommand().
Add git namespace with 3 ipcRenderer.invoke calls.
Add to Thread:
branch: string | null
worktreePath: string | null
- Add optional
branch/worktreePathto persisted thread schema (.nullable().optional()for backwards compat) - Add V3 schema, update union
- Update
hydrateThreadto default new fields tonull - Update
toPersistedStateto serialize new fields
- Update persisted state key to v3, keep v2 as legacy fallback
- Keep existing left-click
handleNewThreadunchanged (immediate thread creation) - Add
onContextMenuhandler to "+ New thread" buttons (both global and per-project) - On right-click: fetch branches via
api.git.listBranches, show a custom context menu - Context menu items: branch names, each with a nested option to create with worktree
- Clicking a branch → creates thread with
branchset, title = branch name - Clicking "with worktree" → calls
api.git.createWorktreefirst, then creates thread withworktreePath - Show branch badge on thread list items
- If not a git repo, show "Not a git repository" as disabled menu item
Context menu component: a positioned <div> with position: fixed anchored to the click position, dismissed on click-outside or Escape. Follows the existing dropdown pattern from ChatView's model picker.
- Line 157: use
activeThread.worktreePath ?? activeProject.cwdas session cwd - Show branch/worktree badge in header bar
packages/contracts/src/git.ts(new schemas)packages/contracts/src/ipc.ts+index.ts(wire up channels)apps/desktop/src/main.ts(git command handlers)apps/desktop/src/preload.ts(bridge methods)apps/renderer/src/types.ts(Thread type update)apps/renderer/src/persistenceSchema.ts+store.ts(persistence migration)apps/renderer/src/components/Sidebar.tsx(branch picker UI)apps/renderer/src/components/ChatView.tsx(worktree cwd + badge)
- Not a git repo:
git branchfails → context menu shows "Not a git repository" disabled item - Branch has slashes:
feature/foo→ worktree dir becomesfeature-foo - Worktree exists: git error surfaces to user via inline error message in context menu
- No persistence breakage:
.nullable().optional()fields parse fine with old data
turbo build— confirm contracts/desktop/renderer all compile- Launch app, add a project pointing to a git repo
- Click "+ New thread" → verify branch list loads
- Select a branch, click Start → thread created with branch in title
- Enable worktree checkbox, pick branch, Start → verify worktree directory created on disk
- Send a message in worktree thread → verify agent runs in worktree cwd
- Add a non-git project → verify graceful error, can still create thread