Skip to content

Git branch display in footer becomes stale after branch switch #7828

Description

@qwen-code-dev-bot

Important

Thanks for taking the time to fill out this bug report!

Please search existing issues to see if an issue already exists for the bug you encountered.

What happened?

The git branch name displayed in the footer (below the input prompt) does not update when the user switches branches externally (e.g. git checkout branch2 or git switch branch2). Running /clear also does not refresh it. The stale branch name persists until the next fs.watch event fires (which may never happen on some filesystems).

What did you expect to happen?

The branch name in the footer should update within a few seconds of switching branches, regardless of the filesystem type.

Steps to reproduce

  1. Start qwen-code in a git repo on branch feature-1
  2. Confirm the footer shows feature-1
  3. In another terminal (or via !git switch feature-2), switch to feature-2
  4. Observe the footer still shows feature-1
  5. Run /clear — footer still shows feature-1

Root cause

useGitBranchName (packages/cli/src/ui/hooks/useGitBranchName.ts) uses watchRepoBranch which sets up fs.watch on .git/logs/HEAD (the reflog). Two problems:

  1. fs.watch is unreliable on some filesystems (NFS, FUSE, Docker overlay, some Linux filesystems). Events can be silently dropped, leaving the branch name stale with no recovery path.

  2. No polling fallback. Unlike the extension file watcher which has both fs.watch and a generation-based polling fallback, the branch watcher has no polling. If the watch event is missed, the branch name stays stale indefinitely.

  3. /clear does not trigger a refresh. The useEffect in useGitBranchName depends on [cwd]. Since /clear doesn't change cwd, the effect doesn't re-run and no refresh occurs.

Suggested fix

  1. Add a polling fallback (e.g. every 5-10 seconds) in watchRepoBranch or useGitBranchName that calls resolveBranchName and compares with the current value, triggering onChange if different.

  2. Alternatively, expose a refreshGitBranch() function and call it from /clear, new message submission, and other session lifecycle events.

Environment

  • Qwen Code: v0.20.1 / v0.21.0
  • OS: Linux (reported on multiple filesystem types)

Anything else we need to know?

resolveBranchName itself does NOT cache — it reads .git/HEAD directly every call. The problem is purely that the watcher doesn't fire and there's no fallback to trigger a re-read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category/uiUser interface and displaypriority/P3Low - Minor, cosmetic, nice-to-fix issuesscope/gitGit integration featurestype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions