Skip to content

exit_worktree — remove, merge, or abandon a worktree

exit_worktree is the cleanup half of the worktree pair. Each action resolves the worktree differently:

ActionEffect
removegit worktree remove <path>. Branch is kept; tree is deleted.
mergeSwitch to the worktree’s parent branch, fast-forward merge the worktree branch, then remove.
abandonremove + git branch -D <name>. Both tree and branch are gone.
ArgTypeRequiredDescription
worktree_pathstringyesFilesystem path of the worktree to operate on.
actionstringyesremove, merge, or abandon.
{"worktree_path": "/Users/me/dev/chimera-spike-redis-backend", "action": "merge"}
from chimera.tools.worktree_tool import ExitWorktreeTool
tool = ExitWorktreeTool()
result = tool.execute(
{"worktree_path": "/Users/me/dev/chimera-spike-redis-backend",
"action": "abandon"},
env=local_env,
)
Abandoned worktree '/Users/me/dev/chimera-spike-redis-backend' (deleted tree, deleted branch 'spike-redis-backend').
  • merge refuses to run if the worktree has uncommitted changes; commit (or remove and accept the loss) first.
  • abandon is destructive. Behind the Permissions layer it should require explicit approval.