Overview
The Worktrees API provides functionality for creating and managing Git worktrees - isolated working directories that share the same repository history but allow working on different branches simultaneously.Data Structures
Worktree
Unique identifier (UUID v4)
Foreign key to the parent project
Random workspace name (e.g., “fuzzy-tiger”)
Absolute path to worktree (defaults to ~/jean/PROJECT_NAME/WORKTREE_NAME)
Git branch name (same as workspace name)
Unix timestamp when worktree was created
Type of session (worktree = git worktree, base = base directory)
Display order within project (lower = higher in list)
GitHub PR number (if a PR has been created)
GitHub PR URL (if a PR has been created)
GitHub issue number (if created from an issue)
User-assigned label with color
Unix timestamp when worktree was archived (null = not archived)
Unix timestamp when worktree was last opened/viewed
Cached Status Fields
Worktrees maintain cached Git and GitHub status for performance:PR status: “draft” | “open” | “review” | “merged” | “closed”
CI check status: “success” | “failure” | “pending” | “error”
Commits behind base branch
Commits ahead of base branch
Lines added in working directory
Lines removed in working directory
Lines added vs base branch
Lines removed vs base branch
Commits not yet pushed to origin
Unix timestamp when status was last checked
Commands
List Worktrees
Retrieve all worktrees for a project.ID of the project
Get Worktree
Retrieve a specific worktree by ID.ID of the worktree
Create Worktree
Create a new Git worktree.ID of the project
Branch to create worktree from (defaults to project’s default_branch)
Custom worktree name (defaults to random name like “fuzzy-tiger”)
GitHub issue context
GitHub PR context
Delete Worktree
Delete a worktree (moves to archive).ID of the worktree to delete
Archive Worktree
Archive a worktree without deleting files.ID of the worktree to archive
Unarchive Worktree
Restore an archived worktree.ID of the worktree to restore
Rename Worktree
Rename a worktree and its branch.ID of the worktree
New worktree name
Update Worktree Label
Set or clear a worktree’s label.ID of the worktree
Label object or null to clear
Reorder Worktrees
Reorder worktrees within a project.ID of the project
Array of worktree IDs in the desired order
Git Operations
Fetch Worktrees Status
Update cached Git/GitHub status for all worktrees in a project.ID of the project
Has Uncommitted Changes
Check if a worktree has uncommitted changes.ID of the worktree
Get Git Diff
Get the diff for a worktree.Absolute path to the worktree
Type of diff: “working” | “staged” | “branch”
Base branch for branch diff
Git Pull
Pull changes from remote.Absolute path to the worktree
Branch to pull from
Remote name (defaults to “origin”)
Git Push
Push changes to remote.Absolute path to the worktree
PR number (for updating PR)
Remote name (defaults to “origin”)
Commit Changes
Create a Git commit.ID of the worktree
Commit message
Stage all changes before committing
Pull Request Operations
Save Worktree PR
Associate a PR with a worktree.ID of the worktree
GitHub PR number
GitHub PR URL
Clear Worktree PR
Remove PR association from a worktree.ID of the worktree
Open Pull Request
Create a GitHub PR for a worktree.ID of the worktree
PR title (auto-generated if omitted)
PR description (auto-generated if omitted)
Create as draft PR
Events
worktree:creating
Emitted when worktree creation starts (background operation).worktree:created
Emitted when worktree creation completes successfully.worktree:create_error
Emitted when worktree creation fails.worktree:status_updated
Emitted when cached Git/GitHub status is updated.Error Codes
| Error | Description |
|---|---|
Worktree not found: {id} | The specified worktree ID does not exist |
Worktree name already exists: {name} | A worktree with this name already exists in the project |
Worktree path already exists: {path} | The target path is already in use |
Branch already exists: {branch} | The branch name is already in use |
No uncommitted changes to commit | Cannot commit with no staged or unstaged changes |
Failed to create worktree: {reason} | Git worktree creation failed |
Next Steps
Sessions API
Manage chat sessions within worktrees
Chat API
Send messages and interact with AI