/clear resets working directory, losing worktree context

Resolved 💬 3 comments Opened Mar 7, 2026 by llamallamaredpajama Closed Mar 11, 2026

Problem

When working inside a git worktree (or any directory navigated to during a session), running /clear resets the working directory back to the original launch directory instead of preserving the current working directory.

This is particularly dangerous with git worktrees because:

  • You think you're still in the worktree on a feature branch
  • You're actually back in the main project directory on main
  • Any file edits or git operations now affect main instead of the worktree branch

Steps to Reproduce

  1. Launch claude from a project root (e.g., ~/dev/my-project/)
  2. Create or enter a worktree: cd .claude/worktrees/my-feature/
  3. Do some work on the worktree branch
  4. Run /clear to free up context
  5. Check pwd and git branch — you're back in the original project root on main

Expected Behavior

/clear should preserve the current working directory so that:

  • pwd remains the same after clear
  • Git branch context is maintained
  • File operations continue targeting the correct directory

Actual Behavior

/clear resets the session to the directory where claude was originally invoked, silently changing the git branch and file context.

Impact

  • Silent data hazard: edits and commits land on main instead of the feature branch
  • Worktree workflow broken: worktrees are designed for isolated work, but /clear breaks that isolation
  • Forces users to either avoid /clear entirely or remember to cd back every time

View original on GitHub ↗

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