Codex VSCode extension corrupts git repositories with `fatal: unable to read sha` and `fatal: Unable to create '.../.git/worktrees/foo/index.lock': File exists.`

Open 💬 2 comments Opened May 8, 2026 by eregon
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the IDE extension are you using?

26.506.31004

What subscription do you have?

Plus

Which IDE are you using?

VS Code

What platform is your computer?

Linux 6.19.14-200.fc43.x86_64 x86_64 unknown

What issue are you seeing?

See repro.

What steps can reproduce the bug?

Repro:

  1. Use a git worktree (I'm using https://github.com/truffleruby/truffleruby a reasonable-size but not small git repository)
  2. Configure:

git config --global core.editor 'code --wait'

  1. Ensure VS Code is not already running
  2. Run:

git commit enter a message in VSCode, quit with with e.g. Ctrl+W. Might happen more often when not taking long to write the commit message, and maybe also happens more with a larger git repository.

  1. Observe:

fatal: unable to read <sha>
or:
fatal: Unable to create .../.git/worktrees/.../index.lock

Observations:

  • Happens only on VS Code cold start, if VS Code is already running it seems fine
  • git reset --hard HEAD seems to fix the git repository, or rm .../.git/worktrees/.../index.lock
  • code --wait --disable-extensions --reuse-window fixes it
  • Bisected to Codex extension, does not happen with the Codex extension disabled, happens more than half the tries with Codex extension enabled.

A workaround is export EDITOR='code --wait --disable-extensions --new-window' to disable all extensions, or disabling or uninstalling the Codex extension.

A possible cause might be that the Codex extension auto-refresh/git operations are racing on the worktree index during editor startup.

What is the expected behavior?

I would expect the Codex extension to never corrupt my git repository.

Also I expect the Codex extension does not do anything until I start using it, e.g. by opening the Codex chat panel and writing in it.

Additional information

_No response_

View original on GitHub ↗

2 Comments

github-actions[bot] contributor · 3 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #20567
  • #20933

Powered by Codex Action

geogiam-net · 1 month ago

I purchased both Codex (desktop app) and Github Copilot (vs) for 1 month testing, both corrupt my local repositories, even for a simple task of reading other classes a fill me up some comments in 1 file.
With Claude, I never have this issue neither my collegues.