功能
Worktrees
Worktree 会话在仓库的隔离副本中运行,因此并行 agents 无法覆盖彼此的文件。Worktrees 需要 git 仓库,位于 ~/.grok/worktrees/<repo>/<name> 下,并从当前 HEAD 开始,其中包括未提交的更改。当父 Agent 委派并行工作时,Subagents 也可以请求 worktree 隔离。
启动 Worktree
grok -w
grok --worktree=feat "refactor module X" # = keeps the prompt out of the name
grok -w --ref main "fix the flaky test" # clean checkout of the ref
grok -w -r <session-id> # resume in a fresh worktree在 TUI 中:/fork --worktree 会将当前会话 fork 到 worktree;欢迎界面中的 Ctrl+W 打开 New Worktree 对话框;Ctrl+W 在 Agent Dashboard 中会将新 agents 分派到 worktrees。/new 和 /fork 是否提供 worktree 可进行配置,请参阅 TOML Values。
Worktree 是真实的 git checkout,在 base commit 上处于 detached 状态;使用普通 git 命令合入更改。
清理
Worktrees 会一直保留到你主动移除它们:结束或删除会话后,其 worktree 仍会保留;gc 只会在你调用时运行。
| 命令 | 作用 |
|---|---|
grok worktree list | 列出已跟踪的 worktrees |
grok worktree show <id> | 显示某个 worktree 的详情 |
grok worktree rm <ids...> | 移除 worktrees(使用 --dry-run 预览) |
grok worktree gc | 移除目录已不存在的条目;--max-age 7d 还会清理未被运行中 process 使用的闲置 worktrees |
最后更新:2026 年 7 月 21 日