A coding session needs the right project context when several projects share similar filenames. Codex can use a selected working directory for project files and commands while the launching shell remains elsewhere.
Relative file names and project instructions are resolved from the selected directory. Choosing the project explicitly avoids reading a same-named file from whichever folder launched the process.
You need an installed Codex CLI with a configured model provider and an existing project directory. Project content can reach that provider, and Codex may ask whether you trust the folder before opening it.
Steps to set the Codex working directory:
Project settings can run code when the folder opens, even without a model request. Folder access should be approved only for project files you trust.
- Start Codex with the absolute path of the existing project.
$ codex -C /work/example-app
The path /work/example-app represents your project directory. Paths containing spaces need quotes. -C and --cd select the same working directory for the new session.
- Approve folder access if Codex asks whether you trust the project.
The Trust and continue option opens the selected folder.
- Check the working directory with /pwd inside Codex.
> /pwd • Current working directory: /work/example-app
The displayed path should match the project selected at launch. A different path means the session is using another directory. This built-in command reports the session's directory without asking the model to infer it.