Skip to content

feat(cli): /cd <path> — change the session working directory#226

Merged
emal-avala merged 1 commit intomainfrom
feat/cd-command
Apr 23, 2026
Merged

feat(cli): /cd <path> — change the session working directory#226
emal-avala merged 1 commit intomainfrom
feat/cd-command

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Adds /cd (alias /chdir) for changing the session's working directory mid-session without restarting with --cwd. Matches the shell-builtin feel users expect.

Accepts:

  • absolute paths: /cd /home/you/other-project
  • paths relative to the current session cwd: /cd ../sibling
  • tilde-prefixed paths: /cd ~, /cd ~/Code/foo

No-arg invocation prints the current cwd and usage, so /cd doubles as a "where am I?" probe when you've lost track during a long session.

Implementation notes

  • Relative paths resolve against the session cwd, not the process cwd. These can diverge when the user spawns the binary from one dir and then navigates elsewhere — the agent cares about the session cwd.
  • Every /cd also calls set_current_dir so subprocess-spawning tools (Bash, PowerShell, REPL) and canonicalize() calls behave consistently. Failure to update the process cwd is a warning, not a fatal error — at worst the agent sees a stale process cwd for one turn.
  • reset_system_prompt_cache() is called after the cwd changes so the next turn's # Environment block reflects the new dir.
  • ~user expansion is not supported — that would require NSS lookups and isn't portable. Only ~ and ~/ are handled.

Test plan

  • cargo clippy --workspace --tests --no-deps -- -D warnings — clean
  • cargo test -p agent-code --bin agent commands::tests::resolve_cd_target — 6/6 pass

6 new tests:

  1. Empty / whitespace-only input errors
  2. Absolute dir path resolves to its canonical form (symlink-aware)
  3. Relative path resolves against the supplied base dir
  4. Nonexistent path errors
  5. Plain-file path errors (not a directory)
  6. ~ expands to $HOME (skipped if HOME unset)

Adds /cd (alias /chdir) for changing cwd mid-session without restarting
with --cwd. Matches the shell-builtin feel users expect.

Accepts:
- absolute paths: /cd /home/you/other-project
- paths relative to the current session cwd: /cd ../sibling
- tilde-prefixed paths: /cd ~, /cd ~/Code/foo

No-arg invocation prints the current cwd and usage, so /cd doubles
as a "where am I?" probe when you've lost track during a long
session.

Implementation notes:
- Relative paths resolve against the session cwd, not the process cwd.
  These can diverge when the user spawns the binary from one dir and
  then navigates elsewhere — the agent cares about the session cwd.
- Every /cd also calls set_current_dir so subprocess-spawning tools
  (Bash, PowerShell, REPL) and canonicalize() calls behave
  consistently. Failure to update the process cwd is a warning, not
  a fatal error — at worst the agent sees a stale process cwd for
  one turn.
- reset_system_prompt_cache() is called after the cwd changes so
  the next turn's # Environment block reflects the new dir.
- ~user expansion is NOT supported — that would require NSS lookups
  and isn't portable. Only ~ and ~/ are handled.

Tests (6 new):
- Empty / whitespace-only input errors
- Absolute dir path resolves to its canonical form
- Relative path resolves against base dir
- Nonexistent path errors
- Plain-file path errors (not a directory)
- ~ expands to $HOME (skipped if HOME unset)
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit 57c25e2 into main Apr 23, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/cd-command branch April 23, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant