openai / openai/codex

Windows CLI: command runner ignores session cwd and executes in a different repository

Open
#42,797 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug CLI tool-calls windows-os
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

Summary

On Windows, Codex CLI starts in the correct directory and reports the correct session working directory, but shell/tool commands execute from a different Git repository.

This is dangerous because the UI/session context appears correct while commands such as git status, tests, file operations, etc. can run against the wrong checkout.

Environment

  • Codex CLI: 0.153.2
  • OS: Windows 11 x64
  • Shell: PowerShell 7
  • Installation: npm (@openai/codex)
  • Git: 2.53.0.windows.1
  • Background app server: not running (codex doctor --json reports ephemeral / not running)

All paths below are anonymized.

Reproduction

Assume two local checkouts:

C:\Users\<user>\dev\repo
C:\Users\<user>\workspaces\repo-copy

From PowerShell:

cd C:\Users\<user>\workspaces\repo-copy
git status --short --branch
codex

Before starting Codex, PowerShell is correctly in repo-copy.

Codex UI also shows repo-copy as the active directory.

Inside Codex:

/pwd

reports:

C:\Users\<user>\workspaces\repo-copy

But asking Codex to run:

Run Get-Location and git status --short --branch. Do not modify anything.

produces:

Get-Location:
C:\Users\<user>\dev\repo

git status:
## main...origin/main

So the session/TUI cwd and the command runner cwd disagree.

Important: reproduces outside Git worktrees

The issue was first observed in a linked Git worktree, but it also reproduces in a separate normal clone.

Therefore this does not appear to be specific to Git linked worktrees.

Diagnostics

A sanitized codex doctor --json confirms that Codex initialization sees the correct checkout before the turn starts:

config.load.cwd:
C:\Users\<user>\workspaces\repo-copy

git.environment.repo root:
C:\Users\<user>\workspaces\repo-copy

git.environment.git branch:
<expected branch>

app_server.status:
background server is not running

The wrong cwd only becomes visible when Codex executes shell/tool commands.

Variants tested

The same wrong command-runner cwd occurs with:

  • normal codex
  • codex --sandbox danger-full-access
  • codex --yolo
  • codex -c 'model_reasoning_effort="medium"'
  • codex -c 'windows.sandbox="unelevated"'

Changing sandbox mode does not fix the problem.

Expected behavior

If Codex is launched from:

C:\Users\<user>\workspaces\repo-copy

and /pwd reports that directory, every shell/tool command should inherit or explicitly use that same cwd.

If the command runner cannot honor the session cwd, it should fail closed rather than silently execute in another repository.

Actual behavior

The UI and /pwd report the requested checkout, while the command runner executes in another existing repository.

This can cause commands to read, test, stage, commit, or modify the wrong repository/branch.

Related

#42001 reports a similar symptom in Codex Desktop where an explicit project cwd is ignored and commands run from a stale directory. This report is for Codex CLI 0.153.2 on Windows and reproduces without the Desktop app running.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the Windows CLI initializes the session cwd, reports it through /pwd, and passes it to the shell/tool command runner. Reproduce from PowerShell with Get-Location and git status --short --branch; done means commands run in the reported checkout or fail closed when that cwd cannot be honored.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.