The Mysterious Git Reset Mechanism Behind Claude Code
Claude Code silently resets uncommitted changes every 10 minutes, leaving only tracked files intact. An investigation reveals a programmatic reset mechanism tied to session start times.
Every 10 minutes, Claude Code performs an automated git fetch origin + git reset --hard origin/main, silently destroying uncommitted changes to tracked files. This feature has been observed across multiple sessions and repositories over several days, raising questions about its purpose and the underlying mechanism.
The Silent Reset Mechanism
This process is not initiated by an external Git binary but rather through programmatic operations within Claude Code itself. Each session begins with a consistent offset that varies between 08 seconds to 41 seconds, confirming it's tied to the start time of each session and executed every 600 seconds thereafter.
During these resets, only tracked files are affected; untracked files remain untouched. Git worktrees appear immune from this operation, suggesting a selective approach that targets specific parts of the repository structure. The reset specifically impacts the main working tree while leaving other trees intact, as evidenced by their reflog entries showing no such actions.
Investigating the Mechanism
The investigation into Claude Code's auto-reset feature involved several steps to rule out external influences:
- Capture of Reset Events: Using fswatch on .git/, we captured events precisely at reset times, confirming that these resets are indeed programmatic and not initiated by an external Git binary.
- Process Monitoring: Process monitoring tools revealed no other git processes running around the time of resets. The operation is performed within Claude Code's own process using libgit2 or a similar library, as evidenced by lock file creation in .git/ without any additional external activity.
- CWD Verification: lsof confirmed that only one process with CWD (current working directory) set to the affected repository was running. This is Claude Code's CLI session, which uses a command like `claude --dangerously-skip-permissions` for this operation.
The compiled binary at /opt/homebrew/Caskroom/claude-code/2.1.87/claude further supports the idea that these resets are an internal feature of Claude Code, not influenced by external factors or user actions within a session.
Impact on Workflow and Development
The impact of this auto-reset mechanism can be significant for developers who rely heavily on uncommitted changes. Changes made in the main working tree must be committed every 10 minutes to avoid being lost, which could disrupt development workflows significantly if not anticipated.
This feature also makes it appear as though issues are intermittent when all changes are committed, leading users to believe that their projects might have been affected by external factors. The lack of a visible mechanism from the outside adds an extra layer of complexity in troubleshooting and understanding the true nature of these resets.
Recommended for you




