VSCode: How to run a command after each terminal open?

On Linux systems you should use:


On Windows and OSX:





If you want to apply shellArgs setting on a per-workspace basis – you can, despite the fact that documentation says:

The first time you open a workspace which defines any of these settings, VS Code will warn you and subsequently always ignore the values after that

At least version 1.42 of VSCode asks you something like:

“This workspace wants to set shellArgs, do you want to allow it?”

See issue 19758

On Linux, if you are using bash (default for shell in VSCode), there are some subtleties:

  1. "terminal.integrated.shellArgs.linux": ["your_init_script.sh"]

    will execute the script and close terminal right away. To prevent this you’ll have to end the script with $SHELL command.

    echo "init"
    export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want

    But that way you end up in a subshell. Sometimes it’s unacceptable (Read 1) (Read 2).

  2. "terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]

    will leave you in the initial shell, but will not execute the .bashrc init file. So you may want to source ~/.bashrc inside your_init_script.sh

    source ~/.bashrc
    echo "init"
    export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
  3. And if you already have some_init_script.sh in a repository, and for some reason don’t feel like adding source ~/.bashrc into it, you can use this:
    "terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]


    source ~/.bashrc
    source some_init_script.sh


    echo "init"
    export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want

    Outside of VSCode you can do without creating extra file. Like this

    bash --init-file <(echo "source ~/.bashrc; source some_init_script.sh")

    But I could not pass this string into terminal.integrated.shellArgs.linux – it needs to be split into array somehow. And none of the combinations I’ve tried worked.

Also, you can open terminal at a specific folder:


Change env:


And even change terminal to your liking with




Leave a Comment