# Local IDE access

VSCode is the most popular IDE, with a rich set of features and extensions that go far beyond what is currently possible in the JupyterLab interface. It also supports different tools that use LLMs and agentic frameworks for code completion, generation and debugging; some of them are available as VSCode extensions (e.g. GitHub Copilot, OpenAI Codex), and others as standalone IDEs (e.g. Cursor, Antigravity) built on top of VSCode.

Purdue AF allows you to connect to your AF session from any VSCode-based IDE and take advantage of these features. Please follow the instructions below; you will only need to run steps 1–5 once, and afterwards you can connect using step 6 alone, as long as you have an AF session running.

## 1\. Install the Remote-SSH extension in your IDE

1. In VSCode/Cursor/Antigravity, click on the Extensions icon in the left sidebar.
2. Search for the `Remote - SSH` extension by Microsoft or Anysphere and install it.

## 2\. Install the `websocat` command on your local machine

1. Check if you already have the `websocat` command on your local machine: `which websocat`. If the output of this command is not empty, skip this step.
2. Install `websocat`:

   On Linux, run the following commands:

   ```shell
   sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
   sudo chmod a+x /usr/local/bin/websocat
   ```

   On macOS, run the following command:

   ```shell
   brew install websocat
   ```

   Once installed, check that the command is available: `which websocat`.

   On Windows:

   - Download the pre-built binary from [https://github.com/vi/websocat/releases/latest/download/websocat.x86\_64-pc-windows-gnu.exe](<https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-pc-windows-gnu.exe>)
   - Move the binary to any directory you can access from the command line: `C:\path\to\websocat.exe`

## 3\. Configure SSH keys on the local machine

1. You may already have an SSH key pair generated: look for the `~/.ssh/id_ed25519` and `~/.ssh/id_ed25519.pub` files on your local machine.
2. If you do not have the key pair yet, you can follow the [GitHub SSH key instructions](<https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent>) and reuse the generated key pair for Purdue AF.
3. Add the following host entry to `~/.ssh/config` on your local machine:

   ```text
   Host PurdueAF
       HostName cms.geddes.rcac.purdue.edu
       User USERNAME
       IdentityFile ~/.ssh/id_ed25519
       IdentitiesOnly yes
       ProxyCommand websocat --binary -H="Authorization: token $(cat ~/.config/purdue-af/token)" asyncstdio: wss://%h/user/USERNAME/sshd/
   ```
4. If you are on Windows, make two small changes to the entry above:

   - replace `websocat` with the full path to `websocat.exe` from the previous step;
   - replace `asyncstdio:` with `stdio:`;
   - replace `$(cat ~/.config/purdue-af/token)` with `TOKEN`, since Windows does not run the `ProxyCommand` through a shell.
5. Replace `USERNAME` (**in two places!**) with your Purdue AF username:

   - If you are using a Purdue account, this is your Purdue career account username.
   - If you are using a CERN account, this is your CERN username followed by `-cern`.
   - If you are using an FNAL account, this is your FNAL username followed by `-fnal`.

The `ProxyCommand` reads the JupyterHub token from `~/.config/purdue-af/token`, which you save in the next step.

## 4\. Start a Purdue AF session and obtain a JupyterHub token

1. In your web browser, open [Purdue AF](<https://cms.geddes.rcac.purdue.edu>) and start a session.
2. Obtain a [JupyterHub API token](<https://analysis-facility.physics.purdue.edu/guide-ssh-access/index.md#jupyterhub-api-token>) and save it in `~/.config/purdue-af/token` as described there. On Windows, use it to replace `TOKEN` in the `~/.ssh/config` file instead.

## 5\. Configure SSH access on the Purdue AF side

This is the last step needed to allow your AF session to authorize connections from your local machine.

On your **local machine**, run this to copy your public key to the clipboard:

On Linux:

```shell
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard
```

On macOS:

```shell
cat ~/.ssh/id_ed25519.pub | pbcopy
```

On Windows:

```shell
type %USERPROFILE%\.ssh\id_ed25519.pub | clip
- OR, if using Git Bash or other shell -
cat ~/.ssh/id_ed25519.pub | clip
```

In the **AF session**, run the following commands one by one. When the `cat` command prompts for input, paste your public key (`Ctrl-V`) and press `Ctrl-D` to finish:

```shell
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cat >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
```

## 6\. Connect from your IDE

1. In your IDE (VSCode, Cursor, etc.), open the command palette (usually `Ctrl-Shift-P` or `Cmd-Shift-P`).
2. Search for the `Remote-SSH: Connect to Host...` command and select it.
3. Select `PurdueAF` from the host list. A new IDE window will open, connected to your AF session.
4. Once the connection is established, open a folder on the AF filesystem. It can be any folder in your home directory, or another directory you have access to (e.g. `/depot/cms/users/<username>/`, `/work/users/<username>/`, etc.).
5. Success! Now you can use your local IDE to browse and edit files in the AF. LLM-powered tools will also have access to your remote files, so you can use them to generate and debug code — but always be careful not to let them run dangerous commands, e.g. deleting important files.

## 7\. Install extensions on the AF side (optional)

After the connection succeeds, you can install extensions on the remote VSCode server that now runs on the AF side. To do that, simply open the Extensions tab in the IDE window connected to the AF.

> [!WARNING]
>
> The Jupyter extension, which runs remote notebooks from your local IDE, cannot discover the AF kernels, so running notebooks this way is not supported.

## Troubleshooting

If the connection fails, you can usually extract useful information from the IDE console. Some known caveats:

- SSH keys are ignored when your home directory is writable by group or others. Every session start sets the right permissions, so restart the session if you changed them.
- If you see errors like `websocat: command not found`, check that the `websocat` command is available on your local machine: `which websocat`. If it is not available, you need to install websocat; if it is available but you are still seeing the same error, change the `ProxyCommand` in the `~/.ssh/config` file to use the full path to the websocat binary (for example, `/opt/homebrew/bin/websocat`).
- If the connection stopped working after you restarted your session, your token may have expired — request a new token (step 4) and save it in `~/.config/purdue-af/token` (on Windows, in `~/.ssh/config`).
