Claude does "cd" even when it doesn't need to

Status Fixed / completed
Maintainer reply ✓ Yes — igorkofman
Activity 10 comments · opened Mar 5, 2025 · closed Jul 31, 2025
💡 Likely answer: A maintainer (igorkofman, collaborator) responded on this thread — see the highlighted reply below.

Bug Description
I am working on 9 different projects at once. This is due to the nature of the projects, a base project template with github project best practices, a testing library for lua projects, and the projects that implement both of them. This means I need to run claude in one directory, and have it access and run commands in all 9 of those directories, and a couple other directories I am using to keep a project plan up to date and a library of prompts I have created with Claude Code to make all of this work easier. The big problems I run into are the fact that Claude code continues to try and use the cd command when it is not allowed do to your security settings. I tell it to use pushd and popd to run commands in directories, or git -C for git commands in other directories, or sometimes full file paths. That is all part of the initial prompt I always give Claude Code when starting up. It works sometimes, others it just forgets those instructions. But worse is that when it gives me the prompt with 3 options where I can say Yes, Yes and don't ask again, or No, it does not remember that I have said yes and dont ask again for those types of commands. It will ask me and I will say yes and dont ask again, and then it will ask me again. Over and Over. This is for any command that has to happen in other directories from the current working directory, but especially for commands that use pushd / popd or git -C. If this was fixed I would do my work in half the time.

Environment Info

  • Platform: linux
  • Terminal: kitty
  • Version: 0.2.30
  • Feedback ID: 32262158-fa9f-48d0-bb69-ce3060c31ac3

View original on GitHub ↗

10 Comments

igorkofman collaborator · 1 year ago

could you launch claude higher up in the directory tree so all the projects are accessible to it?

greggh · 1 year ago

Thanks for responding!

I can do that, but then it still tries to use cd non-stop no matter how many times I tell it not to. And in a long session I might not even see a cd in a longer command chain it wants to run and then i say ok and because its deeper in the same directory, now im in that other directory again. Claude Code is not allowed to use the cd command, that is built in from Anthropics end. Maybe a filter of some kind can be added telling it to never use cd? If we can never use it, then its just a problem. cd functionality in this context can always be replaced with env -C or pushd/popd.

igorkofman collaborator · 1 year ago

It should be able to use cd ok if it's about going into child folders, only cd-ing into parent folders is disallowed.
If you're having issues with a specific task it's failing to accomplish while cd-ing around child folders, please share details so we can debug.

greggh · 1 year ago

I am not sure how to respond to this, I am not being rude, nothing but love for everyone working on this. In the end its about money, and a lot of wasted tokens.

I am in a Projects folder working on many various projects that are all related. To work on them all easily and with far less tokens used, and less problems I need claude to remain in the Projects folder and not go into child folders. It can use many tools and functions to work on anything it needs to in those subfolders. cd'ing into those subdirectories is never neccessary. There are good reasons Claude Code tries to avoid the cd command, security related of course, but also changing the context of what folder I am in, what my relative paths might mean in any code or files we're working with.

The issue here is that I can't think of a single reason using the cd command is actually neccessary. It only has the ability to cause problems and does nothing to help any work you might be doing with Claude Code. With "env -C", "git -C", and "pushd / popd" or sometimes full paths, we never need cd.

I am spending many hours in sessions building up context related to all of the projects I am working on, and of course building up answers to various permission prompts that speed up development. So restarting Claude Code is not a great option.

If Claude Code would cd back to the working directory after cd'ing into a deeper directory then it wouldn't be the worst solution. But right now there is no reason to cd ever.

EDIT:

Another problem related to all of this is my toolings portability, for me to use it on multiple devices I have a lot of relative paths in scripts, prompts and context saving files for memory. When Claude Code moves around the file system it can forget how to get to those relative paths, when it does this it uses tools and tokens taking lot of time and money to do things it shouldn't need to do to find those files and folders again. And in a multi-project setup like this Claude loves to try to cd, sometimes to places it cant, which wastes more tokens on that attempt, on my response tellingit no, on my response telling it it isn't allowed to use cd, or on my response after it does attempt to cd and fails with the security error. Having to tell Claude not to do somthing that is costing me money and time, repeatedly in the same session, costs a lot in the end if you're in coding and working in and out of Claude Code > 8 hours a day.

igorkofman collaborator · 1 year ago

Appreciate the in-depth feedback and the love!

We are aware that it sometimes can cd too much even when this isn't necessary and are working on improvements. I understand that this is frustrating from a time and tokens perspective.

If you run into specific scenarios where it's not just doing it too much but ends up unable to continue (ie. can't cd back etc) please report it with /bug so we can look at the logs and debug the issue. Otherwise, we'll keep working on enhancements to reduce un-needed cd's

greggh · 1 year ago

Thanks for the quick response. I can't tell you how much more effective and performant I am with Claude Code unless you want me to get a bit effusive here. But just know I would not be back up to my current level of productivity without Claude Code after my long-covid really did some damage. But that also means money is tight so wasting tokens hurts me a bit more than maybe some other users.

I'll catch the next few unneeded cd commands and context for them over the week and get a more thorough report in with hard examples. Some of this is fixed by the massive prompt library i've been building up, but no matter how many times I tell it not to do certain things, it's still an AI and they will just do what they want sometimes.

wanderingnature · 1 year ago

This is a SIGNIFICANT issue which I have tried many ways to resolve and results in a COST TO USERS in tokens as Claude searches in vain for files that I provide a correct relative path to without knowing that somewhere along the way Claude needlessly CHANGED DIRECTORIES so it could run a bash command using ./command rather than folder/command. It makes absolutely no sense that Claude cannot simply understand relative paths and just use them. I have even tried to use memory to address this issue but to no avail, because Claude Code doesn't seem to have a fully (accroding to the docs) implemented memory functionality... I put this into CLAUDE.local.md and even into CLAUDE.md but I cannot get Claude to stop using 'cd' - it is annoying a f#ck. ## Command Restrictions

  • NEVER use the 'cd' command - stay in the folder you are started in so I can use relative paths for the files I want you to read or edit
  • If you need to run a command just use the relative path - it is easier and better than using 'cd' first
mattgodbolt · 1 year ago

Agreed. this is annoying as heck for my code too as I watch claude flounder around trying all sorts of different things until:

<img width="972" height="295" alt="Image" src="https://github.com/user-attachments/assets/2b883211-d8de-4899-bb3e-03799e75c319" />

igorkofman collaborator · 1 year ago

The original issue is significantly better in Claude 4 family models and we'd done a bunch of work to address it in product as well

github-actions[bot] · 1 year ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.