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
string
required
Unique identifier (UUID v4)
string
required
Foreign key to the parent project
string
required
Random workspace name (e.g., “fuzzy-tiger”)
string
required
Absolute path to worktree (defaults to ~/jean/PROJECT_NAME/WORKTREE_NAME)
string
required
Git branch name (same as workspace name)
number
required
Unix timestamp when worktree was created
'worktree' | 'base'
default:"worktree"
Type of session (worktree = git worktree, base = base directory)
number
default:0
Display order within project (lower = higher in list)
number | null
GitHub PR number (if a PR has been created)
string | null
GitHub PR URL (if a PR has been created)
number | null
GitHub issue number (if created from an issue)
object | null
User-assigned label with color
number | null
Unix timestamp when worktree was archived (null = not archived)
number | null
Unix timestamp when worktree was last opened/viewed
Cached Status Fields
Worktrees maintain cached Git and GitHub status for performance:string | null
PR status: “draft” | “open” | “review” | “merged” | “closed”
string | null
CI check status: “success” | “failure” | “pending” | “error”
number | null
Commits behind base branch
number | null
Commits ahead of base branch
number | null
Lines added in working directory
number | null
Lines removed in working directory
number | null
Lines added vs base branch
number | null
Lines removed vs base branch
number | null
Commits not yet pushed to origin
number | null
Unix timestamp when status was last checked
Commands
List Worktrees
Retrieve all worktrees for a project.string
required
ID of the project
Get Worktree
Retrieve a specific worktree by ID.string
required
ID of the worktree
Create Worktree
Create a new Git worktree.string
required
ID of the project
string
Branch to create worktree from (defaults to project’s default_branch)
string
Custom worktree name (defaults to random name like “fuzzy-tiger”)
object
GitHub issue context
object
GitHub PR context
Delete Worktree
Delete a worktree (moves to archive).string
required
ID of the worktree to delete
Archive Worktree
Archive a worktree without deleting files.string
required
ID of the worktree to archive
Unarchive Worktree
Restore an archived worktree.string
required
ID of the worktree to restore
Rename Worktree
Rename a worktree and its branch.string
required
ID of the worktree
string
required
New worktree name
Update Worktree Label
Set or clear a worktree’s label.string
required
ID of the worktree
object | null
required
Label object or null to clear
Reorder Worktrees
Reorder worktrees within a project.string
required
ID of the project
string[]
required
Array of worktree IDs in the desired order
Git Operations
Fetch Worktrees Status
Update cached Git/GitHub status for all worktrees in a project.string
required
ID of the project
Has Uncommitted Changes
Check if a worktree has uncommitted changes.string
required
ID of the worktree
Get Git Diff
Get the diff for a worktree.string
required
Absolute path to the worktree
string
required
Type of diff: “working” | “staged” | “branch”
string
Base branch for branch diff
Git Pull
Pull changes from remote.string
required
Absolute path to the worktree
string
required
Branch to pull from
string
Remote name (defaults to “origin”)
Git Push
Push changes to remote.string
required
Absolute path to the worktree
number
PR number (for updating PR)
string
Remote name (defaults to “origin”)
Commit Changes
Create a Git commit.string
required
ID of the worktree
string
required
Commit message
boolean
default:false
Stage all changes before committing
Pull Request Operations
Save Worktree PR
Associate a PR with a worktree.string
required
ID of the worktree
number
required
GitHub PR number
string
required
GitHub PR URL
Clear Worktree PR
Remove PR association from a worktree.string
required
ID of the worktree
Open Pull Request
Create a GitHub PR for a worktree.string
required
ID of the worktree
string
PR title (auto-generated if omitted)
string
PR description (auto-generated if omitted)
boolean
default:false
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
Next Steps
Sessions API
Manage chat sessions within worktrees
Chat API
Send messages and interact with AI