feat(kimi-code): add -w, --worktree [name] flag for isolated sessions#818
feat(kimi-code): add -w, --worktree [name] flag for isolated sessions#818rrva wants to merge 10 commits into
Conversation
Add a CLI flag that creates a new git worktree under <repo-root>/.kimi/worktrees/<name> and runs the session inside it. When no name is given, a kimi-<timestamp> name is generated. The worktree is created in detached HEAD at the current HEAD. - New worktree utility module with create/remove/list/find helpers. - Conflict validation against --session and --continue. - Persist worktree_path and parent_repo_path in session metadata. - Clean up the worktree on exit when the session is empty. - Add CLI parsing tests and worktree utility unit tests. Inspired by the upstream kimi-cli worktree feature.
🦋 Changeset detectedLatest commit: 42902f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7db693578
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 895e65e2de
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Make prepareWorktree synchronous; it performs no async work. - Log best-effort worktree cleanup failures instead of swallowing them.
895e65e to
a74eb19
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a74eb192b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed15942c78
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ed15942 to
91be1d7
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91be1d7b83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Keep .kimi/ out of the parent git index via .git/info/exclude. - Preserve the caller's subdirectory when entering a worktree session. - Delay worktree creation until after update preflight returns continue. - Skip prompt-mode worktree cleanup on turn failures; leave worktrees inspectable. - Track lifetime session content so /new does not delete earlier-session worktrees. - Emit resume hints with cd '<worktree>' for worktree sessions.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a86ada5cb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When a user ran /new inside a worktree session, createSessionFromCurrentState() did not pass the startup metadata, so the replacement session lost worktreePath and parentRepoPath. The TUI then no longer surfaced worktree context in the system prompt or subagents. Forward the startup metadata into replacement sessions and add a test covering the /new path.
- Set everHadSessionContent when entries are appended/pushed and before the transcript is cleared, so /new after an earlier session does not delete the worktree. - Fall back to the worktree root when the mirrored caller subdirectory does not exist in the detached worktree; clean up the worktree if chdir still fails. - Use quoteShellArg for the cd path in worktree resume hints so paths with shell metacharacters are safe to paste.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4710074370
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Resolve the worktree exclude via `git rev-parse --git-path info/exclude` instead of `--git-dir`. When the repo root is itself a linked worktree, `--git-dir` points at `.git/worktrees/<name>`, but Git reads the local exclude from the common git dir; the old path wrote `.kimi/` to a file Git never consults, so `git status` in the parent worktree still showed `?? .kimi/`. - Carry the current/resumed session's worktree metadata into replacement sessions when startup metadata is absent. A worktree session resumed with `-r` (no `--worktree`) has undefined startup metadata, so `/new` previously dropped worktreePath/parentRepoPath and lost the worktree system-prompt context for agents/subagents. Both paths gain regression tests (linked-worktree exclude resolution; resumed session /new metadata carry-forward).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42902f6c8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return; | ||
| } | ||
| const excludePath = resolve(repoRoot, excludePathResult.stdout); | ||
| const marker = '.kimi/'; |
There was a problem hiding this comment.
Limit the local exclude to worktree storage
When a repository already has untracked .kimi content unrelated to these session worktrees, appending .kimi/ to the shared info/exclude hides the entire directory from git status for every checkout using this common git dir. Running kimi -w can therefore silently stop Git from reporting files the user may intend to add; exclude only the storage path such as .kimi/worktrees/ instead of the whole .kimi/ tree.
Useful? React with 👍 / 👎.
Related Issue
Closes #828
Problem
Users running multiple Kimi Code sessions on the same repository need a way to avoid file conflicts and branch-switching overhead. The legacy Kimi CLI already supports this with a worktree flag, and users expect the same capability in Kimi Code CLI.
What changed
amber-drifting-cloud) when no name is supplied.Checklist
Verification