codex - 💡(How to fix) Fix Agent runtime CWD/worktree is not rebound when navigating between project chats [5 comments, 3 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#20725Fetched 2026-05-03 04:46:44
View on GitHub
Comments
5
Participants
3
Timeline
10
Reactions
0
Author
Timeline (top)
commented ×5labeled ×5

Error Message

  1. Warn when the visible project does not match the runtime CWD.

Root Cause

This is especially dangerous in agent workflows because the assistant may autonomously edit files, run commands, configure tooling, inspect Git state, or use business-domain context based on the stale CWD.

RAW_BUFFERClick to expand / collapse

Title: Agent runtime CWD/worktree is not rebound when navigating between project chats

Severity: High / data integrity and business-context integrity risk

When working across multiple projects, clicking into an existing chat under a different project does not appear to update the agent tool runtime CWD. The UI can indicate I am in one project, but shell/tool calls may still execute from a previous project’s repo.

In my case, I was navigating between projects including:

  • MyAISpeakEasy
  • Eventryx
  • ArticleMngrSLN

But the agent runtime still reported and operated from:

C:\Users\Richard\source\repos\MyAISpeakEasy

Expected: When I open or switch to a chat associated with a project, the agent runtime CWD should be rebound to that project’s workspace/repo. The visible project context, chat context, runtime CWD, Git worktree root, and project-scoped tool context should all match.

Actual: The visible project/chat context can differ from the shell/tool CWD. This means I may believe I am working in Eventryx or ArticleMngrSLN, while agent commands, file operations, Git operations, and project-scoped tooling are still targeting MyAISpeakEasy.

Why this matters: Each project has its own CWD and Git worktree. If project navigation changes the visible context but not the runtime CWD, generated files, configuration changes, setup scripts, git status checks, staging, commits, or other repo-affecting operations can silently affect the wrong repository.

This also affects project-scoped tools. For example, the ContentTraker plugin relies on the current working directory to associate a local project/repo with a ContentTraker workspace. That ContentTraker workspace represents the business-domain knowledge for the application.

If the runtime CWD is stale, ContentTraker setup or lookup operations can associate the wrong application with the wrong ContentTraker workspace, or retrieve business-domain context for the wrong project. That can lead the agent to reason from incorrect domain knowledge while making code or configuration changes.

This is especially dangerous in agent workflows because the assistant may autonomously edit files, run commands, configure tooling, inspect Git state, or use business-domain context based on the stale CWD.

Suggested invariant: Chat/project context == agent runtime CWD == Git worktree root == project-scoped tool context

Suggested fixes:

  1. Rebind the agent runtime CWD whenever a chat/project is opened.
  2. If an existing runtime cannot be safely rebound, block tool execution and require a new runtime/session for that project.
  3. Clearly display the active runtime CWD near the chat/tool area.
  4. Warn when the visible project does not match the runtime CWD.
  5. Before file, Git, or project-scoped tool operations, automatically verify:
    • pwd
    • git rev-parse --show-toplevel
    • any project binding file used by the tool, such as .contenttraker/project-binding.json
  6. Prevent staging, commits, setup scripts, file edits, and project-scoped tool setup/lookups when the runtime worktree does not match the visible project.

Repro:

  1. Open a chat in Project A, for example MyAISpeakEasy.
  2. Confirm the runtime CWD with pwd or git rev-parse --show-toplevel.
  3. Navigate to an existing chat under Project B, for example Eventryx or ArticleMngrSLN.
  4. Ask the agent to report CWD or run a repo-specific/project-scoped command.
  5. Observe that the runtime may still be in Project A, despite the UI showing Project B.

Impact: High. This can cause incorrect file edits, dirty worktrees in unrelated repos, accidental setup/configuration in the wrong project, accidental staging or commits from the wrong repository, incorrect ContentTraker workspace association, and incorrect business-domain context being used during agent work.

Concrete example: A ContentTraker configuration/readiness check was requested while I believed I was working in another project context, but the runtime CWD was still:

C:\Users\Richard\source\repos\MyAISpeakEasy

Because ContentTraker uses the current working directory and .contenttraker/project-binding.json to associate a repo with the application’s business-domain workspace, the operation targeted the MyAISpeakEasy project context rather than the intended project.

extent analysis

TL;DR

Rebinding the agent runtime CWD whenever a chat/project is opened is likely the most effective fix to ensure data integrity and business-context integrity.

Guidance

  • Verify the current working directory (CWD) and Git worktree root after navigating to a different project to confirm the issue.
  • Implement a check to ensure the visible project context matches the runtime CWD before executing any file, Git, or project-scoped tool operations.
  • Consider displaying the active runtime CWD near the chat/tool area to provide visual feedback and warn when the visible project does not match the runtime CWD.
  • Review the suggested fixes, such as rebinding the agent runtime CWD or blocking tool execution when the runtime cannot be safely rebound, to determine the best approach for the specific use case.

Example

No code snippet is provided as the issue description does not include specific code references.

Notes

The issue highlights the importance of ensuring the agent runtime CWD is correctly updated when navigating between projects to prevent data integrity and business-context integrity risks. The suggested fixes and guidance provided aim to help mitigate this issue, but the specific implementation details may vary depending on the underlying system architecture and requirements.

Recommendation

Apply a workaround to rebind the agent runtime CWD whenever a chat/project is opened, as this is likely to be the most effective fix to ensure data integrity and business-context integrity. This approach will help prevent incorrect file edits, dirty worktrees in unrelated repos, and accidental setup/configuration in the wrong project.

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