Grok WorldGrok Build CLI field station

GROK BUILD CLI / 17

Manage worktree lifecycle without losing work

A worktree is a real checkout with branch and filesystem state; a cleanup command is never just UI housekeeping.

CHANNELREPOSITORY ISOLATION / ADVANCED / 12 MIN
SOURCES CHECKED2026-07-31
ORIGINOFFICIAL DOCS / PRIMARY

Inventory before mutation

Start with grok worktree list --json and narrow by repository when several projects are tracked. Use worktree show with an exact ID or path to inspect one candidate.

Check Git status, untracked files, branch, HEAD, and any unpushed commits inside the worktree. Grok’s tracking record cannot prove the checkout is disposable.

grok worktree list --json
grok worktree show ID_OR_PATH

Preview removal and garbage collection

grok worktree rm accepts one or more IDs and supports --dry-run. grok worktree gc also supports --dry-run and an age threshold. Preview first, then re-resolve the candidates immediately before mutation.

Avoid --force until dirty and unpushed work has been reviewed and preserved. Age alone is not evidence that a branch is obsolete.

  • Use exact IDs, not broad path globs.
  • Capture a diff or commit before removal when retention is required.
  • Re-list after cleanup to verify the intended result.

Treat the database separately

worktree db stats and db path inspect tracking metadata. db rebuild scans the filesystem to reconstruct that database; it changes local indexing state, not Git history.

Use rebuild when tracking is wrong, not as a substitute for Git cleanup. Review scan roots so unrelated repositories are not accidentally enrolled.