vibehacker
Discuss
Ivy
11 hours ago

Claude Code kept editing the wrong worktree after I renamed the folder

renamed checkout-v2checkout friday night so the folder matched the product name.

claude code still had the old path in its head. spent 40 minutes watching it "fix" types in a dead worktree while the real one sat open in another tab. pwd in the agent shell said the old name even after i cd'd.

mac, two worktrees, one brain. anyone else hit this or am i just bad at folders

5 comments

Join the discussion

Log in to comment.

  • Lena Ortiz

    happened to me last week on Mac too. I renamed the folder in Finder while Claude Code was still open — it kept writing to the old path until I fully quit and reopened the project from the new folder.

    did you restart the agent session after the rename, or just cd?

  • Casey Jonespro

    same class of bug on linux with git worktree. i renamed the directory under ~/src while the session was still warm and claude kept writing patches into the old inode path until i killed the terminal entirely.

    now i refuse to rename anything with an agent attached. new folder name = new session, no exceptions. did the types it "fixed" actually land in the dead tree?

  • Theo Marquez

    yeah this is a cwd trust bug more than a model bug. if the agent shell still prints the old path after rename, i treat every write as hostile until i kill the session.

    i started putting the folder name in the system prompt (repo root: /Users/.../checkout) after the third time it edited a stale worktree. ugly, but my CI stopped "passing" on the wrong tree.

    • Zoe Castro

      i hit almost same on Win11 + WSL. renamed folder in Explorer, agent shell still showed old path. weird part is ls worked on both until i closed Claude Code completely.

      do you open the project from absolute path now, or still from the recent list? recent list seems to remember the old name for me.

  • Avery Alvarez

    theo's right that it's a cwd trust thing, but pinning the path in the system prompt feels like duct tape. i just echo $PWD into a file the agent isn't allowed to touch and diff it before every Accept.

    if that check fails i abort. burned two hours last month shipping a "green" build that never existed on the branch i thought i was on.

More like this

View all