Skip to content

/cwd command to switch working directory without restarting session #12464

Closed

Description

@ignatremizov

What variant of Codex are you using?

CLI (TUI) custom fork off of 0.104.0

What feature would you like to see?

Add a /cwd slash command to change the working directory inside the current TUI session, with a policy-selection step in the same flow.

Current workflow is frustrating:

  1. Exit TUI
  2. cd into another repo/worktree
  3. codex resume ...
  4. Re-approve sandbox/policy for that directory

This is especially painful when iterating on many sibling forks. I want Codex to keep autonomous execution within the selected repo, but I do not want to grant blanket access to the parent directory just to avoid repeated approvals.

Proposed UX:

  • /cwd <path> to switch current working directory
  • /cwd with no args opens a picker/input modal
  • In the same flow, prompt for policy handling for the target directory:
    • apply target directory defaults (trust/project policy)
    • or keep current runtime policy override
  • Show a short confirmation line in transcript (new cwd + effective approval/sandbox policy)

Additional information

Related but not equivalent: /add-dir (#11747) expands access roots; it does not switch active cwd and policy context.

Short implementation sketch:

  1. Wire command + dispatch
  • codex-rs/tui/src/slash_command.rs: add SlashCommand::Cwd with description and inline args support.
  • codex-rs/tui/src/chatwidget.rs: dispatch /cwd and /cwd <path> via a new app event.
  1. Add app-level event and handler
  • codex-rs/tui/src/app_event.rs: add AppEvent::ChangeCwd { path: Option<String> }.
  • codex-rs/tui/src/app.rs: handle ChangeCwd by resolving/validating path, then rebuilding config with existing rebuild_config_for_cwd(...).
  1. Apply cwd + policy atomically
  • Reuse rebuilt config’s derived approval/sandbox defaults for target cwd.
  • Send Op::OverrideTurnContext { cwd: Some(...), approval_policy: Some(...), sandbox_policy: Some(...) } so core session state updates without restart.
  • Update in-memory TUI state (self.config, file-search root via file_search.update_search_dir(...), and chat widget config copy) so UI and behavior stay consistent.
  1. Prompt UI and tests
  • Reuse/extend codex-rs/tui/src/cwd_prompt.rs patterns for selection/confirmation.
  • Add tests in codex-rs/tui/src/chatwidget/tests.rs and codex-rs/tui/src/app.rs for command dispatch, path validation, and policy-application behavior.

Status after #38894

#38894 / commit ed32158e90ef872c5eef96baf2f14feac70aee6e is a good direction and solves the core pain point: /cd <path> can switch an idle local TUI conversation to another working directory while preserving history and reloading the destination project context.

The command naming is not considered a gap. /cd is the conventional user-facing command for changing directories, while /cwd is reasonable as an alias for /pwd.

Remaining follow-up work:

  • Policy selection: add an in-flow choice between applying the destination directory's defaults and retaining the current runtime policy override. The implementation currently applies compatible overrides automatically and rejects incompatible transitions.
  • Directory-switching restrictions: revisit the deliberately conservative blanket restrictions. Some currently rejected transitions may be supportable where the relevant state can be transferred safely.
  • Bare command UX: open a directory picker or input prompt for bare /cd instead of always selecting ~.
  • Fork versus move semantics: the current implementation forks and replaces the active thread. Some workflows instead need to move the existing thread to the new directory without changing its identity, so this should be an explicit choice or preserve the original thread when safe.
  • Confirmation: include the resulting approval and sandbox policy alongside the new path in the transcript confirmation.

The merged implementation establishes the right foundation, while these policy-selection and transition-semantics gaps remain in scope for this issue.

Activity

  1. added
    enhancement
    CLI
    TUI
    on Feb 21, 2026
  2. github-actions commented on Feb 21, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. changed the title [-]TUI: /cwd command to switch working directory without restarting session[/-] [+][Feature] TUI: /cwd command to switch working directory without restarting session[/+] on Feb 21, 2026
  4. removed
    CLI
    on Feb 21, 2026
  5. Astro-Han commented on Mar 29, 2026

    @Astro-Han

    I want to add one clarification here: for me this is not just a generic directory-switching request.

    The most important case is switching the active session into another existing git worktree without leaving Codex, manually cd-ing, and restarting/resuming.

    So if this issue becomes the main tracking thread for in-session cwd switching, I would strongly consider existing worktree navigation to be a core use case, not just an edge case.

  6. backnotprop commented on Apr 15, 2026

    @backnotprop

    Need this.

  7. justinTM commented on Apr 25, 2026

    @justinTM

    desktop app frequently gets stuck in its workdir. when the model returns filepaths different from what appears in terminal or file tree, you have no option in the app to rectify this mismatch.

  8. changed the title [-][Feature] TUI: /cwd command to switch working directory without restarting session[/-] [+]/cwd command to switch working directory without restarting session[/+] on Apr 28, 2026
  9. moddyfire commented on Apr 28, 2026

    @moddyfire

    I want to add one clarification here: for me this is not just a generic directory-switching request.

    The most important case is switching the active session into another existing git worktree without leaving Codex, manually cd-ing, and restarting/resuming.

    So if this issue becomes the main tracking thread for in-session cwd switching, I would strongly consider existing worktree navigation to be a core use case, not just an edge case.

    This doesn't even work for me. If I close, cd, codex --resume it doesn't have permissions for the new directory. Or maybe it was bug.

  10. backnotprop commented on Jun 17, 2026

    @backnotprop

    Major paper cut right here.

  11. backnotprop commented on Jun 17, 2026

    @backnotprop

    Oh, I already commented above April 14th and got 14 upvotes. I forgot about that and just continued to run into it. came searching for a solution.

  12. thewh1teagle commented on Jul 4, 2026

    @thewh1teagle

    Meanwhile you can ask codex

     Get the current Codex session id from the environment and give me the exact resume command from new-folder/.
  13. ignatremizov commented on Jul 5, 2026

    @ignatremizov
    Author

    @thewh1teagle lol what a waste of tokens. /statusline and enable session-id, or get it from /status directly

    cd to your path and resume from there

  14. ignatremizov commented on Aug 22, 2026

    @ignatremizov
    Author

    PR #38894 / commit ed32158 is a good direction and solves the core pain point: /cd <path> can now switch an idle local TUI conversation to another working directory while preserving its history and reloading the destination project context.

    The command naming looks right to me. /cd is the conventional user-facing command for changing directories, while advanced users are likely to understand /cwd as an alias for /pwd anyway. I would not treat that naming difference as a gap.

    There are still a few parts of the requested flow worth tracking:

    • Policy selection: there is no in-flow choice between applying the destination directory's defaults and retaining the current runtime policy override. The implementation currently applies compatible overrides automatically and rejects incompatible transitions.
    • Directory-switching restrictions: the initial implementation is deliberately conservative. Some blanket restrictions may be unnecessary where the relevant state can be transferred safely, and should be revisited rather than becoming permanent limitations.
    • Bare command UX: /cd without a path currently selects ~; it should offer a directory picker or input prompt.
    • Fork versus move semantics: the current implementation forks and replaces the active thread. That is useful when a fork is desired, but some workflows need to move the existing thread to the new directory without changing its identity. The user should have an explicit choice, or the operation should otherwise preserve the original thread when safe.
    • Confirmation: the transcript confirms the new path but does not show the resulting approval and sandbox policy.

    So this establishes the right foundation and addresses the main workflow, but the policy-selection and transition semantics from this issue remain useful follow-up work.

  15. avabbbb commented on Sep 20, 2026

    @avabbbb

    I have a small UX suggestion for the remaining bare /cd / /cwd picker work.

    I recently implemented a similar "recent working directories" picker in Oh My Pi:

    can1357/oh-my-pi#12497

    The useful part was not the move logic itself, but the destination source: derive a short recent-directory list from existing session/thread metadata, dedupe it, exclude the current cwd, and then hand the selected path to the existing safe cwd-transition pipeline.

    For Codex, I think bare /cd could follow the same pattern without adding new persistence:

    /cd
      ↓
    recent threads/session metadata
      ↓
    sort by recency
      ↓
    extract cwd → dedupe → exclude current cwd
      ↓
    show ~8 recent directories
      ↓
    existing ChangeWorkingDirectory flow
    

    This seems especially useful on Windows/PowerShell when jumping between several project folders.

    I am only suggesting the UX/data-source approach here, not a second cwd-transition implementation.

    If a picker is already planned for bare /cd, I would be happy to test this interaction on Windows 11 and share screenshots / edge cases.

  16. etraut-openai commented on Oct 12, 2026

    @etraut-openai
    Contributor

    /cd is now implemented.

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

    TUIenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions