Skip to content

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) #4703

Closed

Description

@0xdevalias

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

Activity

  1. added
    bug
    on Oct 4, 2025
  2. jazzyalex commented on Oct 14, 2025

    @jazzyalex

    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.

    Image
  3. etraut-openai commented on Nov 25, 2025

    @etraut-openai
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions