Skip to content

Visual Studio Code

Visual Studio Code can be used on Merlin7 with the Remote - SSH extension. The recommended workflow is to start a normal non-X11 interactive Slurm session and connect VS Code to the allocated compute node.

Do not run VS Code on login nodes

Do not start VS Code directly on Merlin7 login nodes.

Login nodes are not meant for CPU-intensive, memory-intensive, or long-running VS Code workloads. Running VS Code there can slow down the system for all users and may lead to your session or process being terminated by administrators.

Start an interactive session first, then connect VS Code to the allocated compute node.

Do not use X11 mode for VS Code

Use the default non-X11 mode:

Bash
interactive

Do not use interactive --x11 for VS Code Remote SSH. X11 sessions are not detachable and are intended for foreground graphical applications.

VS Code via interactive sessions

1. Start an interactive session

From a Merlin7 login node, start a normal interactive session:

Bash
interactive

For more resources, pass Slurm options after --:

Bash
interactive -- --cpus-per-task=8 --mem=16G

Request resources with --cpus-per-task

For most VS Code workflows, request CPUs with --cpus-per-task.

Avoid requesting more CPUs or memory than needed for an editor, terminal, notebook, or compile session.

The allocation is detachable. You may leave the shell with:

Bash
exit

The allocation remains active.

Cancel the allocation when finished

In non-X11 mode, exit does not stop the Slurm allocation.

When you are done, cancel it explicitly:

Bash
interactive --cancel

2. Generate the VS Code SSH config

After creating the allocation, print the VS Code SSH configuration snippet:

Bash
interactive --print-vscode

Copy the printed Host block into the SSH config file on your local computer:

Text Only
~/.ssh/config

Use --print-vscode after each new allocation

The allocated compute node may change whenever you create a new session.

Run this command again after creating a new allocation and update your local SSH config:

Bash
interactive --print-vscode

3. Connect from VS Code

On your local computer:

  1. Open Visual Studio Code.
  2. Open the command palette.
  3. Select Remote-SSH: Connect to Host....
  4. Choose the host name from the generated SSH config block.
  5. Open your working directory on Merlin7.

VS Code should now start its remote server on the allocated compute node.

To check, open a VS Code terminal and run:

Bash
hostname -f

The output should be a compute node, for example:

Text Only
cn001.merlin7.psi.ch

Check where VS Code is running

If hostname -f shows a login node, disconnect and check your SSH configuration.

Troubleshooting

No active allocation found

Create one first:

Bash
interactive
interactive --print-vscode

The compute node changed

Regenerate the config snippet and update your local ~/.ssh/config:

Bash
interactive --print-vscode

VS Code stopped working

Check whether the allocation is still active:

Bash
interactive --status

If it has ended, create a new allocation and regenerate the VS Code SSH config.

VS Code via Open OnDemand

As an alternative to creating an interactive session with or without X11 forwarding, you can also use Open OnDemand on Merlin7.

Open OnDemand provides web-based access to HPC resources and can be used to start graphical applications such as VS Code or MATLAB directly from a browser. Sometimes, this can be more convenient than setting up local SSH configuration, X11 forwarding, or VS Code Remote SSH manually.

Tip

If you mainly need a graphical VS Code or MATLAB session, Open OnDemand on Merlin7 is often the easiest option.

Warning

The same login-node rule still applies: do not run heavy interactive applications directly on login nodes.

Use either an interactive Slurm allocation, as described in this page, or the Open OnDemand web interface.