When I `resume` a session that was previously started with `--cd`; it should respect that original directory (or at least prompt me to confirm which I want)

Resolved 💬 3 comments Opened Oct 4, 2025 by 0xdevalias Closed Nov 25, 2025
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.42.0

Which model were you using?

N/A

What platform is your computer?

Darwin 23.6.0 x86_64 i386

What steps can reproduce the bug?

Start a new session using --cd:

codex --cd /foo/bar/baz

Do some things in the session then close, it; noticing the suggested resume command:

..snip..

Token usage: total=2,602 input=2,094 (+ 17,408 cached) output=508 (reasoning 256)
To continue this session, run codex resume 0199a9d9-f5f2-7691-8920-cfdb4384ab3e.

Run codex resume and notice that the directory is set to your current working directory, and not the directory you originally --cd'd to in that session.

What is the expected behavior?

If the session was previously run in a directory other than my current working directory, when I resume a session, it would be nice if codex noticed this, and asked me if I wanted to use the old directory or my CWD.

If I explicitly pass --cd while resume'ing a session then it might be fine to assume I know what I am doing and bypass this confirmation step; but sometimes maybe it would still be useful even then (perhaps that could be a config option?)

As a minimal partial workaround in the meantime, I wonder if that 'onClose' message about resume could include a --cd with the directory it was running in as well.

So instead of:

To continue this session, run codex resume 0199a9d9-f5f2-7691-8920-cfdb4384ab3e.

It would be:

To continue this session, run codex resume --cd /foo/bar/baz 0199a9d9-f5f2-7691-8920-cfdb4384ab3e.

What do you see instead?

The existing working directory of the resume'd session is ignored, and the current working directory is used.

Additional information

N/A

View original on GitHub ↗

3 Comments

0xdevalias · 10 months ago
jazzyalex · 10 months ago

Agreed — --cd should persist or at least prompt for confirmation when resuming. Right now, Codex CLI resumes sessions statelessly and doesn’t restore the original working directory, which can easily lead to context mismatches if the project path has changed.

Agent Sessions currently handles this on macOS by recording each session’s working directory and automatically restoring it when launching /resume in Terminal or iTerm. Still, having this behavior built directly into the CLI would make the workflow much more consistent across platforms.

<img width="2296" height="1616" alt="Image" src="https://github.com/user-attachments/assets/d2874722-752e-4b11-87e1-a77426b10bd6" />

etraut-openai contributor · 9 months ago

With the most recent version of the CLI, codex resume filters the list of sessions based on your directory.