Allow switching working directory mid-session (/cd command)

Resolved 💬 4 comments Opened Feb 12, 2026 by marcospgp Closed Mar 13, 2026

Preflight

  • [x] I've searched existing feature requests
  • [x] This addresses a single feature

Problem Statement

When using git worktrees (.worktrees/<branch>/), the agent needs to work on files in the worktree directory, not the repo root. Claude Code currently cannot switch its working directory mid-session — cd outside the original directory is blocked, and /add-dir only grants read/edit access without changing the working root.

This means any session that needs to work on a worktree must be started from within that worktree directory. There's no way to create a worktree and then switch to it in the same session.

The previous issue #1628 was closed with the addition of --add-dir / additionalDirectories, but as noted in comments there, this doesn't solve the working directory problem — tools still anchor to the original root, and the agent defaults to writing files relative to it.

Proposed Solution

A /cd slash command (user-invoked only, not agent-callable) that changes the working directory mid-session. Since slash commands can only be typed by the user, this is not injectable by prompt injection.

Alternatively, an agent-callable mechanism to switch working context would enable workflows like: create worktree → switch to it → work → switch back.

Alternative Solutions

Current workaround: exit Claude Code and restart from the worktree directory. This loses all conversation context.

Another workaround: use absolute paths to the worktree. This is error-prone in practice — the agent forgets to prefix paths and edits files in the wrong directory.

Priority

Medium - Impacts my workflow

Feature Category

CLI commands

Use Case Example

  1. User is in /project working on main
  2. User asks agent to create a worktree for a feature branch: ./scripts/worktree.sh create my-feature
  3. Worktree is created at .worktrees/my-feature/
  4. User types /cd .worktrees/my-feature
  5. Agent now works relative to the worktree — all file operations target the correct directory
  6. When done, user types /cd /project to return to main

Additional Context

Related: #1628 (closed, partially addressed by --add-dir)

The git worktree workflow is increasingly common for isolating agent changes per branch. The inability to switch working directory mid-session is the main friction point.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