codex - 💡(How to fix) Fix Codex runs git add and git commit in parallel, causing index.lock errors [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#17482Fetched 2026-04-12 13:27:55
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2closed ×1unlabeled ×1

Error Message

When Codex tried to commit changes, the commit failed with a Git index.lock error. 4. The git commit command fails with an index.lock error. The error was:

Root Cause

In this case, the lock file was removed automatically, so retrying the commit succeeded. Because of that, this is not always a blocking problem in practice, but it does interrupt the workflow and produces avoidable Git errors.

Code Example

fatal: Unable to create '/path/to/repo/.git/index.lock': File exists.

Another git process seems to be running in this repository...
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.120.0

What subscription do you have?

ChatGPT Plus

Which model were you using?

gpt-5.4

What platform is your computer?

Darwin 25.3.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

VSCode

What issue are you seeing?

When Codex tried to commit changes, the commit failed with a Git index.lock error.

What steps can reproduce the bug?

  1. Open a Git repository with modified files.
  2. Ask Codex to commit the current changes.
  3. Codex invokes git add ... and git commit -m "..." in parallel.
  4. The git commit command fails with an index.lock error.

What is the expected behavior?

Codex should run Git write operations sequentially, not in parallel.

For example:

  1. git add
  2. wait for completion
  3. git commit
  4. wait for completion
  5. git push

Additional information

In my experience, this happens frequently.

In this case, the lock file was removed automatically, so retrying the commit succeeded. Because of that, this is not always a blocking problem in practice, but it does interrupt the workflow and produces avoidable Git errors.

The error was:

fatal: Unable to create '/path/to/repo/.git/index.lock': File exists.

Another git process seems to be running in this repository...

extent analysis

TL;DR

Run Git commands sequentially to avoid the index.lock error.

Guidance

  • The error occurs because Codex invokes git add and git commit in parallel, causing a conflict over the Git index lock.
  • To fix this, ensure that Git commands are executed one after the other, waiting for each command to complete before running the next one.
  • Modify the Codex workflow to run git add, wait for its completion, then run git commit, and finally git push after the commit is successful.
  • Consider adding a retry mechanism with a delay to handle cases where the lock file is temporarily present.

Example

git add .
wait
git commit -m "commit message"
wait
git push

Notes

This solution assumes that the issue is solely due to the parallel execution of Git commands. Other factors, such as concurrent Git processes or system issues, might also contribute to the problem.

Recommendation

Apply workaround: Run Git commands sequentially to avoid the index.lock error, as this approach directly addresses the identified cause of the problem and can be implemented without waiting for a potential fix in the Codex CLI.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING