Label Worktrees while in Terminal

Feature request for product/service

AI Models

Describe the request

Can we have an indicator in Terminal that shows what worktree we are currently in? I keep putting the wrong items into terminal when I am in a worktree that it doesn’t belong in. Thanks

Hey @Aerospace!

Since these are just regular git worktrees, the simplest way to get an always-visible indicator today is to have your shell prompt label them for you.

If you already use a git-aware prompt (Starship, oh-my-zsh, powerlevel10k), you get this for free. The branch name shows up automatically, and the branch is the most meaningful label anyway, since the worktree folder names are auto-generated.

If you’d prefer an explicit badge that appears only when you’re inside a worktree, add the following to your shell profile.

For zsh (~/.zshrc):

setopt PROMPT_SUBST
worktree_badge() {
  [ "$(git rev-parse --git-dir 2>/dev/null)" = "$(git rev-parse --git-common-dir 2>/dev/null)" ] && return
  echo "[worktree: $(git branch --show-current 2>/dev/null)] "
}
PROMPT='$(worktree_badge)'"$PROMPT"

For bash (~/.bashrc):

worktree_badge() {
  [ "$(git rev-parse --git-dir 2>/dev/null)" = "$(git rev-parse --git-common-dir 2>/dev/null)" ] && return
  echo "[worktree: $(git branch --show-current 2>/dev/null)] "
}
PS1='$(worktree_badge)'"$PS1"

That said, a ready-made setup like oh-my-zsh or Starship is much less work than maintaining your own snippet, and it handles the edge cases for you!

You totally rock!! Thanks. Having my Grok Build die on me last night was terrifying. I didn’t realize that I have to manually clean the .bin and .obj folders.