feat(cli): /cd <path> — change the session working directory#226
Merged
emal-avala merged 1 commit intomainfrom Apr 23, 2026
Merged
feat(cli): /cd <path> — change the session working directory#226emal-avala merged 1 commit intomainfrom
emal-avala merged 1 commit intomainfrom
Conversation
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)
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
/cd /home/you/other-project/cd ../sibling/cd ~,/cd ~/Code/fooNo-arg invocation prints the current cwd and usage, so
/cddoubles as a "where am I?" probe when you've lost track during a long session.Implementation notes
/cdalso callsset_current_dirso subprocess-spawning tools (Bash, PowerShell, REPL) andcanonicalize()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# Environmentblock reflects the new dir.~userexpansion 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— cleancargo test -p agent-code --bin agent commands::tests::resolve_cd_target— 6/6 pass6 new tests:
~expands to$HOME(skipped if HOME unset)