Skip to content

Worktree

Base classes

Name Children Inherits
ClaudeCodeBaseModel
clawd_code_sdk.models.base
Base model for all Claude Code Pydantic models.

⋔ Inheritance diagram

graph TD
  3622335539["settings.Worktree"]
  2604142835["base.ClaudeCodeBaseModel"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  2604142835 --> 3622335539
  3879467795 --> 2604142835
  2751680898 --> 3879467795

🛈 DocStrings

Bases: ClaudeCodeBaseModel

Configuration for --worktree sessions. See https://code.claude.com/docs/en/settings#worktree-settings.

Source code in src/clawd_code_sdk/models/settings.py
class Worktree(ClaudeCodeBaseModel):
    """Configuration for --worktree sessions. See https://code.claude.com/docs/en/settings#worktree-settings."""

    model_config = ConfigDict(
        extra="forbid",
    )
    sparse_paths: list[SparsePath] | None = Field(
        None, alias="sparsePaths", examples=[["packages/my-app", "shared/utils"]]
    )
    """
    Directories to check out in each worktree via git sparse-checkout (cone mode). Only the listed paths are written to disk, which is faster in large monorepos. See https://code.claude.com/docs/en/settings#worktree-settings
    """
    base_ref: Literal["fresh", "head"] | None = Field("fresh", alias="baseRef")
    """
    Whether to branch worktrees from `origin/<default>` (fresh) or local HEAD (head). Default: fresh. Set to 'head' to preserve unpushed commits in new worktrees. See https://code.claude.com/docs/en/settings#worktree-settings
    """
    bg_isolation: Literal["worktree", "none"] | None = Field("worktree", alias="bgIsolation")
    """
    Isolation mode for background sessions. "worktree" blocks Edit/Write in main checkout until EnterWorktree is called; "none" lets background jobs edit the working copy directly without EnterWorktree, for repos where worktrees are impractical. See https://code.claude.com/docs/en/settings#worktree-settings
    """
    symlink_directories: list[str] | None = Field(
        None, alias="symlinkDirectories", examples=[["node_modules", ".cache"]]
    )
    """
    Directories to symlink from the main repository into each worktree to avoid duplicating large directories on disk. No directories are symlinked by default. See https://code.claude.com/docs/en/settings#worktree-settings
    """

base_ref class-attribute instance-attribute

base_ref: Literal['fresh', 'head'] | None = Field('fresh', alias='baseRef')

Whether to branch worktrees from origin/<default> (fresh) or local HEAD (head). Default: fresh. Set to 'head' to preserve unpushed commits in new worktrees. See https://code.claude.com/docs/en/settings#worktree-settings

bg_isolation class-attribute instance-attribute

bg_isolation: Literal['worktree', 'none'] | None = Field('worktree', alias='bgIsolation')

Isolation mode for background sessions. "worktree" blocks Edit/Write in main checkout until EnterWorktree is called; "none" lets background jobs edit the working copy directly without EnterWorktree, for repos where worktrees are impractical. See https://code.claude.com/docs/en/settings#worktree-settings

sparse_paths class-attribute instance-attribute

sparse_paths: list[SparsePath] | None = Field(
    None, alias="sparsePaths", examples=[["packages/my-app", "shared/utils"]]
)

Directories to check out in each worktree via git sparse-checkout (cone mode). Only the listed paths are written to disk, which is faster in large monorepos. See https://code.claude.com/docs/en/settings#worktree-settings

symlink_directories: list[str] | None = Field(
    None, alias="symlinkDirectories", examples=[["node_modules", ".cache"]]
)

Directories to symlink from the main repository into each worktree to avoid duplicating large directories on disk. No directories are symlinked by default. See https://code.claude.com/docs/en/settings#worktree-settings

:fa-brands-github: Show source on GitHub