Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

treehouse

> AI 编程
Open source

Manage worktrees without managing worktrees.

1.2K stars0 likes1 views
WebsiteGitHub

About

Manage worktrees without managing worktrees.

treehouse

Manage worktrees without managing worktrees.

Are you still only working on one task at a time? Are you manually juggling between a few clones of the same repo?

Or... are you starting a new worktree for every agent session, losing all your installed dependencies and build cache each time, and wondering why your agents are slow?

Treehouse helps you manage a pool of reusable, isolated worktrees so each of your agents gets its own environment instantly — no cloning, no conflicts, no coordination overhead.

  • Instant isolation — treehouse puts you into a clean worktree with zero hassel.
  • Reusable worktrees — worktrees are preserved in a pool when you're done, with dependencies and build cache intact, ready for the next agent.
  • Conflict-free — automatic detection of in-use worktrees and your agents never step on each other's toes.

Quick Start

bash
$ cd myproject                 # start in your repo as usual
$ treehouse                    # get a worktree and drop into a subshell
 Entered worktree at ~/.treehouse/myproject-a1b2c3/1/myproject. Type 'exit' to return.

# You're now in an isolated worktree.
# Run your AI agent, make changes, do whatever you need.

$ exit                         # exit the subshell when you're done
 Terminated lingering processes: opencode (pid 12345)
 Worktree returned to pool.

Install

macOS / Linux

bash
curl -fsSL https://kunchenguid.github.io/treehouse/install.sh | sh

Windows (PowerShell)

powershell
irm https://kunchenguid.github.io/treehouse/install.ps1 | iex

Nix

bash
nix run github:kunchenguid/treehouse
# or pin a specific release tag:
nix run github:kunchenguid/treehouse/v2.3.0

Install into your Nix profile:

bash
nix profile add github:kunchenguid/treehouse

Or add to your flake inputs:

nix
treehouse = {
  url = "github:kunchenguid/treehouse";
  inputs.nixpkgs.follows = "nixpkgs";
};

The flake exposes #default and #treehouse package outputs, plus apps for nix run.

Go

bash
go install github.com/kunchenguid/treehouse@latest

From source

bash
git clone https://github.com/kunchenguid/treehouse.git
cd treehouse
make install

How It Works

Treehouse manages a pool of git worktrees per repository, stored under the configured treehouse root. The default treehouse root is ~/.treehouse/. You can instead keep the pool inside the project with --root ., so it lives next to the code and is removed with the project.

…
  • Detached HEAD — worktrees use detached HEAD mode, reset to whichever of the local or remote default branch is further ahead, avoiding branch name conflicts entirely.
  • Choosable base branch — set base_branch in treehouse.toml, or pass treehouse get --base , to cut worktrees from a branch other than the repository default. Opt-in; unset keeps today's inference. Worktrees stay in detached HEAD — this selects the commit they start at, it does not create or check out a branch.
  • Unique worktree directory names — pass treehouse get --unique-leaf (or set unique_leaf in treehouse.toml) to name new slots - instead of ``, so tooling that derives per-checkout identity from the directory name tells the slots apart. Opt-in; off keeps today's layout, and existing worktrees are never moved.
  • Choosable worktree path — set worktree_path in treehouse.toml, or pass treehouse get --worktree-path '', to place new worktrees somewhere a tool requires instead of {pool}/{slot}/{repo}. Opt-in, and creation-only: worktrees already in the pool keep their recorded paths. See Worktree path.
  • No daemon - all operations are inline CLI commands. Pool state is a small on-disk file, written under a lock by each command.
  • Interactive shell setup — when opening a subshell on macOS or Linux, treehouse, treehouse get, and treehouse enter start $SHELL as an interactive login shell when it resolves to bash, fish, or zsh. Other shells, fallback shells, and Windows use their default invocation. A regular executable that is merely named like a supported shell but does not accept -i -l (for example a wrapper script at /opt/tools/bash) is an accepted limitation: the resolved basename is the contract, and PATH-identity probing would reject genuine second installs of the same shell.
  • In-use detection — treehouse scans running processes and short-lived owner reservations to determine which worktrees are in-use. Reservations are persisted only while get, destroy, and prune lifecycle work is running.
  • Durable leases - treehouse get --lease reserves a worktree as a persistent home without keeping a process inside it. Each acquisition gets an immutable random lease identity, and the lease is recorded in treehouse's own state. The worktree is never handed out by a later get and never removed by prune until you release it with treehouse return. Unlike process-based in-use detection, a lease survives with zero processes running inside the worktree.
  • State recovery - treehouse writes pool state atomically via a temp file and replacement. If an existing state file is empty, truncated, or omits an on-disk worktree, treehouse rebuilds the missing entries and quarantines them for inspection and explicit destruction. See Recovering missing pool state.
  • Gitignored file seeding — commit a .worktreeinclude file for the default selection, or pass get --include-file for a personal manifest. Selected local files are copied from the main checkout on each acquire. See Seeding gitignored files.
  • Dirty detection - treehouse treats tracked changes and untracked files as dirty, even when repository config hides untracked files from normal git status output.
  • Safe pruning - By default, treehouse prune removes only idle managed worktrees whose HEAD is already merged into the default branch and whose working tree is clean. treehouse prune --all applies the same safety checks across every managed pool under the user-level treehouse root. Backing-repository-missing orphans are reported by default; --prune-orphans includes them as unverified prune candidates, and --yes is required before deletion. It is a dry run unless you pass --yes.
  • Self-healing get - treehouse get prunes stale git worktree bookkeeping (e.g. left behind by a crashed or forcibly removed worktree) before adding a new worktree, so a prunable registration never wedges the pool with a "missing but already registered worktree" error.

