Repository navigation
VS Code Codex Agent keeps running npm commands in wrong directory instead of project root (Windows 11) #7096
Description
What version of the VS Code extension are you using?
1.106.2
What subscription do you have?
plus
Which IDE are you using?
vs code
What platform is your computer?
windows 11 pro 25h2
What issue are you seeing?
VS Code Codex Agent keeps running npm commands in wrong directory instead of project root (Windows 11)
What is the issue?
I’m using the “Codex – OpenAI’s coding agent” VS Code extension on Windows 11.
I opened a folder called root3 in VS Code. Inside this folder, Codex created a Next.js project with:
npx create-next-app@14.2.33 etemadmarket-super-ecommerce --typescript --tailwind --eslint --app --src-dir --import-alias "@/*" --use-npm
This correctly created the project at:
C:\Users\Ali\Desktop\root3\etemadmarket-super-ecommerce
However, after that, Codex repeatedly ran commands like:
npm install --save-exact next@14.2.33 react@18.3.1 react-dom@18.3.1 ...
Problem:
These commands were executed in the root folder C:\Users\Ali\Desktop\root3 instead of inside the actual project folder etemadmarket-super-ecommerce.
That directory does not contain a package.json, so all these commands failed and the VS Code UI showed a red “failed” icon for those steps.
The agent also tried destructive commands (like uninstall / cleanup) in the wrong directory, which is very dangerous when run outside the actual project root.
Expected behavior
Once Codex creates a project inside a subfolder (here: etemadmarket-super-ecommerce), it should:
cd into that folder before running npm install or any other project-specific commands
Or at least recognize where the package.json is and treat that as the project root for all future steps.
Environment
OS: Windows 11
Editor: VS Code (latest stable)
Codex VS Code extension: (latest from Marketplace at the time of writing)
Model: gpt-5-codex
Mode: Agent (Full Access), Local / Work locally
Steps to reproduce
Open C:\Users\Ali\Desktop\root3 as the VS Code workspace.
Ask Codex Agent (Full Access) to create a new Next.js app with create-next-app inside a subdirectory (e.g. etemadmarket-super-ecommerce).
Let the agent continue and install additional packages.
The agent now runs npm install ... in root3 instead of root3\etemadmarket-super-ecommerce, causing all commands to fail.
Why this is serious
The agent ignores the actual project root (where package.json lives) and keeps using the workspace root.
It repeatedly fails commands and can potentially run destructive shell commands in the wrong directory.
Please treat this as a high-priority bug for the VS Code Codex extension, especially on Windows 11.
What steps can reproduce the bug?
Steps to reproduce
Open C:\Users\Ali\Desktop\root3 as the VS Code workspace.
Ask Codex Agent (Full Access) to create a new Next.js app with create-next-app inside a subdirectory (e.g. etemadmarket-super-ecommerce).
Let the agent continue and install additional packages.
The agent now runs npm install ... in root3 instead of root3\etemadmarket-super-ecommerce, causing all commands to fail.
What is the expected behavior?
Codex should detect the actual project root (the folder that contains package.json, e.g. etemadmarket-super-ecommerce) and run all npm/Next.js commands inside that folder, not in the parent root3 directory.
After creating the Next.js app in a subfolder, the agent should automatically cd into that project directory (or treat it as the workspace root) before running npm install, npm run dev, or any other project-specific or destructive commands.
Additional information
No response
Activity
etraut-openai commentedon Nov 21, 2025
Thanks for the bug report. We'll share the feedback with the team responsible for training our codex models. If you see other model behavior that you'd like to report, please use the
/feedbackcommand. That will provide us with additional details including logs and conversation text. You can access the/feedbackslash command in the extension by typing it in the prompt input box or by clicking on the/button.