Auto-stash on branch switch uses --include-untracked, silently sweeping untracked files (appear deleted)

Resolved 💬 4 comments Opened Jun 7, 2026 by FulcrumVDC Closed Jul 14, 2026

What happened

A git stash entry was created automatically by the Claude Code harness (not by any command I or an agent ran) at the moment of a branch switch, and it used --include-untracked. This swept ~140 untracked files (local assets that had never been committed) out of the working tree and into a stash.

From the user's perspective the files were deleted — they vanished from the folder, and a folder-syncing client (OneDrive) then propagated the deletion to the cloud. They were only recovered after discovering the stash by inspecting git reflog.

Evidence

git stash list:

stash@{0}: On <branch-b>: <name>: pre-switch from <branch-b>

git reflog --date=iso around the moment — note the three objects created in the same second, which is the signature of git stash --include-untracked:

<sha1> HEAD@{2026-..-.. 10:31:13}: On <branch-b>: <name>: pre-switch from <branch-b>
<sha2> HEAD@{2026-..-.. 10:31:13}: index on <branch-b>: <sha> <commit subject>
<sha3> HEAD@{2026-..-.. 10:31:13}: untracked files on <branch-b>: <sha> <commit subject>
<sha>  HEAD@{2026-..-.. 10:27:18}: checkout: moving from <branch-a> to <branch-b>

The stash's untracked-files tree contained ~140 untracked files (all under one local assets folder) that had never been committed to the repo.

No agent ran git stash. I grepped every Claude Code session transcript for this project (~/.claude/projects/<project>/*.jsonl) for the string git stash — zero matches. The stash was created by the harness around the branch switch, not as a visible tool call. The stash commit objects carry the user's normal configured git identity, so it shells out git as the user.

Why this is a problem

  • --include-untracked captures files the user never asked git to manage — local assets, scratch files, build outputs — which silently vanish from the working tree on a branch switch.
  • The stash is not surfaced to the user — there is no notice that a stash was created or that files were moved into it. It looks like data loss.
  • With a folder-syncing client (OneDrive/Dropbox/iCloud) on the working tree, the local "deletion" propagates to the cloud, compounding the appearance of loss.
  • It's easy to hit when multiple sessions operate on a single checkout and switch branches.

Expected behavior (any of)

  1. Don't auto-stash untracked files — limit any automatic stash to tracked changes (plain git stash, no -u), or skip auto-stash entirely.
  2. Surface it — if the harness stashes, tell the user explicitly (e.g. "stashed N files including untracked as stash@{0} before switching branches") and how to restore.
  3. Make it configurable — a settings.json flag to disable auto-stash and/or exclude untracked files.

Questions

  • Is this auto-stash an intended feature? What is it called internally? (A codename appears in the stash message; is that the mechanism?)
  • Is there an existing setting to disable it, or to stop it from including untracked files? I could not find one in the settings docs.

Environment

  • Claude Code version: 2.1.161
  • OS: Windows 11
  • Working tree is inside a folder synced by a cloud client (OneDrive)
  • Repo worked on by multiple concurrent Claude Code sessions, switching branches in a shared checkout

Related

  • #20001 — "Auto-detect and restore git stashes when switching branches" (related but the inverse: that asks for restore; this asks to not silently sweep untracked files in the first place).

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