Skip to main content

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.

This page documents the types specific to the createWorktree() API. The Worktree handle’s methods (run(), interactive(), createSandbox()) accept their own option types that are slightly different from the top-level equivalents. All types are exported from @ai-hero/sandcastle.

WorktreeBranchStrategy

type WorktreeBranchStrategy = MergeToHeadBranchStrategy | NamedBranchStrategy;
The branch strategies accepted by createWorktree(). The head strategy is intentionally excluded because head mode means there is no worktree to create — it would be a compile-time type error to pass it here. See BranchStrategy for the full strategy shapes.

WorktreeRunOptions

Options for wt.run() — run an AFK agent in an existing worktree with a required sandbox.
agent
AgentProvider
required
Agent provider — for example claudeCode("claude-opus-4-7").
sandbox
SandboxProvider
required
Sandbox provider. Required for AFK agent runs — unattended agents must always be sandboxed.
prompt
string
Inline prompt. Mutually exclusive with promptFile.
promptFile
string
Path to a prompt file. Mutually exclusive with prompt.
promptArgs
PromptArgs
Key-value map for {{KEY}} placeholder substitution. Only valid with promptFile.
maxIterations
number
default:"1"
Maximum iterations to run.
completionSignal
string | string[]
Substring(s) the agent emits to stop the loop early.
idleTimeoutSeconds
number
default:"600"
Idle timeout in seconds. Resets on each agent output event.
name
string
Optional display name for the run.
logging
LoggingOption
default:"{ type: 'file' } (auto-generated)"
Logging mode: { type: "file", path } or { type: "stdout" }.
hooks
SandboxHooks
Lifecycle hooks. See SandboxHooks.
env
Record<string, string>
Additional environment variables injected into the sandbox.
resumeSession
string
Resume a prior Claude Code session by ID. Incompatible with maxIterations > 1. The session JSONL file must exist on the host.
signal
AbortSignal
Cancel the run when aborted. If already aborted at entry, rejects immediately. Aborting mid-iteration kills the in-flight agent subprocess. The worktree is preserved on disk. The Worktree handle remains usable for subsequent operations.

WorktreeRunResult

Return value of wt.run().
iterations
IterationResult[]
Per-iteration results. Use .length for the count.
completionSignal
string | undefined
The matched completion signal, or undefined if the loop ran to maxIterations without a match.
stdout
string
Combined stdout output from all agent iterations.
commits
{ sha: string }[]
List of commits created during the run.
branch
string
The branch name the agent worked on.
logFilePath
string | undefined
Path to the log file. Only present when logging was set to { type: "file" }.

WorktreeInteractiveOptions

Options for wt.interactive() — run a supervised interactive agent session in an existing worktree.
agent
AgentProvider
required
Agent provider.
sandbox
AnySandboxProvider
default:"noSandbox()"
Sandbox provider. Defaults to noSandbox() when omitted.
prompt
string
Inline prompt. Optional — omit to open the TUI with no initial message. Mutually exclusive with promptFile.
promptFile
string
Path to a prompt file. Mutually exclusive with prompt.
name
string
Optional session name.
hooks
SandboxHooks
Lifecycle hooks. See SandboxHooks.
promptArgs
PromptArgs
Key-value map for {{KEY}} placeholder substitution. Only valid with promptFile.
env
Record<string, string>
Additional environment variables injected into the sandbox.
signal
AbortSignal
Cancel the session when aborted. The worktree is preserved on disk. The Worktree handle remains usable. Rejects with signal.reason.

WorktreeCreateSandboxOptions

Options for wt.createSandbox() — create a long-lived sandbox backed by the existing worktree.
sandbox
SandboxProvider
required
Sandbox provider — for example docker().
hooks
SandboxHooks
Lifecycle hooks. See SandboxHooks.
copyToWorktree
string[]
Host-relative file paths to copy into the worktree at creation time.
timeouts
Timeouts
Override default timeouts. See Timeouts.
When you create a sandbox via wt.createSandbox(), calling sandbox.close() tears down the container only. The worktree stays alive until you call wt.close(). This differs from top-level createSandbox(), where sandbox.close() owns both the container and the worktree.

IterationResult

A single iteration’s result, available in the iterations array on any run result type.
sessionId
string | undefined
Claude Code session ID parsed from the agent’s init line. undefined for non-Claude agents.
sessionFilePath
string | undefined
Absolute host path to the captured session JSONL file. undefined when session capture is disabled or not applicable.
usage
IterationUsage | undefined
Token usage snapshot from the last assistant message. undefined when session capture is off or the provider does not emit usage data.

IterationUsage

Token usage for a single iteration, derived from the agent’s last assistant message.
inputTokens
number
Input tokens consumed.
cacheCreationInputTokens
number
Tokens used to create prompt cache entries.
cacheReadInputTokens
number
Tokens read from the prompt cache.
outputTokens
number
Output tokens generated.

Build docs developers (and LLMs) love