🤖
Use Cursor with GitHub Codespaces
Cursor is a lightning-fast, AI-powered code editor. GitHub Codespaces gives you a prebuilt cloud dev environment. Connecting the two gives you the power of a cloud IDE with the feel of a local editor.
Here’s how to set them up to work together — and what to do when it doesn’t work.

✅ What you’ll get

  • Use Cursor to edit code inside a live GitHub Codespace
  • Push to GitHub, deploy, run, test — all from within Cursor
  • No fake "remote folders", this is the actual Codespace

Prerequisites

  • A GitHub Codespace already created
  • GitHub CLI installed (gh)
  • SSH working on your machine

 

Problem

Failure to connect to a GitHub codespace when using Cursor
 
 

Solution

Download the “Remote-SSH” extension/plugin if you haven’t already.
 
By the end of this guide, you’ll be able to select your GitHub codespace as an option.

🔐 Step 0: Set up your SSH key (first-time only)

Create an SSH key.
Upload it to GitHub.
 
If you haven’t used SSH with GitHub before, you’ll need to create a key and upload it to your GitHub account.

✅ Check if you already have a key:

ls ~/.ssh/id_ed25519.pub
If that file exists, skip to Step 1.

✅ If not, generate a new key:

ssh-keygen -t ed25519 -C "your_email@example.com"
  • Press Enter to accept the default file location
  • Set a passphrase if you want (or leave blank for simplicity)
Then add the key to your SSH agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

✅ Upload the key to GitHub:

Copy it:
cat ~/.ssh/id_ed25519.pub
Then go to https://github.com/settings/keys → New SSH key → paste it in → give it a name (e.g., MacBook).
 

🔐 Step 1: Authenticate with GitHub CLI

Run:
gh auth login
  • Select: GitHub.com
  • Choose protocol: HTTPS or SSH
  • Log in via browser
✅ Make sure it says:
Logged in as your-username

🔗 Step 2: Generate SSH config for your Codespace

Run this:
gh codespace ssh --config
This outputs a block like:
Host cs.friendly-mongoose-xyz.main
  User vscode
  ProxyCommand /usr/local/bin/gh cs ssh -c friendly-mongoose-xyz --stdio -- -i /Users/you/.ssh/codespaces.auto
  IdentityFile /Users/you/.ssh/codespaces.auto
  StrictHostKeyChecking no
  UserKnownHostsFile=/dev/null
  ControlMaster auto
  LogLevel quiet


✍️ Step 3: Add it to your SSH config

Append it to your SSH config file:
gh codespace ssh --config >> ~/.ssh/config
This tells SSH (and Cursor) how to connect to your running Codespace.

🧭 Step 4: Fix Cursor’s Remote SSH settings

By default, Cursor may look at the wrong SSH config file.
Cmd+Shift+P → type Remote-SSH: Settings
This is essential. If it points to something like ~/.ssh/devboxes, you won’t see any Codespaces listed.
Change SSH config path to:
~/.ssh/config
I had to change my settings from ~/.ssh/devboxes (no such file exists) to ~/.ssh/config (which is the file we made/updated in the last step).

🚀 Step 5: Connect

  1. Cmd+Shift+P → Remote-SSH: Connect to Host…
  1. You’ll now see your Codespace (e.g. cs.friendly-mongoose-xyz.main)
  1. Click it — you're in 🎉
You’re now running Cursor connected over SSH to your GitHub-hosted Codespace.

🛠️ Troubleshooting

❗ 1. "No Codespaces appear" in Connect to Host…

Fix: Make sure Cursor is looking at the correct config file (~/.ssh/config), not ~/.ssh/devboxes.
Cmd-Shift-P, select “Connect to Host…”
By the end of this guide, you’ll be able to select your GitHub codespace as an option.
If you don’t see your codespace
 
A - Cmd-Shift-P “Remote - SSH settings”
Check that it’s reading the correct local ssh config file.
B - [not sure if this step is necessary] Try starting the codespace (on GitHub.com/codespaces or in VS Code), or Ensure it’s running with gh codespace list.
 

❗ 2. "Permission denied" or "403 Unauthorized" errors from gh

The GitHub CLI may be missing required scopes. Run:
gh auth refresh -h github.com -s codespace,admin:public_key,read:org
✅ This upgrades your auth token to allow Codespace access via SSH.
You may be prompted to re-authenticate in the browser.

❗ 3. gh codespace ssh --config fails with “no SSH server installed”

If your Codespace was rebuilt recently, you may need to add SSH support:
Edit your .devcontainer/devcontainer.json:

"features": {
  "ghcr.io/devcontainers/features/sshd:1": {
    "version": "latest"
  }
}
Then rebuild the container (Cmd+Shift+P → "Rebuild Container").

❗ 4. “Where’s my code?” after connecting

Once connected, run:
ls /workspaces
cd /workspaces/your-repo-name
That’s where GitHub mounts your codebase inside the container.
You can also click “Open Folder” and browse to /workspaces/your-repo-name.
 
⚠️ Do NOT accidentally attempt your old “connect to codespace” flow.
 
 
Instead, click “File → Open folder”.
Type “workspaces”.
Select your project within (mine is called awe2023 )
 
In my case, that’s /workspaces/awe2023 →”OK”
 
In terms of folder structure, I first arrived into home/vscode/
the workspaces/ folder is a sibling folder of home/
$ pwd
/home/vscode
@markitics ➜ ~ $ ls
@markitics ➜ ~ $ ls ../..
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var     workspaces
boot  etc  lib   media  opt  root  sbin  sys  usr  vscode
@markitics ➜ ~ $ cd ../../workspaces/
@markitics ➜ /workspaces $ ls
awe2023
@markitics ➜ /workspaces $ cd awe2023/
 

❗ 5. ”Dev Container” popup: dismiss

If you get this pop-up in the bottom left corner, dismiss it:
You’re already SSH’d into the running container via Cursor. If you click “Reopen in Container,” Cursor will try to create a new Docker container inside the Codespace, which isn’t what you want, probably won’t work cleanly, wI’ll break the current setup.
 
 
 

🧠 Under the Hood

  • The gh CLI handles OAuth, SSH key generation, and Codespace access.
  • Cursor (like VS Code) uses the Remote - SSH plugin and reads from ~/.ssh/config
  • The Codespace itself runs an SSH server, enabled via the sshd feature
  • codespaces.auto is the default key GitHub generates for SSH access — you don’t need to create your own
    • The original motivation that “hm, maybe I can indeed do it with the “Remote - SSH” plugin was this helpful blog post by @NFAblog.

✅ Summary


Now you’re using Cursor + GitHub Codespaces like a pro. Fast local editing with real cloud compute.
 
 

About this post

Most of the above blog post was written by ChatGPT and I haven’t proof-read it in detail. I (Mark Moriarty) can confirm I did get Cursor working for me, can get Cursor composer to suggest and implement edits, I can git push after I’ve committed changes, and I can eb deploy to deploy an updated app to Elastic Beanstalk. (I had to manually install awscli, eb cli, and I customised my ~/.git/config to include personalized shortcuts).
 
 
Once again, the main unlock is copying gh codespace ssh --config to local ~/.ssh/config, which I found on https://medium.com/@NFAblog/connect-github-codespaces-to-cursor-ai-ai-friendly-vs-code-clone-243fa5f79414
Â