From 94d44fefd28c2983fe889f9db06a34249e798422 Mon Sep 17 00:00:00 2001 From: Austin Wang Date: Fri, 20 Feb 2026 14:31:13 -0800 Subject: [PATCH] chore(claude-opus-4-6): Branch name in sidebar sometimes doesn't update correctly... (#199) --- .../shell-integration/cmux-bash-integration.bash | 11 +++++++++-- Resources/shell-integration/cmux-zsh-integration.zsh | 12 ++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Resources/shell-integration/cmux-bash-integration.bash b/Resources/shell-integration/cmux-bash-integration.bash index 8ad8d2fa..1e110f91 100644 --- a/Resources/shell-integration/cmux-bash-integration.bash +++ b/Resources/shell-integration/cmux-bash-integration.bash @@ -88,9 +88,16 @@ _cmux_prompt_command() { # Git branch/dirty can change without a directory change (e.g. `git checkout`), # so update on every prompt (still async + de-duped by the running-job check). + # When pwd changes (cd into a different repo), kill the old probe and start fresh + # so the sidebar picks up the new branch immediately. if [[ -n "$_CMUX_GIT_JOB_PID" ]] && kill -0 "$_CMUX_GIT_JOB_PID" 2>/dev/null; then - : - else + if [[ "$pwd" != "$_CMUX_GIT_LAST_PWD" ]]; then + kill "$_CMUX_GIT_JOB_PID" >/dev/null 2>&1 || true + _CMUX_GIT_JOB_PID="" + fi + fi + + if [[ -z "$_CMUX_GIT_JOB_PID" ]] || ! kill -0 "$_CMUX_GIT_JOB_PID" 2>/dev/null; then _CMUX_GIT_LAST_PWD="$pwd" _CMUX_GIT_LAST_RUN=$now { diff --git a/Resources/shell-integration/cmux-zsh-integration.zsh b/Resources/shell-integration/cmux-zsh-integration.zsh index 802e3cb3..3b5d00cc 100644 --- a/Resources/shell-integration/cmux-zsh-integration.zsh +++ b/Resources/shell-integration/cmux-zsh-integration.zsh @@ -139,11 +139,12 @@ _cmux_preexec() { _CMUX_CMD_START=$EPOCHSECONDS - # Heuristic: git commands can change branch/dirty state without changing $PWD. + # Heuristic: commands that may change git branch/dirty state without changing $PWD. local cmd="${1## }" - if [[ "$cmd" == git\ * || "$cmd" == git ]]; then - _CMUX_GIT_FORCE=1 - fi + case "$cmd" in + git\ *|git|gh\ *|lazygit|lazygit\ *|tig|tig\ *|gitui|gitui\ *|stg\ *|jj\ *) + _CMUX_GIT_FORCE=1 ;; + esac # Register TTY + kick batched port scan for foreground commands (servers). _cmux_report_tty_once @@ -196,6 +197,9 @@ _cmux_precmd() { head_mtime="$(_cmux_git_head_mtime "$_CMUX_GIT_HEAD_PATH" 2>/dev/null || echo 0)" if [[ -n "$head_mtime" && "$head_mtime" != 0 && "$head_mtime" != "$_CMUX_GIT_HEAD_MTIME" ]]; then _CMUX_GIT_HEAD_MTIME="$head_mtime" + # Treat HEAD file change like a git command — force-replace any + # running probe so the sidebar picks up the new branch immediately. + _CMUX_GIT_FORCE=1 should_git=1 fi fi