VS Code extension creates new chats in a stale project from global storage
What version of the IDE extension are you using?
26.715.31925
What subscription do you have?
Unknown (not relevant to local workspace selection)
Which IDE are you using?
Visual Studio Code 1.129.1
What platform is your computer?
Darwin 25.5.0 arm64 arm
What issue are you seeing?
New Codex chats created from VS Code are assigned to an old project instead of the folder open in the current VS Code window.
For example, the current VS Code window has /Users/<user>/Work/wechat-tool open, but every new chat uses:
/Users/<user>/Work/monorepo-app
This affects both the chat cwd and its writable root. Asking Codex to run pwd returns the stale project path.
Evidence
The VS Code workspace metadata correctly identifies the active window as wechat-tool, but the Codex extension's user-level global storage contains:
select json_extract(value, '$."selected-project"')
from ItemTable
where key = 'openai.chatgpt';
Result:
{"type":"local","projectId":"/Users/<user>/Work/monorepo-app"}
The Codex extension log for a newly created chat in the wechat-tool window shows:
requestRuntimeWorkspaceRootCount=0
requestSandboxWritableRootCount=1
The created thread is then persisted with cwd and thread-writable-roots pointing to the stale monorepo-app project.
This is potentially unsafe because commands, reads, and edits can run in a repository different from the one visibly open in VS Code.
What steps can reproduce the bug?
- Open multiple VS Code windows, each with a different local folder.
- Use Codex in one project, for example
/Users/<user>/Work/monorepo-app. - Switch to another VS Code window, for example
/Users/<user>/Work/wechat-tool. - Create a new Codex chat in that window.
- Ask Codex to run
pwd.
Actual result: the new chat runs in the previously selected monorepo-app project instead of wechat-tool.
The ChatGPT desktop bridge was active while this occurred.
What is the expected behavior?
A new IDE chat should use the folder or workspace open in the current VS Code window.
If several VS Code windows are open, each window should maintain its own active local project. A stale user-level global project selection must not override the current window's workspace root.
Additional information
Workaround that fully resolves the issue
After completely closing VS Code and backing up its state database, removing only selected-project fixes the problem:
db="$HOME/Library/Application Support/Code/User/globalStorage/state.vscdb"
cp "$db" "$db.codex-backup"
sqlite3 "$db" \
"UPDATE ItemTable SET value=json_remove(value, '$.\"selected-project\"') WHERE key='openai.chatgpt';"
After reopening VS Code, new Codex chats correctly use the current workspace.
Likely cause
The evidence suggests that selected-project is persisted in VS Code's user-level globalStorage, shared across VS Code windows. When the extension starts a chat without supplying a runtime workspace root (requestRuntimeWorkspaceRootCount=0), it falls back to this stale global selection.
The exact event that leaves selected-project stale is not yet known. Multiple VS Code windows and the active ChatGPT desktop bridge may be relevant triggers.
Privacy note
I am not attaching the full state.vscdb because the openai.chatgpt record can contain prompt history and other local chat metadata. The query result and log fields above are sanitized.
7 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I also am having this issue, and yes I use multiple VSCode windows simultaneously.
So having multiple windows active may well be a trigger for the issue.
Edit: I am running on Windows 11
For windows, the equivalent path is
%APPDATA%\Code\User\globalStorage\state.vscdbYou can use any normal SQLite DB editing software to edit the table, such as "DB Browser for SQLite".
But if you use a GUI based SQLite editor then remember to remove the
\"escaping in the SQLite command provided above.If you use this command then it will show you the end result for sanity, you know it worked if it says "extracted_project" is NULL.
I can independently reproduce this on Windows, with a more severe consequence than mixed chat history: new prompts execute against the stale project’s working directory and writable root, not the workspace visibly open in the current VS Code window.
Verified local evidence:
Observed behavior:
Get-Location.cwd/project assignment.The normal recovery paths did not fix it:
This indicates that the visible selector and the new-thread/execution path may not be using or refreshing the same state consistently. Renaming the affected directory is not a fix because the stale pointer remains in global state.
This should be treated as a cross-project data-integrity and security issue, not only a chat-scoping/UI issue: a user can unknowingly read, modify, or create files in an unrelated repository. A safe behavior would be to derive a new IDE chat’s
cwdand writable roots from the active VS Code workspace, or fail closed and require explicit confirmation whenever a stored global project conflicts with the active workspace.Environment: Windows 11 Pro, VS Code 1.129.1. The latch began while running pre-release extension 26.5715.61943. Updating to stable 26.715.61943 did NOT clear it; the stale
selected-projectsurvived the update and continued to capture new chats until the key was removed from global storage.Additional evidence for the root cause: every misassigned thread on my machine was persisted with
"localProjectId": nullwhile itsworkspaceRootscarried the stale path. This corroborates the fallback theory in the original report from a second independent machine: when workspace-root resolution returns nothing, the extension silently substitutes the globalselected-projectinstead of failing closed.Resolution steps that worked:
codex.exeapp-server processes keep the stale directory as their working directory (this even blocks renaming that directory on Windows).%APPDATA%\Code\User\globalStorage\state.vscdb(same SQL @dsisco11 posted above):UPDATE ItemTable SET value=json_remove(value, '$."selected-project"') WHERE key='openai.chatgpt';Get-Locationin a fresh chat across multiple projects.Cleanup of already-misassigned threads (optional): removing
selected-projectfixes new chats only. Threads created during the latch stay bound to the stale project's cwd and writable root forever, and a queued follow-up message in such a thread will still execute against the stale directory when delivered. To fully purge them I had to remove, per thread id: the rollout file in~\.codex\sessions\, the matching line in~\.codex\session_index.jsonl, rows referencing the id in~\.codex\state_5.sqlite, and thethread-project-assignments/thread-writable-rootsentries under theopenai.chatgptkey instate.vscdb.I am having simialr issue:
Issue:
C:\Projects\project-ain the Codex desktop app.C:\Projects\project-b, in VS Code.git rev-parse --show-toplevel.The VS Code chat incorrectly receives project A—the project selected in the desktop app—as its workspace instead of project B.
I reproduced this after:
Developer: Reload WindowThis appears to be workspace state leaking from the Codex desktop app into the VS Code extension. It is potentially dangerous because commands or edits could target the wrong repository.
Environment:
26.715.619431.130.010.0.26200.0 x64Running into this same issue except it will happen randomly during a session, not just when starting a new session. GPT will then say something like:
I cannot safely inspect, edit, review, or dispatch agents against [current-project] until /workspaces/[current-project] is restored. Please reopen/remount the repository workspace. The last verified commit before disappearance was cb2f256.
Can reproduce on
26.715.31925and26.715.61943. Cannot reproduce after downgrading the extension to26.707.91948. Have not tried any newer versions of the extension due to #35058.我也遇到了这个问题,我也是觉得自动识别当前的工作项目比较好,我现在是每次在项目里新增一个仓库级规则,后Codex 每轮首次执行项目命令前会: