Unable to use git even with workspace-write
Resolved 💬 5 comments Opened Oct 10, 2025 by gcp Closed Oct 10, 2025
💡 Likely answer: A maintainer (nornagon-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
codex-cli 0.46.0
Which model were you using?
gpt-5-codex
What platform is your computer?
Darwin 25.0.0 arm64 arm
What steps can reproduce the bug?
codex -s workspace-write
› Move the last 2 commits to a branch called "codex-rackleave".
• Explored
└ List heads
• Ran git branch --show-current
└ master
• Ran git checkout codex-rackleave
└ failed in sandbox: fatal: Unable to create '/Users/morbo/git/scrax/.git/index.lock': Operation not permitted
• I'm exploring why git can't create the index.lock file, likely due to system-level restrictions such as immutable flags or
extended attributes on the .git directory or its files, which blocks changing branches or modifying the index. I'll check
further with xattr -l .git to see if any attributes prevent write operations despite chmod changes.
And so on, while the model tries to debug why it can't write things.
What is the expected behavior?
Writing to .git should work.
What do you see instead?
_No response_
Additional information
_No response_
5 Comments
This is probably functioning as intended, see:
https://github.com/openai/codex/commit/80555d4ff25b8d7af34be207436c786de4fbaf71
I suspect this decision was made because agents have been known to inadvertently blow away entire projects, and we probably don't want them to take the .git folder with it.
@chall37 is correct. Eventually we will have more fine-grained control over the sandbox, but for now if you want write access to .git you'll need to pass
--dangerously-bypass-approvals-and-sandbox.With the competition (ahem) this would generate a request for approval to the user, who can then sanity check the git command.
I was able to fix this problem by telling codex to escalate any write operations on Git. That disables the sandbox protection and allows the commits to go through.
Codex should add that to their system prompt.
@nornagon-openai and others,
Instead of elevating permissions, we can create a separate shadow git directory for codex to commit changes to.
Here is a script that allows this.
https://github.com/dmahurin/git-shadow/blob/main/mk-git-shadow
This script creates a new git-dir using object alternates to inherit form the existing .git and a worktree which points back to the current directory.
Use:
mk-git-shadow .aigit
GIT_DIR=
pwd/.aigit npx @openai/codex ...Then review and pull:
git --git-dir .aigit log
git pull .aigit