# Add Keyboard Shortcuts to a VS Code Extension

Yes. An agent adds a keybindings contribution for your extension's commands, with a when clause and a mac variant, tests it in the extension host, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-keybindings/vscode-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the manifest and the test setup first, because a keybinding is declared, not coded, and the only proof it works runs inside VS Code. In an extension like `helloworld-test-sample` in microsoft/vscode-extension-samples, `package.json` sets `engines.vscode` to `^1.100.0`, an empty `activationEvents` list (the command contribution activates the extension), and `contributes.commands` with one entry, `extension.helloWorld` titled `Hello World`. `src/extension.ts` registers that command with `vscode.commands.registerCommand` and shows a `Hello World` message with `showInformationMessage`. Scripts are `compile` (`tsc -p ./`), `lint` (`eslint`), `pretest` and `test` (`node ./out/test/runTest.js`); `src/test/runTest.ts` downloads VS Code with `@vscode/test-electron` and runs `src/test/suite/index.ts`, a Mocha `tdd` runner over `**/**.test.js`, whose only test so far asserts on an array index. The repository's `.github/workflows/ci.yml` runs `npm ci --workspaces=false` and `npm run validate` at the root; `vim-sample/package.json` shows how this repository writes `contributes.keybindings` with `key` and `when`.

The agent adds `contributes.keybindings` to `package.json` with one entry per command: `command: extension.helloWorld`, `key: ctrl+alt+h`, `mac: cmd+alt+h`, and `when: editorTextFocus` so the chord only fires while an editor has focus and stays free for other extensions in the terminal or the sidebar. A `menus.commandPalette` entry with the same `when` is added so the palette and the shortcut agree about where the command is available. Nothing in `src/extension.ts` changes: VS Code routes the key to the registered command.

The test is the part a developer usually skips. The agent replaces the placeholder test in `src/test/suite/extension.test.ts` with two real ones: `vscode.commands.getCommands(true)` must include `extension.helloWorld`, and `vscode.extensions.getExtension('vscode-samples.helloworld-sample')` must resolve, with `packageJSON.contributes.keybindings` containing an entry whose `command` is `extension.helloWorld`, whose `key` is `ctrl+alt+h`, and whose `when` is `editorTextFocus`. That checks the manifest VS Code actually loaded, not the file on disk. A third test executes the command with `vscode.commands.executeCommand` and asserts it resolves.

The agent runs `npm install`, `npm run compile`, `npm run lint` and `xvfb-run -a npm test` in its sandbox, where `@vscode/test-electron` downloads a VS Code build and runs the suite in the extension host, and includes the output. It adds a `Keyboard shortcut` line to the sample's `README.md` naming the chord on each platform, and runs `npm run validate` from the repository root as `ci.yml` does.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add keyboard shortcuts for this VS Code extension's commands. Read package.json, src/extension.ts, src/test/runTest.ts, src/test/suite/index.ts, src/test/suite/extension.test.ts and the README first. Add a contributes.keybindings entry for each command in contributes.commands, with a key, a mac variant and a when clause of editorTextFocus, and a menus.commandPalette entry with the same when clause. Do not change the command implementation. Replace the placeholder test with tests that run in the extension host: the command is registered, the loaded extension's packageJSON contributes a keybinding with the expected command, key and when, and executing the command resolves. Run npm install, npm run compile, npm run lint and the test script under xvfb, add the shortcut to the README, and include the output. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that changes `package.json` (`contributes.keybindings` and `contributes.menus`), `src/test/suite/extension.test.ts` (three tests replacing the placeholder) and `README.md` (the shortcut). `src/extension.ts`, `src/test/runTest.ts`, `src/test/suite/index.ts` and `tsconfig.json` are untouched.

The description names the chord on Windows, Linux and macOS, quotes the Mocha summary from the extension host run and the `tsc` and `eslint` results, and asks the reviewer to confirm the chord is free in their own keymap. The commands and the full output are in the transcript at `GET /o/{org}/sessions/{id}/messages`.

Before merging, a reviewer opens the Keyboard Shortcuts editor, which lists conflicts for the chord, and decides whether `editorTextFocus` is the right scope or the command should also work from the Explorer. A follow-up message to the same session can change the chord or add a second binding.

## Run it on every Linear issue labelled shortcut

Set up an automation with a Linear trigger on the `shortcut` label and this prompt, scoped to the Project that holds the extension. The trigger appends the issue to the prompt, so an issue that names the command and the chord a user asked for starts a run that binds exactly that, tests it in the extension host, and opens its own pull request.

From your own server, send `POST /o/{org}/sessions` with the repository in `resources` and the issue URL as a second resource, and a `request_id` that is a UUID v5 of the issue identifier so a retried call returns the run already started. The key's `webhook_url` reports when each run the key starts finishes.

## Why run it on Rush?

A keybinding is four lines of JSON that nobody tests, so the typo in `when` or the chord that collides with a built-in command ships to the Marketplace and comes back as an issue. The agent writes the contribution, then proves it in a sandbox by downloading VS Code and asserting on the manifest the extension host actually loaded.

The pull request carries the extension-host test output, so a reviewer checks the chord and the scope rather than installing the branch to press keys. An organisation with several extensions can run the same prompt on each, in parallel, each in its own sandbox with its own pull request.

## Frequently asked questions

### How do I know the chord does not clash with a built-in?

The pull request names the chord and asks the reviewer to open the Keyboard Shortcuts editor, which shows every command bound to it. The `when: editorTextFocus` clause keeps it out of the terminal and views, which is where most collisions with other extensions happen. A user can always override it in their own `keybindings.json`.

### Why add a commandPalette menu entry too?

So the palette hides the command in the same situations the shortcut does not fire. Without it the command appears in the palette while no editor is focused, runs, and surprises the user. The two `when` clauses are kept identical on purpose.

### Do the tests really press the key?

No. VS Code owns key dispatch and does not expose a way to simulate a chord in tests. The tests assert the loaded manifest contributes the binding, that the command is registered, and that executing it resolves, which is everything the extension controls.

### Does the test need a display?

It needs an X server because `@vscode/test-electron` starts a real VS Code window. The agent runs it under `xvfb-run` in its sandbox; the repository's CI runs only `npm run validate` and does not run the extension host tests, which the pull request notes.

## More VS Code Extension jobs

- [Add Output Channel Logging to a VS Code Extension](https://getrush.ai/run/add-output-channel-logging/vscode-extension/)
- [Add a Release Workflow for a VS Code Extension](https://getrush.ai/run/add-release-workflow/vscode-extension/)
- [Add Telemetry to a VS Code Extension](https://getrush.ai/run/add-telemetry/vscode-extension/)

## More jobs like this: Turn a Linear label into a PR

- [Add Keyboard Shortcuts to a Chrome Extension](https://getrush.ai/run/add-keyboard-shortcuts/chrome-extension/)
- [Add Keyboard Shortcuts to an Electron App from a Linear Issue](https://getrush.ai/run/add-keyboard-shortcuts/electron/)
- [Add KV Caching to a Cloudflare Worker](https://getrush.ai/run/add-kv-caching/cloudflare-workers/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
