Skip to main content
praisonai run --worktree runs an agent on a fresh git branch and worktree, then commits, keeps, or discards the result — your working tree is never touched.
That single command provisions a fresh worktree on a new branch, runs the agent there, commits every change (tracked and untracked) to the isolated branch, and prints how to merge it back.

Quick Start

1

Run a prompt in isolation

The agent edits a fresh branch — your working tree stays clean.
2

Run a YAML file in isolation

The YAML file is resolved to an absolute path before isolation, so an untracked or git-ignored agents.yaml still loads.
3

Keep the worktree for review

Both the worktree checkout and the branch stay in place after the run so you can inspect the files directly.

How It Works

--worktree provisions a per-run branch and directory, chdirs into it for the run, then decides what to keep based on whether the agent produced changes.
The worktree is named after the run target plus a random token, then hashed into a git-ref-safe slug. Two runs of the same prompt or YAML file never clobber each other’s uncommitted changes.

Teardown Matrix

What survives after the run depends on whether the agent changed anything and whether you passed --keep.
Untracked new files are committed too. Teardown uses git status --porcelain (not git diff), so brand-new files the agent creates are always captured on the branch before the checkout is pruned.

What Gets Rejected

--worktree is scoped to direct prompt and YAML file runs. These combinations fail fast with exit code 1.

CI / JSON Mode

Under --output json, the isolation status messages are suppressed but isolation still happens.
The agent runs on the isolated branch exactly as before; only the informational prints (Isolated run on branch ..., Committed changes ...) are silenced so your JSON payload stays clean.

Best Practices

Isolation means a bad run never dirties your working tree. Run the agent, inspect the branch, then git merge only if you like the result.
Without --keep, changed runs commit and prune the checkout — you review via git merge <branch>. With --keep, the checkout stays on disk under .praisonai/worktrees/ so you can open the files directly.
On teardown, changes are committed with git commit --no-verify. If no user.name / user.email is set, the commit fails and the worktree is kept in place for manual review instead. Set a git identity to get the clean commit-and-merge path.
--keep and commit-failure paths leave a worktree on disk. Remove it with git worktree remove <path> once you’ve reviewed or merged the branch.

Workspace Isolation

The SDK GitWorktreeAdapter this CLI flag wraps.

Kanban Worktree Isolation

Per-task git worktrees for kanban workers.

Run Command

Full praisonai run CLI reference.