A CLI tool for managing Claude instances with git worktree
A CLI tool for managing Claude instances with git worktree
Manage Claude or Codex coding sessions by turning every git worktree into its own agent playground.
xlaude keeps large projects organized by pairing each feature branch with a dedicated AI session. It automates worktree creation, keeps track of conversation history, and helps you pause, resume, and clean up work in seconds.
../- with automatic branch creation, sanitized names, and submodule updates.list reads Claude (~/.claude/projects) and Codex (~/.codex/sessions) logs to surface the last user prompt and activity timestamps per worktree.agent command (default claude --dangerously-skip-permissions). When that command is codex, xlaude auto-appends resume matching the worktree.XLAUDE_YES/XLAUDE_NON_INTERACTIVE, and exposes a hidden completion helper for shell integration.cargo install or local builds).gh) so delete can detect merged PRs even after squash merges.cargo install xlaudegit clone https://github.com/xuanwo/xlaude
cd xlaude
cargo build --releaseUse target/release/xlaude or add it to your PATH.
Re-run cargo install xlaude to pull the latest published release, or git pull && cargo build --release if you track main.
Generate completion scripts for bash, zsh, or fish:
xlaude completions bash > ~/.bash_completion.d/xlaude
xlaude completions zsh > ~/.zfunc/_xlaude
xlaude completions fish > ~/.config/fish/completions/xlaude.fishThe completions use the hidden xlaude complete-worktrees --format=detailed helper to surface worktree names, repositories, and recent session counts.
State lives in a JSON file that xlaude migrates automatically:
~/Library/Application Support/com.xuanwo.xlaude/state.json~/.config/xlaude/state.json%APPDATA%\\xuanwo\\xlaude\config\state.jsonEach entry is keyed by / (introduced in v0.3). Use XLAUDE_CONFIG_DIR to override the directory for testing or portable setups.
Set the global agent field to the exact command line xlaude should launch for every worktree. Example:
{
"agent": "codex --dangerously-bypass-approvals-and-sandbox",
"worktrees": {
"repo/feature": { /* ... */ }
}
}claude --dangerously-skip-permissions.codex and no positional arguments were supplied, xlaude will locate the latest session under ~/.codex/sessions (or XLAUDE_CODEX_SESSIONS_DIR) whose cwd matches the worktree and automatically append resume .xlaude create and checkout copy CLAUDE.local.md into the new worktree if it exists at the repo root.git submodule update --init --recursive in every new worktree.feature/foo → feature-foo) before creating the directory.xlaude create [name]main, master, develop, or the remote default).XLAUDE_TEST_SEED for deterministic names in CI.XLAUDE_NO_AUTO_OPEN or XLAUDE_TEST_MODE is set.xlaude create auth-gateway
xlaude create # -> ../repo-harborxlaude checkout #).origin/ when missing.pull//head into pr/ before creating the worktree.xlaude open [name]state.json.fzf-like list) or honors piped input.xlaude, it is drained and not passed to the agent to avoid stuck sessions.xlaude add [name]Attach the current git worktree (where .git is a file) to xlaude state. Name defaults to the sanitized branch. The command refuses to add the same path twice, even under a different alias.
xlaude rename Renames the entry in state.json within the current repository, keeping the underlying directory and git branch unchanged.
xlaude list [--json]~/.claude/projects/; up to three per worktree are previewed with "time ago" labels.--json emits a machine-readable structure:{
"worktrees": [
{
"name": "auth-gateway",
"branch": "feature/auth-gateway",
"path": "/repos/repo-auth-gateway",
"repo_name": "repo",
"created_at": "2025-10-30T02:41:18Z",
"sessions": [ { "last_user_message": "Deploy staging", "time_ago": "5m ago" } ],
"codex_sessions": [ ... ]
}
]
}xlaude dir [name]Prints the absolute path of a worktree with no ANSI formatting, making it ideal for subshells:
cd $(xlaude dir auth-gateway)When no argument is provided, an interactive selector (or piped input) chooses the worktree.
xlaude delete [name]git branch --merged or GitHub PR history (gh pr list --state merged --head ). Squash mergers are therefore detected.xlaude cleanCross-checks state.json against actual git worktree list output for every known repository. Any missing directories are removed from state with a concise report.
xlaude configOpens the state file in $EDITOR, creating parent directories as needed. Use this to hand-edit the global agent or worktree metadata.
xlaude completions Prints shell completion scripts. Combine with complete-worktrees for dynamic worktree hints.
xlaude complete-worktrees [--format=simple|detailed] (hidden)Emits sorted worktree names. The detailed format prints namerepopathsession-summary and is consumed by the provided zsh/fish completion functions. You can also call it in custom tooling.
Input priority is always CLI argument > piped input > interactive prompt. Example: echo feature-x | xlaude open correct-name opens correct-name.
Environment switches:
| Variable | Effect |
|---|---|
XLAUDE_YES=1 |
Auto-confirm every prompt (used by delete, create, etc.). |
XLAUDE_NON_INTERACTIVE=1 |
Disable interactive prompts/selectors; commands fall back to defaults or fail fast. |
XLAUDE_NO_AUTO_OPEN=1 |
Skip the “open now?” question after create. |
XLAUDE_CONFIG_DIR=/tmp/xlaude-config |
Redirect both reads and writes of state.json. |
XLAUDE_CODEX_SESSIONS_DIR=/path/to/sessions |
Point Codex session discovery to a non-default location. |
XLAUDE_TEST_SEED=42 |
Deterministically pick random names (handy for tests). |
XLAUDE_TEST_MODE=1 |
Test harness flag; suppresses some interactivity (also skips auto-open). |
Piped input works with selectors and confirmations. For example, yes | xlaude delete feature-x or printf "1\n" | xlaude open to pick the first entry.
# 1. Create an isolated workspace from main
xlaude create payments-strategy
# 2. Start working with your agent
xlaude open payments-strategy
# 3. Inspect outstanding worktrees across repositories
xlaude list --json | jq '.worktrees | length'
# 4. Clean up after merge
xlaude delete payments-strategyApache License 2.0. See LICENSE for details.
No open issues yet, or sync has not completed.