Cloud session checks out stale local branch when a commit is pushed between container pre-warm and session start
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
A Claude Code on the web session (started from the desktop app) came up one commit behind the remote tip of the branch I named. Reflogs show the harness did re-fetch the branch at session start and got the new tip (HEAD detached on it), then ran git checkout <branch>, which resolved to the local branch created ~9 min earlier during container pre-warm — pointing at the old tip. In the same second refs/remotes/origin/<branch> was rewritten back to the OLD sha, so git status reported up to date. SessionStart hooks then ran against the stale checkout, so a hook fix pushed minutes earlier had no effect.
Window: any push landing between container preparation (09:03) and session start (09:12) is silently dropped from the checkout.
What Should Happen?
HEAD is at the remote tip of the requested branch as of session start, and SessionStart hooks / CLAUDE.md / settings are read from that tip. If a local branch already exists from pre-warm, it should be forced onto the fetched tip (git checkout -B <branch> FETCH_HEAD or reset --hard origin/<branch>), and the remote-tracking ref must never be written back to a stale sha.
Error Messages/Logs
# all UTC. Missing commit bb04b761c pushed 09:11:22.
$ git reflog --date=iso
13513f9a8 HEAD@{09:12:59}: checkout: moving from bb04b761c to rainer/pr-body-shape-hook
bb04b761c HEAD@{09:12:55}:
13513f9a8 HEAD@{09:03:53}: checkout: moving from 13513f9a8 to rainer/pr-body-shape-hook
13513f9a8 HEAD@{09:03:42}:
$ git reflog show rainer/pr-body-shape-hook # local branch never moved
13513f9a8 @{09:03:53}: branch: Created from refs/remotes/origin/rainer/pr-body-shape-hook
$ git reflog show origin/rainer/pr-body-shape-hook
bb04b761c @{09:18:43}: fetch -q origin rainer/pr-body-shape-hook: fast-forward # my manual fetch
13513f9a8 @{09:12:59}: # rewritten to OLD sha, empty msg
bb04b761c @{09:12:55}: fetch --no-progress --depth 50 origin refs/heads/rainer/pr-body-shape-hook: fast-forward
13513f9a8 @{09:03:42}: fetch --no-progress --depth 50 origin refs/heads/rainer/pr-body-shape-hook: storing head
# mtimes: .git/refs/heads/<branch>=09:03:53 .git/shallow=09:12:46 .git/HEAD=09:12:59
# diag log: SessionStart hook_spawn_started at 09:13:05 (after stale checkout)
Steps to Reproduce
- From the desktop app, start a cloud session on branch X of a repo. The container is prepared some minutes before the first turn.
- Push a new commit to X during that gap.
- In the session run
git log -1, thengit fetch origin X && git status -sb.
Result: HEAD is the pre-warm-time tip; status is "up to date" until the manual fetch, then [behind 1].
Claude Model
_No response_
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.42
Platform
Other
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Env: CLAUDE_CODE_ENTRYPOINT=remote_desktop, CLAUDE_CODE_REMOTE_ENVIRONMENT_TYPE=cloud_default, runner release-ba76006550-ext, CLAUDE_CODE_WORKER_EPOCH=1, git 2.43.0, shallow clone (--depth 50), private org repo.
Impact: work is based on an outdated tip (later non-ff push or silent revert of the missing commit); SessionStart hooks/settings come from the old commit; the stale remote-tracking ref hides it from git status.
Related, not duplicates: #55861 (web session never fetches before branching — here it fetched and then discarded the result), #41885 (marketplace sync fetches but never fast-forwards — same class, different path), #60295 (concurrent local sessions).
3 Comments
I'm having the same issue in Claude Code cloud sessions via the browser. It fetches the latest commits, then resets both the local and remote branches to an old commit, even if that old commit is not in the history of the current branch tip.
Here's a Reddit post describing the same problem: https://www.reddit.com/r/ClaudeCode/comments/1w1pvfk/claude_code_web_sessions_keep_starting_my_feature/
My workaround is to simply add this line to the "Setup script" section of the environment that I am using:
/home/user/<name of the repository> && git pull --ff-only || echo "git pull skipped"