Features
Terminal UI worktrees
This page covers the Terminal UI. For the Agents Window, see Worktrees in the Agents Window.
A worktree session runs in an isolated copy of your repository, so parallel agents cannot overwrite each other's files. Worktrees require a git repository, live under ~/.grok/worktrees/<repo>/<name>, and start from your current HEAD, including uncommitted changes. Subagents can also request worktree isolation when the parent delegates parallel work.
Starting one
Bash
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
In the TUI: /fork --worktree forks the current session into a worktree, Ctrl+W on the welcome screen opens the New Worktree dialog, and Ctrl+W in the Agent Dashboard dispatches new agents into worktrees. Whether /new and /fork offer a worktree is configurable—see TOML Values.
A worktree is a real git checkout, detached at its base commit; land changes with ordinary git.
Housekeeping
Ending or deleting a session leaves its worktree in place, and you can remove worktrees yourself at any time with the commands below. Grok also collects old ones for you: starting a session runs a garbage-collection pass, throttled to at most once every six hours, which removes session worktrees older than seven days on macOS and Linux. Worktrees you created yourself, rather than through a session or a fork, never expire by age.
The automatic pass applies the same safety checks as grok worktree gc, so it keeps anything that still holds work: a worktree with uncommitted changes, with commits you have not pushed, with ignored or untracked content that exists nowhere else, or one a running process is using. To manage worktrees entirely by hand, turn the pass off in $GROK_HOME/config.toml:
TOML
[worktree.auto_gc]
enabled = false
| Command | What it does |
|---|---|
grok worktree list | List tracked worktrees |
grok worktree show <id> | Show details for one worktree |
grok worktree rm <ids...> | Remove worktrees (--dry-run to preview) |
grok worktree gc | Remove entries whose directory is gone; --max-age 7d also expires idle worktrees not in use by a running process |
Last updated: November 23, 2026