Skip to content

apply_patch edits primary worktree instead of selected Git worktree #52885

Open

Description

@svejda-cz

What version of Codex CLI is running?

codex-cli 0.162.1

What subscription do you have?

ChatGPT Pro

Which model were you using?

GPT-5.6-Terra medium

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

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

Windows PowerShell (PowerShell host on Windows)

Codex doctor report

{
  "schemaVersion": 1,
  "generatedAt": "<redacted>",
  "overallStatus": "fail",
  "codexVersion": "0.162.1",
  "checks": {
    "app_server.status": {
      "id": "app_server.status",
      "category": "app-server",
      "status": "ok",
      "summary": "background server is running",
      "details": {
        "app-server version": "0.162.1",
        "control socket": "C:\\Users\\<USER>\\.codex\\app-server-control\\app-server-control.sock",
        "daemon state dir": "C:\\Users\\<USER>\\.codex\\app-server-daemon",
        "dedicated pid file": "C:\\Users\\<USER>\\.codex\\app-server-daemon\\daemon.pid (file)",
        "dedicated update-loop pid file": "C:\\Users\\<USER>\\.codex\\app-server-daemon\\daemon-updater.pid (file)",
        "mode": "ephemeral",
        "pid file": "C:\\Users\\<USER>\\.codex\\app-server-daemon\\app-server.pid (missing)",
        "settings": "C:\\Users\\<USER>\\.codex\\app-server-daemon\\settings.json (missing)",
        "status": "running",
        "update-loop pid file": "C:\\Users\\<USER>\\.codex\\app-server-daemon\\app-server-updater.pid (missing)"
      },
      "remediation": null,
      "durationMs": 44
    },
    "auth.credentials": {
      "id": "auth.credentials",
      "category": "auth",
      "status": "ok",
      "summary": "auth is configured",
      "details": {
        "auth file": "C:\\Users\\<USER>\\.codex\\auth.json",
        "auth storage mode": "File",
        "stored API key": "false",
        "stored ChatGPT tokens": "true",
        "stored agent identity": "false",
        "stored auth mode": "chatgpt"
      },
      "remediation": null,
      "durationMs": 0
    },
    "config.load": {
      "id": "config.load",
      "category": "config",
      "status": "ok",
      "summary": "config loaded",
      "details": {
        "CODEX_HOME": "C:\\Users\\<USER>\\.codex",
        "active thread overrides": "not inspected",
        "config.toml": "C:\\Users\\<USER>\\.codex\\config.toml",
        "config.toml parse": "ok",
        "configuration load ms": "117",
        "configuration scope": "invocation config, including cloud-managed policy",
        "configured TUI mode": "fullscreen",
        "cwd": "C:\\Users\\<USER>\\Projects\\<PROJECT>",
        "enabled feature flags": "<redacted>",
        "feature flag overrides": "memories=true",
        "feature flags enabled": "59",
        "log dir": "C:\\Users\\<USER>\\.codex\\log",
        "mcp servers": "2",
        "model": "gpt-5.6-terra",
        "model provider": "openai",
        "sqlite home": "C:\\Users\\<USER>\\.codex"
      },
      "remediation": null,
      "durationMs": 0
    },
    "git.environment": {
      "id": "git.environment",
      "category": "git",
      "status": "ok",
      "summary": "git executable found; execution not verified",
      "details": {
        ".git entry": "directory",
        "PATH git #1": "C:\\Program Files\\Git\\cmd\\git.exe",
        "PATH git entries": "1",
        "git execution": "not inspected (PATH helpers are not executed)",
        "repo detected": "true",
        "repo root": "C:\\Users\\<USER>\\Projects\\<PROJECT>",
        "selected git": "C:\\Program Files\\Git\\cmd\\git.exe"
      },
      "remediation": null,
      "durationMs": 24
    },
    "git.worktree.dev_drive": {
      "id": "git.worktree.dev_drive",
      "category": "git",
      "status": "warning",
      "summary": "this worktree is not on a Windows Dev Drive; moving it to a trusted Dev Drive can significantly improve repository and filesystem performance",
      "details": {},
      "remediation": "create a trusted Windows Dev Drive for source repositories: https://learn.microsoft.com/en-us/<redacted>",
      "durationMs": 1
    },
    "installation": {
      "id": "installation",
      "category": "install",
      "status": "ok",
      "summary": "installation looks consistent",
      "details": {
        "PATH codex #1": "C:\\Users\\<USER>\\AppData\\Roaming\\npm\\codex.cmd",
        "current executable": "C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\bin\\codex.exe",
        "install context": "npm (package C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc, bin C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\bin, resources C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\codex-resources, path C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\codex-path)",
        "managed by Vite+": "false",
        "managed by bun": "false",
        "managed by npm": "true",
        "managed by pnpm": "false",
        "managed package root": "C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex",
        "npm update target": "not inspected (PATH helpers are not executed)"
      },
      "remediation": null,
      "durationMs": 34
    },
    "mcp.config": {
      "id": "mcp.config",
      "category": "mcp",
      "status": "ok",
      "summary": "MCP configuration is locally consistent",
      "details": {
        "configured servers": "2",
        "disabled servers": "0",
        "stdio servers": "1",
        "streamable_http servers": "1"
      },
      "remediation": null,
      "durationMs": 252
    },
    "network.env": {
      "id": "network.env",
      "category": "network",
      "status": "ok",
      "summary": "network-related environment looks readable",
      "details": {
        "managed proxy": "not configured",
        "proxy env vars": "none",
        "respect system proxy": "disabled"
      },
      "remediation": null,
      "durationMs": 0
    },
    "network.provider_reachability": {
      "id": "network.provider_reachability",
      "category": "reachability",
      "status": "ok",
      "summary": "active provider endpoints are reachable over HTTP",
      "details": {
        "ChatGPT inference URL": "https://chatgpt.com/backend-api/<redacted> reachable (HTTP 405)",
        "reachability mode": "ChatGPT auth"
      },
      "remediation": null,
      "durationMs": 250
    },
    "network.websocket_reachability": {
      "id": "network.websocket_reachability",
      "category": "websocket",
      "status": "ok",
      "summary": "Responses WebSocket handshake succeeded",
      "details": {
        "DNS": "2 IPv4, 0 IPv6, first IPv4",
        "auth mode": "chatgpt",
        "connect timeout": "15000 ms",
        "endpoint": "wss://chatgpt.com/backend-api/<redacted>",
        "handshake result": "HTTP 101 Switching Protocols",
        "model provider": "openai",
        "provider name": "OpenAI",
        "proxy env vars": "none",
        "reasoning header": "false",
        "server model present": "false",
        "supports websockets": "true",
        "wire API": "responses"
      },
      "remediation": null,
      "durationMs": 771
    },
    "runtime.provenance": {
      "id": "runtime.provenance",
      "category": "runtime",
      "status": "ok",
      "summary": "running npm on windows-x86_64",
      "details": {
        "commit": "unknown",
        "current executable": "C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\bin\\codex.exe",
        "install method": "npm (package C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc, bin C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\bin, resources C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\codex-resources, path C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\codex-path)",
        "platform": "windows-x86_64",
        "version": "0.162.1"
      },
      "remediation": null,
      "durationMs": 1
    },
    "runtime.search": {
      "id": "runtime.search",
      "category": "search",
      "status": "ok",
      "summary": "search command found (bundled); execution not verified",
      "details": {
        "search command": "C:\\Users\\<USER>\\AppData\\Roaming\\npm\\node_modules\\@openai\\codex\\node_modules\\@openai\\codex-win32-x64\\vendor\\x86_64-pc-windows-msvc\\codex-path\\rg.exe",
        "search command readiness": "file exists",
        "search provider": "bundled"
      },
      "remediation": null,
      "durationMs": 0
    },
    "sandbox.filesystem_paths": {
      "id": "sandbox.filesystem_paths",
      "category": "sandbox",
      "status": "ok",
      "summary": "no explicit filesystem paths to probe",
      "details": {},
      "remediation": null,
      "durationMs": 2
    },
    "sandbox.helpers": {
      "id": "sandbox.helpers",
      "category": "sandbox",
      "status": "fail",
      "summary": "elevated Windows sandbox provisioning recorded a structured failure",
      "details": {
        "approval policy": "OnRequest",
        "codex-linux-sandbox helper": "none",
        "denied-read glob rules": "0",
        "denied-read restrictions": "false",
        "denied-read rules": "0",
        "error code": "helper_unknown_error",
        "execve wrapper helper": "none",
        "filesystem sandbox": "restricted",
        "glob scan max depth": "unbounded",
        "managed filesystem source": "none",
        "network sandbox": "restricted",
        "sandbox backend": "elevated",
        "sandbox provisioning": "failed"
      },
      "issues": [
        {
          "severity": "fail",
          "cause": "elevated Windows sandbox provisioning recorded a structured failure",
          "measured": "helper_unknown_error",
          "expected": null,
          "remedy": "repair or reinstall the Codex CLI from an approved distribution",
          "fields": [
            "error code"
          ]
        }
      ],
      "remediation": "repair or reinstall the Codex CLI from an approved distribution",
      "durationMs": 3
    },
    "state.paths": {
      "id": "state.paths",
      "category": "state",
      "status": "ok",
      "summary": "state paths and databases are inspectable",
      "details": {
        "CODEX_HOME": "C:\\Users\\<USER>\\.codex (dir)",
        "active rollout files": "<redacted>",
        "archived rollout files": "<redacted>",
        "goals DB": "C:\\Users\\<USER>\\.codex\\goals_1.sqlite (file)",
        "goals DB integrity": "ok",
        "log DB": "C:\\Users\\<USER>\\.codex\\logs_2.sqlite (file)",
        "log DB integrity": "ok",
        "log dir": "C:\\Users\\<USER>\\.codex\\log (missing)",
        "memories DB": "C:\\Users\\<USER>\\.codex\\memories_1.sqlite (file)",
        "memories DB integrity": "ok",
        "memories v2 DB": "C:\\Users\\<USER>\\.codex\\memories_v2_1.sqlite (missing)",
        "memories v2 DB integrity": "skipped (missing)",
        "queue DB": "C:\\Users\\<USER>\\.codex\\queue_1.sqlite (file)",
        "queue DB integrity": "ok",
        "sqlite home": "C:\\Users\\<USER>\\.codex (dir)",
        "state DB": "C:\\Users\\<USER>\\.codex\\state_5.sqlite (file)",
        "state DB integrity": "ok",
        "thread history DB": "C:\\Users\\<USER>\\.codex\\thread_history_1.sqlite (file)",
        "thread history DB integrity": "ok"
      },
      "remediation": null,
      "durationMs": 8555
    },
    "state.rollout_db_parity": {
      "id": "state.rollout_db_parity",
      "category": "threads",
      "status": "ok",
      "summary": "rollout files and state DB thread inventory agree",
      "details": {
        "default model provider": "openai",
        "rollout DB active files": "<redacted>",
        "rollout DB active rows": "<redacted>",
        "rollout DB archive mismatches": "0",
        "rollout DB archived files": "<redacted>",
        "rollout DB archived rows": "<redacted>",
        "rollout DB duplicate DB paths": "0",
        "rollout DB duplicate rollout thread ids": "0",
        "rollout DB malformed file names": "0",
        "rollout DB missing active rows": "0",
        "rollout DB missing archived rows": "0",
        "rollout DB model providers": "<redacted>",
        "rollout DB rows": "<redacted>",
        "rollout DB scan cap reached": "false",
        "rollout DB scan errors": "0",
        "rollout DB sources": "<redacted>",
        "rollout DB stale rows": "0"
      },
      "remediation": null,
      "durationMs": 1672
    },
    "system.disk": {
      "id": "system.disk",
      "category": "disk",
      "status": "ok",
      "summary": "sufficient free disk space (23.0 GiB)",
      "details": {
        "CODEX_HOME available": "23.0 GiB",
        "failure threshold": "1.0 GiB",
        "warning threshold": "5.0 GiB",
        "worktree available": "23.0 GiB"
      },
      "remediation": null,
      "durationMs": 0
    },
    "system.environment": {
      "id": "system.environment",
      "category": "system",
      "status": "ok",
      "summary": "OS language en-GB",
      "details": {
        "EDITOR": "not set",
        "VISUAL": "not set",
        "os": "Windows 10.0.26200 (Windows 11 Professional) [64-bit]",
        "os language": "en-GB",
        "os type": "Windows",
        "os version": "10.0.26200"
      },
      "remediation": null,
      "durationMs": 3
    },
    "terminal.env": {
      "id": "terminal.env",
      "category": "terminal",
      "status": "ok",
      "summary": "terminal metadata was detected",
      "details": {
        "WT_SESSION": "present",
        "color output": "enabled",
        "console input code page": "852",
        "console output code page": "852",
        "stderr console mode": "0x00000007 (VT processing: true)",
        "stderr is terminal": "true",
        "stdin is terminal": "true",
        "stdout console mode": "0x00000007 (VT processing: true)",
        "stdout is terminal": "true",
        "terminal": "Windows Terminal",
        "terminal size": "120x30"
      },
      "remediation": null,
      "durationMs": 2
    },
    "terminal.title": {
      "id": "terminal.title",
      "category": "title",
      "status": "ok",
      "summary": "terminal title default",
      "details": {
        "terminal title activity": "true",
        "terminal title items": "activity, project-name",
        "terminal title project source": "git repo root",
        "terminal title project value": "<PROJECT>",
        "terminal title source": "default"
      },
      "remediation": null,
      "durationMs": 0
    },
    "updates.status": {
      "id": "updates.status",
      "category": "updates",
      "status": "ok",
      "summary": "update configuration is locally consistent",
      "details": {
        "cached latest version": "0.162.1",
        "check for update on startup": "true",
        "last checked at": "<redacted>",
        "latest version": "0.162.1",
        "latest version status": "current version is not older",
        "npm update target": "not inspected (PATH helpers are not executed)",
        "update action": "npm install -g @openai/codex",
        "version cache": "C:\\Users\\<USER>\\.codex\\version.json"
      },
      "remediation": null,
      "durationMs": 363
    }
  }
}

