Skip to content

[FEATURE]: Add /cd slash command for runtime working directory switching #23358

@yangelaboy

Description

@yangelaboy

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Related: #2177, #15220

Add a /cd slash command that allows changing the working directory at runtime without restarting OpenCode. This is a common workflow need when navigating between projects or worktrees mid-conversation.

Proposed behavior

  • /cd <path> — switch to the given directory (supports relative paths, absolute paths, ~ expansion)
  • /cd without arguments — return to the initial startup directory
  • Appears in slash command autocomplete list
  • When switching outside the current project root, show a confirmation dialog
  • Record the directory change in the session as a shell command (cd <path> display + pwd output)

Why this is useful

Users frequently need to navigate between related projects, monorepo packages, or git worktrees during a single session. Currently the only option is to quit and restart OpenCode in the new directory. A lightweight /cd command avoids losing conversation context.

Implementation approach

  • TUI-side only: resolve path, validate directory exists, update SDK's target directory, record in session
  • Minimal changes (~150 lines added across 7 files), no server-side changes needed
  • A previous attempt (feat: add /cd command for changing working directory #7266, 3400+ lines) was closed — this approach is significantly smaller and focused

Environment

  • OS: macOS (darwin-arm64)
  • Terminal: Ghostty

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions