How to Change Gemini CLI Directory: Step-by-Step
In this article
To change the working directory in Gemini CLI, use the /cd slash command followed by the path, or launch the CLI from the target folder. Gemini CLI runs in your terminal and uses your current working directory as its context, so switching directories is a matter of either changing your shell's location before starting it or using the built-in command while it is running. This guide covers both methods, plus what to do when the change does not stick.
What You'll Need
- Gemini CLI installed and authenticated (the
geminicommand available in your terminal). - A terminal or command prompt on Windows, macOS, or Linux.
- The path to the folder you want to work in. You can copy it from your file manager or use a relative path like
../projects/my-app.
Step-by-Step
- Open your terminal. On Windows, use Windows Terminal or Command Prompt; on macOS or Linux, use Terminal. Menu labels and prompts can differ slightly by version, device, or region, but the commands below are standard.
- Navigate to the folder you want Gemini CLI to use. Use the
cdcommand with the full or relative path. For example,cd ~/projects/my-appon macOS or Linux, orcd C:\Users\YourName\projects\my-appon Windows. Press Enter and confirm you are in the right place withpwd(macOS/Linux) orcdwith no arguments (Windows shows the current directory). - Start Gemini CLI. Type
geminiand press Enter. The CLI opens with the folder you navigated to as its working directory. Any files it reads or commands it runs will be relative to that folder. - To change directory while Gemini CLI is already running, use the
/cdslash command. Type/cd path/to/folderand press Enter. For example,/cd ../other-projectmoves up one level and intoother-project. The CLI confirms the new working directory in its output. - Verify the change. Ask Gemini CLI to list the current directory, or run a command like
/cd .to re-confirm the path. You can also type a simple request such as "what files are in the current directory?" and check that the answer matches the folder you intended. - If you want a fresh session in a different folder, exit and restart. Type
/exitor press Ctrl+C twice to leave Gemini CLI, then repeat steps 1–3 from the new location. Restarting is the cleanest way to ensure no cached context from the previous folder carries over.
Common Mistakes
- Using
cdwithout the slash inside the CLI. Inside Gemini CLI, plaincdmay be interpreted as a shell command or ignored. Use the slash command/cdto change the CLI's working directory. - Assuming the CLI follows your terminal after launch. If you change your shell's directory in another tab, an already-running Gemini CLI session does not automatically follow. Use
/cdin the session or restart it. - Paths with spaces. Wrap paths containing spaces in quotes, for example
/cd "My Projects/app". Unquoted spaces split the path and cause an error. - Confusing the CLI's directory with your shell's directory. The
/cdcommand changes where Gemini CLI looks for files; it does not change the directory of your terminal prompt. - Forgetting permissions. On macOS or Linux, if the folder is outside your home directory, you may need to adjust permissions before the CLI can read it.
Tips
- Use relative paths like
../sibling-folderfor quick switches without typing the full path. - Start Gemini CLI from the project root so it can see all subfolders and configuration files in one session.
- If you frequently switch between two projects, keep two terminal tabs open, each started in its own folder.
- Check the CLI's built-in help by typing
/helpto see the current list of slash commands, since available commands can vary by version. - Use tab completion in your shell before launching the CLI to avoid typos in long paths.
Troubleshooting
- The
/cdcommand is not recognized. Your version of Gemini CLI may not support it, or you may have typed it without the leading slash. Type/helpto confirm the command exists. If it does not, exit and restart the CLI from the desired folder instead. - “No such file or directory” error. The path is wrong or the folder does not exist. Run
ls(macOS/Linux) ordir(Windows) in your terminal to list the current folder's contents and check the exact name. - Permission denied. The folder may be owned by another user or read-only. Move the project into your home directory, or adjust permissions with your system's file tools. On Windows, avoid system folders like
C:\Windows. - The CLI still sees old files after changing directory. Some context may be cached. Exit with
/exitand restart the CLI from the new folder to force a clean read. - Changes do not persist between sessions. Gemini CLI does not remember the last directory across restarts by default. Start each session from the folder you want, or use
/cdat the beginning of each session.
Frequently Asked Questions
Does Gemini CLI remember the last directory I used?
No. Each new session starts in the directory where you launched the gemini command. Use /cd or restart from the desired folder.
Can I change the directory without restarting Gemini CLI?
Yes, if your version supports the /cd slash command. Type /cd path/to/folder inside the running session. If the command is not available, restart the CLI from the new folder.
What is the difference between cd and /cd?
cd is a shell command that changes your terminal's working directory. /cd is a Gemini CLI slash command that changes the CLI's working directory without affecting your shell.
Can I use an absolute path with /cd?
Yes. Both absolute paths (like /Users/name/project) and relative paths (like ../project) work, as long as the folder exists and you have permission to read it.
Why does Gemini CLI say the directory does not exist when I can see it in my file manager?
Check for typos, hidden characters, or spaces in the path. Quote paths with spaces. Also confirm you are using the correct path separator for your operating system (backslash on Windows, forward slash on macOS and Linux).
Does changing the directory affect which files Gemini CLI can access?
Yes. Gemini CLI reads and writes files relative to its working directory. Changing the directory changes the scope of files it can see in that session. It does not grant access to folders outside that directory unless you provide full paths.