'Change default working directory for VS Code terminal

Is it possible to change the working directory for new integrated terminal windows in Visual Studio Code?

I have opened the folder /path/to/project in Code, so when I open a new terminal windows, it starts in that folder. I would like the terminal to open in /path/to/project/app so that I don't have to cd to that folder every time. Is it possible to configure this in settings.json?



Solution 1:[1]

It turns out this was fairly easy to find in the documentation at https://code.visualstudio.com/docs/getstarted/settings.

The setting that controls this is

  // An explicit start path where the terminal will be launched, this is used
as the current working directory (cwd) for the shell process. This may be
particularly useful in workspace settings if the root directory is not a convenient cwd.
  "terminal.integrated.cwd": "",

This can be added to settings.json in the .vscode folder. Absolute and relative paths are supported, so

"terminal.integrated.cwd": "app"

and

"terminal.integrated.cwd": "/path/to/project/app"

will both work.

Solution 2:[2]

if you are changing your directory in your .bashrc or .zshrc file to your home directory (cd ~/ or cd $HOME/) then your vscode console will use the directory that you have specified.

Bellow is a little code you can use in your .bashrc or .zshrc to address this:

if [ "$NAME" != "Code ]; then
  cd ~
else
  cd $OLDPWD
fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 toryan
Solution 2 Dexter Le Blanc Jr.