CLI Reference

Command Description
treehouse Get a worktree and open a subshell (alias for get)
treehouse get Acquire a worktree from the pool
treehouse get --lease Durably lease a worktree without a subshell; print its path
treehouse lease Durably lease an existing pool worktree in place, without touching its files or git state
treehouse enter Open a subshell in an existing worktree by name (the number from status), even if it is in use; pool state is left untouched
treehouse status Show pool status (highlights leased and current worktrees)
treehouse return [path] Release any lease and return a worktree only after verifying foreign processes stopped
treehouse prune Dry-run removal of stale idle worktrees in the current repo pool
treehouse prune --all Dry-run removal of stale idle worktrees across every managed pool
treehouse destroy Dry-run removal of one worktree (safe by default; --yes to execute)
treehouse destroy --all Dry-run removal of every disposable worktree in that pool
treehouse init Create a default treehouse.toml config file
treehouse update Update treehouse to the latest version

Flags

Command Flag Description
get --lease Durably lease the worktree without opening a subshell; print only its path to stdout
get --lease-holder Optional label recorded as the lease holder (defaults to $TREEHOUSE_LEASE_HOLDER)
get --json Print path, lease_id, lease_holder, leased_at, and base_branch as JSON (requires --lease)
get --base Branch to cut this worktree from, overriding base_branch in config
get --include-file Replace committed .worktreeinclude for this acquisition with the supplied manifest
get --unique-leaf Name a newly created worktree directory - instead of ``, overriding unique_leaf in config
get --worktree-path Template for a newly created worktree's directory, overriding worktree_path in config
lease --lease-holder Optional label recorded as the lease holder (defaults to $TREEHOUSE_LEASE_HOLDER)
lease --json Print path, lease_id, lease_holder, leased_at, and base_branch as JSON (base_branch is best-effort: empty when the slot records no explicit base and its own worktree cannot resolve a default)
enter --print-path Print only the worktree's absolute path to stdout instead of opening a subshell (for cd "$(treehouse enter --print-path 1)")
status --json Print worktree status and lease metadata as JSON
return --force Clean, reset, and return without prompting
return --if-lease-id Return only if the current lease has the expected per-acquisition identity
return --if-lease-holder Return only if the current lease has the expected holder
prune --yes Delete listed prune candidates instead of doing a dry run
prune --all Sweep every managed pool under the user-level treehouse root
prune --global Alias for --all
prune --prune-orphans Include backing-repository-missing orphans in prune candidates
prune --verbose, -v Show detailed skip diagnostics
destroy --all Remove all worktrees in the named pool (requires a pool path)
destroy --yes Execute the removal instead of doing a dry run
destroy --include-unlanded Also remove dirty, unmerged, or unverified worktrees (irreversible data loss)
destroy --include-in-use Also remove worktrees with a running process or owner reservation (processes are terminated cleanly first)
destroy --include-leased Also remove a leased worktree; only when the exact path is named, never via --all

Seeding gitignored files

Commit a .worktreeinclude file to seed selected gitignored files from the main checkout into each acquired Git worktree or jj workspace. This is useful for local configuration or generated files that every worktree needs but Git should not track. By default, only the committed file at the worktree's HEAD is used; a dirty or untracked .worktreeinclude in the main checkout is ignored, and a missing committed file is a no-op.

Manifests use .gitignore pattern syntax. A file must be ignored by the repository and selected by the manifest; tracked files and unignored untracked files are never copied. Use ! to exclude a broader match:

gitignore
.env*
!.env.local
local-config/

For a personal selection that does not need to be committed, pass an explicit manifest:

bash
treehouse get --include-file ./personal.include
treehouse get --lease --include-file ./personal.include

The supplied manifest replaces, rather than extends, committed .worktreeinclude for this acquisition, on both new and r

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goagentscodinggitworktree

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.