How to open code-insiders from the Terminal

If you are used to opening VSCode on the command line like code . you run into issues when you want to run the Insiders edition instead.

code-insiders . is what you are looking for, but maybe you do not want to stop there and you want your code . command back. Let me show you how that is done.

Reverting to Original Solution

Slight confession, it is christmas 2022 now and my original solution fails to be reliable. The original strategy was to put extra files right into the code-insiders folder, so that the Environment paths would not need to be touched. I installed some extensions today and it looks like code-insiders seemingly verified the installation and removed my custom scripts. There are two solutions, one requires a new folder the other requires protecting the files from code-insiders. I will go down the first route and take you along for the ride.

Finding the Location of code-insiders

You will need to run a command to find out where the code-insiders executeable is located on your hard drive.

  • bash - run which code-insiders
  • powershell - run ‘$(Get-command code-insiders).Source’
  • windows command line - run where code-insiders

Creating Scripts to Forward Commands

It might be tempting to just copy and rename the existing files or putting some other files into the same directory. Keep in mind that a code-insiders update may change the startup files or remove unverified files from its directories.

So it’s better to create your own folders and scripts and forward the script call to the actual implementation.

On Windows 11 with WSL, I need to add both variants (below). Depending on your system you may need to add only some of the files below. For pure linux you should consider using the alias system.

Creating a Directory for Scripts

You can use any method to create a path including using the ui of explorer.exe. Here is the command I used to create my windows path for my future binaries mkdir %USERPROFILE%\bin.

Next up in order for Windows to pay attention to this path it has to be added to the PATH variable. There is a safe way of using setx for this but the TL;DR: if you are unaware that setx can clip your PATH which can leave you in a bad state and you know how to fix it, do not use setx. Instead just open your Edit Environment Variables window and add the path yourself - here is a shortcut to that window: rundll32 sysdm.cpl,EditEnvironmentVariables

I added %USERPROFILE%\bin to the user-specific variables for my user under the key Path. If you’re wondering why echo %path% does not show your new edit you need to close and reopen your terminal so a fresh copy of the environment variables is loaded, after that the path should show up with your userprofilepath filled in.

Creating a bash Script

Create a script called code in %USERPROFILE%\bin and use chmod +x code to mark it executeable.

#!/bin/bash
code_insiders=$(which code-insiders) #find your actual code-insiders
"$code_insiders" $@ #call it even though that path has spaces and pass all arguments
  • $(which code-insiders) gets the path to the code-insiders script.
  • $@ gets all the arguments and forwards them to code-insiders.

Creating a cmd Script

Create a script called code.cmd in %USERPROFILE%\bin.

@echo off
REM set the variable code_insiders to the path of code-insiders.cmd
FOR /F "tokens=*" %%g IN ('where code-insiders.cmd') do (SET code_insiders=%%g)
REM execute code-insiders.cmd and pass all arguments even if that path contained spaces
"%code_insiders%" %*
  • FOR ... do the iconic batch way of setting a variable from an output.
  • %* gets all the arguments and forwards them to code-insiders.cmd.

Conclusion

You should now be able to type code . and run code-insiders . like you are used to doing.

On top of that code-insiders will not remove these files since they are safe and sound in a different directory.

If you liked this article give me quick ego boost over on twitter :)

Written on December 5, 2022