feat(cli): add git worktree support for isolated sessions#2073
feat(cli): add git worktree support for isolated sessions#2073cal-gooo wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
4facdcb to
091d7b1
Compare
Add --worktree / -W flag to create a new git worktree and run the session inside it. This allows multiple parallel kimi sessions on the same repository without file conflicts or branch-switching overhead. New CLI options: --worktree, -W Create a new git worktree for the session --worktree-name TEXT Custom worktree directory name --worktree-branch TEXT Branch to check out (default: detached HEAD) Changes: - New worktree.py module with create_worktree(), remove_worktree(), list_worktrees(), and find_git_root() helpers. - SessionState extended with worktree_path and parent_repo_path. - Session.delete() cleans up the git worktree to avoid accumulation. - Conflict checks prevent combining --worktree with --continue or --session (resuming in a worktree doesn't make sense). PR review fixes: - Add --detach flag when creating worktree without a branch, preventing git from auto-creating a branch named after the worktree directory. - Fix _rmtree_sync fallback to convert KaosPath to pathlib.Path, avoiding silent failures from shutil.rmtree type errors. - Guard worktree creation with _worktree_created flag so Reload re-entries (e.g. /model, /theme) do not create nested worktrees. Tests: - Unit tests for worktree creation, removal, listing, and error cases. - CLI tests for option parsing and conflict detection. Inspired by Codex and Claude Code worktree workflows.
091d7b1 to
1886a8f
Compare
|
Forwarding two findings from automated reviewers on the stacked PR #2076. Both apply to code originating in this PR: 1.
|
Summary
Add
--worktree/-Wflag to create a new git worktree and run the session inside it. This allows multiple parallel kimi sessions on the same repository without file conflicts or branch-switching overhead.New CLI Options
--worktree,-W— Create a new git worktree for the session--worktree-name <name>— Custom worktree directory name--worktree-branch <branch>— Branch to check out (default: detached HEAD)Usage Example
Implementation Details
worktree.pymodule withcreate_worktree(),remove_worktree(),list_worktrees(), andfind_git_root()helpers.SessionStateextended withworktree_pathandparent_repo_path.Session.delete()cleans up the git worktree to avoid accumulation of abandoned worktrees.--worktreewith--continueor--session.Tests
Motivation
Inspired by Codex and Claude Code worktree workflows, which use git worktrees to isolate parallel agent sessions on the same repo.