openai / openai/codex

IDE: Select new chat working directory from active file in multi-root workspaces

Open
#44,863 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug extension session
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

What version of the IDE extension are you using?

26.908.31748 (openai.chatgpt, darwin-arm64)

What subscription do you have?

Not included; this report concerns local workspace selection before the request is sent.

Which IDE are you using?

Cursor, with two Git repositories in one multi-root workspace.

What platform is your computer?

macOS, Apple Silicon (Darwin 25.6.0 arm64 arm).

What issue are you seeing?

New Codex chats start in the first workspace folder even when the active editor file belongs to another workspace folder. This affects the actual session working directory and the repository instructions loaded at startup, not just the project name shown in a response.

For example, with workspace roots ordered as repo-a, repo-b, starting a new chat while a file in repo-b is selected still starts the session in repo-a and loads its root AGENTS.md.

Both repositories remain available as workspace roots. Attaching a file from repo-b, or adding a personal instruction to infer the intended repository from that file, can make the assistant work in repo-b, but does not correct the session's initial working directory or startup instruction selection.

What steps can reproduce the bug?
  1. Open a multi-root Cursor workspace with two Git repositories, repo-a first and repo-b second.
  2. Give each repository a distinct root AGENTS.md so startup instruction selection is easy to distinguish.
  3. Select a file in repo-b in the editor.
  4. Start a new Codex sidebar chat.
  5. Ask: "What is your actual session working directory, and which repository instructions were loaded at startup? Don't infer the project from attached files."
  6. Observe that the session reports repo-a and its root instructions despite the selected file belonging to repo-b.
What is the expected behavior?

A new chat should use the workspace folder containing the active editor file as its starting directory, or provide a setting to enable that behavior. The matching repository instructions and project configuration should be selected before the session starts.

Moving focus into the sidebar should retain the last valid editor workspace selection. Existing chats should retain their saved directory when the active editor changes. With no valid editor selection, fall back to the normal workspace default.

Local workaround and verified results

We tested a local patch to the installed extension's out/extension.js, after backing up the original bundle. This is a temporary, version-specific workaround, not a supported setting. Extension updates can overwrite it.

In this version, the extension builds one workspace project from the ordered workspace roots, and the webview uses rootPaths[0] as the default directory. The patch makes two changes:

  1. In the workspace-root collection function (aS in this particular bundle), use window.activeTextEditor and workspace.getWorkspaceFolder(editor.document.uri) to identify the active file's workspace folder. Move that root to the front of the returned array, retaining all other roots. Keep the last valid root when editor focus disappears.
  2. Subscribe to window.onDidChangeActiveTextEditor. When the selected workspace root changes, send the same global-state-updated notification already used for workspace-folder changes, invalidating LOCAL_PROJECTS and SELECTED_PROJECT.

Source-level sketch of the selection logic, with the bundle's existing path filtering and platform conversion omitted:

let lastEditorRoot: string | undefined;

function captureEditorRoot(editor: vscode.TextEditor | undefined) {
  const uri = editor?.document.uri;
  const root = uri
    ? vscode.workspace.getWorkspaceFolder(uri)?.uri.fsPath
    : undefined;

  if (root != null) lastEditorRoot = root;
  return lastEditorRoot;
}

function orderedWorkspaceRoots() {
  const roots = (vscode.workspace.workspaceFolders ?? [])
    .map(folder => folder.uri.fsPath);
  const root = captureEditorRoot(vscode.window.activeTextEditor);
  const index = root == null ? -1 : roots.indexOf(root);
  if (index > 0) roots.unshift(roots.splice(index, 1)[0]);
  return roots;
}

After applying the patch and running Developer: Reload Window, we tested fresh chats from files in each repository:

Selected file Actual session working directory Root instructions loaded at startup
File in repo-a repo-a Personal overrides + repo-a AGENTS.md
File in repo-b repo-b Personal overrides + repo-b AGENTS.md

The user checked both results against the new chats' reported environment_context and startup instruction blocks, rather than asking the assistant to infer the project from attachments. Both workspace roots remained available.

The patched bundle passed node --check. Focused checks also passed for default selection, switching between roots, retaining selection on sidebar focus, a file outside the workspace, and removal of the previously selected folder.

Not yet verified end-to-end: existing-chat stability after changing the editor selection, or the effective project config.toml layers. The local source inspection shows existing conversation cwd takes precedence over the new-chat default, but that should receive a regression test in a proper implementation. The temporary patch also reorders the roots used to derive the workspace project's ID; an upstream fix should account for project identity and history behavior explicitly.

To undo the local workaround, restore the original out/extension.js backup and run Developer: Reload Window again.

Related: #38065 concerns instructions when crossing repository boundaries; this report concerns choosing the correct repository before a new IDE session starts. #25319 concerns history grouping/filtering, rather than active-editor-based startup selection.

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 with the workspace-root collection function (aS) and the out/extension.js bundle behavior described in the report, then inspect the existing workspace-folder notification and project selection flow. Run the focused checks and node --check; done means new chats select the active file's workspace root, preserve existing-chat directories, retain all roots, and fall back correctly without breaking project identity or history.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.