What issue are you seeing?

Feedback: apply_patch did not honor the selected worktree

Summary

In a repository with multiple Git worktrees, the patch-editing interface wrote
to the primary shared worktree instead of the explicitly selected external
worktree. This can put unrelated work at risk when multiple agents or users
work concurrently.

Environment

  • Windows host, PowerShell shell
  • One Git repository with a primary worktree and a separately created external
    worktree on a feature branch
  • Multi-agent session with a shared filesystem

Steps to reproduce

  1. Start in a Git repository whose primary worktree is on develop.
  2. Create a separate worktree at another absolute path and check out a feature
    branch there.
  3. Request an edit using the patch-editing interface while the task's selected
    working directory is the external worktree.
  4. Inspect git status in both worktrees.

Expected result

The patch is applied only in the selected external worktree. The primary
worktree remains unchanged.

Actual result

The edit appeared in the primary shared worktree. The external worktree stayed
clean. The discrepancy was detected before further edits, so no unrelated work
was overwritten.

Impact

This is especially risky when:

  • another agent owns changes in the primary worktree;
  • a user intentionally isolates work on a feature branch; or
  • an agent assumes the patch tool follows its command working directory.

It can lead to edits being committed from the wrong branch or colliding with
parallel work.

Safe workaround used

Before continuing, verify git status and branch identity in both worktrees.
If the external worktree is clean and the changes are known to be only the
current task's edits, remove the unused external worktree and switch the
primary checkout to the intended feature branch. Do not continue editing until
the destination is unambiguous.

Requested behavior

Make the patch-editing interface honor the active task worktree / selected
working directory, or expose an explicit target-worktree parameter. If that is
not possible, fail safely when multiple worktrees exist instead of silently
editing the primary worktree.

What steps can reproduce the bug?

Uploaded thread: 01a123fb-6104-7122-b37f-f7671468ba53

What is the expected behavior?

No response

Additional information

No response

Activity

  1. added
    CLIIssues related to the Codex CLI
    windows-osIssues related to Codex on Windows systems
    tool-callsIssues related to tool calling
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIbugSomething isn't workingtool-callsIssues related to tool callingwindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions