Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mattpocock/sandcastle/llms.txt
Use this file to discover all available pages before exploring further.
createWorktree() creates a git worktree as an independent, first-class concept that exists separately from any sandbox container. You get a Worktree handle with its own run(), interactive(), and createSandbox() methods. This is useful when you want to run a supervised interactive session first to explore the codebase, then hand the same worktree to an unattended AFK agent — all without recreating the worktree between steps.
The key difference from createSandbox() is split ownership: when you call wt.createSandbox(), the resulting sandbox.close() tears down the container only. The worktree stays alive until you call wt.close().
Only branch and merge-to-head branch strategies are accepted. The head strategy is a compile-time type error because it means there is no worktree to create.
Import
Signature
Full example — interactive session then AFK agent
Creating a long-lived sandbox from a worktree
Automatic cleanup with await using
await using calls wt.close() automatically when the block exits. If the worktree has uncommitted changes it is preserved on disk; if clean it is removed.
CreateWorktreeOptions
Controls which branch the worktree is on. Accepts
{ type: "branch", branch: "name" } for an explicit named branch, or { type: "merge-to-head" } for a temporary branch that merges back to HEAD when closed. The head strategy is not accepted.Host-relative file paths to copy into the worktree at creation time — for example
["node_modules", ".env"].Host repo directory. Relative paths resolve against
process.cwd(); absolute paths pass through as-is. A CwdError is thrown if the path does not exist or is not a directory.Worktree object
The branch the worktree is on.
Absolute host path to the worktree directory.
Run an AFK agent in the worktree. A
sandbox is required. See WorktreeRunOptions.Run an interactive agent session in the worktree. Defaults to
noSandbox() when no sandbox is specified. See WorktreeInteractiveOptions.Create a long-lived sandbox backed by this worktree.
sandbox.close() tears down the container only; the worktree remains. See WorktreeCreateSandboxOptions.Clean up the worktree. Preserves it on disk if it has uncommitted changes; removes it if clean.
Called automatically by
await using. Delegates to close().