Lesson 9 of 40AI coding tools
Claude Code in VS Code
Install the Claude Code extension, share your file and selection as context, review edits as diffs, and build a small feature without leaving the editor.
The terminal version of Claude Code is powerful, but you spend most of your coding day in an editor. The Claude Code extension for VS Code puts the same agent in a panel next to your code. It can see which file you have open and what you have selected, and it shows every proposed change as a side-by-side diff you accept or reject. This lesson covers installing it, the shortcuts that make it fast, how it handles context and changes, and when to reach for the terminal instead. The previous lesson, Claude Code in the Terminal, covers sessions, permission modes and slash commands; all of that carries over here.
Install and open
- Open the Extensions view: Cmd+Shift+X on macOS, Ctrl+Shift+X on Windows and Linux.
- Search for Claude Code and install the one published by Anthropic. Its extension id is
anthropic.claude-code, which is how you tell it apart from look-alikes. - Open it. There are several ways: the spark icon in the editor toolbar (top right of an open file), the Activity Bar on the side, the status bar at the bottom, or by searching for Claude Code in the Command Palette.
- Sign in when asked.
You type a request in the Claude panel, just like in the terminal.
The shortcuts that matter
Two shortcuts do most of the work. Shortcuts can change between versions, so check the extension's docs if these do not respond.
| Shortcut | What it does |
|---|---|
| Cmd+Esc | Toggle focus between the editor and Claude |
| Option+K | Insert an @-mention of your current selection |
| Shift+Tab | Cycle permission modes |
| Cmd+Shift+X | Open the Extensions view |
| Shortcut | What it does |
|---|---|
| Ctrl+Esc | Toggle focus between the editor and Claude |
| Alt+K | Insert an @-mention of your current selection |
| Shift+Tab | Cycle permission modes |
| Ctrl+Shift+X | Open the Extensions view |
Using your editor as context
The biggest advantage of the extension is that what you look at becomes context. In the terminal you say "the function that parses dates in utils". In the editor you select it.
- Selection. Highlight some lines and ask "why does this return undefined for empty input?" The selection is shared automatically.
- @-mentions. Option+K (Alt+K on Windows) inserts a reference like
@dates.ts#5-10: the file plus the exact line range. This is precise and keeps the prompt short. You can type @-mentions of other files too. - Pointing beats pasting. A mention tells Claude where to look. It reads the file itself, so you do not fill the conversation with copied code.
cart.ts and press Option+K (Alt+K). What appears in the prompt?Prompts that use the editor well
The editor lets you write shorter prompts that are also more precise. Compare:
| Vague | Precise, using the editor |
|---|---|
| "There is a bug in the date code somewhere" | Select the function, then: "This returns the wrong day for dates near midnight UTC. Why?" |
| "Make the tests pass" | Open the failing test, then: "Make @dates.test.ts pass without changing the test." |
| "Refactor this file" | Select one block: "Extract this into a formatRange helper in the same file. Keep behaviour identical." |
Good editor prompts have three parts: what you are pointing at (a selection or mention), what is wrong or wanted, and a constraint ("without changing the test", "keep behaviour identical"). The constraint is what stops an agent from "fixing" a failing test by deleting it.
You can also hand Claude the editor's own view of problems. If VS Code is underlining an error, select the line and ask about it, or ask Claude to fix the errors in the open file. Pressing Cmd+Esc (Ctrl+Esc) to jump back to your code, reading the change, and jumping back into the panel becomes a fast rhythm.
Reviewing changes
When Claude wants to edit a file, the extension shows the change as a side-by-side diff: old code on one side, new code on the other. You accept or reject it. This is the moment to apply everything from Trust but Verify: read every line, not just the part you asked for.
Plans get the same treatment. In plan mode, the plan opens as a Markdown document you can comment on inline, the way you would comment on a teammate's design doc. Add "use the existing formatPrice helper here" next to the step it applies to, and Claude revises the plan before writing any code.
The panel also shows a permission mode indicator, so you can always see whether Claude will ask before editing. Shift+Tab cycles modes here too. Past conversations are kept in the session history, so you can return to one later.
Match each feature to what it gives you.
Walkthrough: a small feature in the editor
Say you have a shop app and want a "Clear cart" button that empties the cart after a confirmation.
Switch to plan mode with Shift+Tab. Open Cart.tsx, select the cart header, press Option+K / Alt+K, and ask for a plan.
A few details make this go smoothly. Keep the request small enough to review in one sitting: one button, not "redesign the cart". If a diff touches a file you did not expect, reject it and ask why before accepting anything. And if Claude goes off track mid-task, stop it, say what was wrong, and let it continue from there, rather than accepting a half-right change to fix later.
Notice what you did not do: copy code into a chat, paste errors back, or switch windows. The editor gave Claude its context, and the diff view gave you control.
Put the editor workflow in order.
- Tap the steps below in the right order.
Extension or terminal?
They are the same agent, so the choice is about where you are working.
| Use the extension when | Use the terminal when |
|---|---|
| You want to point at code by selecting it | You work over SSH or on a server |
| You prefer reviewing edits as visual diffs | You want to script it with claude -p |
| You are making focused changes to files you have open | You run several sessions side by side |
| You want plan comments next to each step | You use another editor |
Many people use both: the panel for focused work on the file in front of them, a terminal for longer tasks or scripts.
Claude Code is not limited to VS Code. There is also a JetBrains plugin, a desktop app, a web version at claude.ai/code, a Slack integration and GitHub Actions; the ideas in this lesson carry over to all of them.
- extension
- An add-on that adds features to VS Code, installed from the Extensions view.
- @-mention
- A reference to a file or line range in a prompt, like @utils.ts#5-10, so Claude reads exactly that code.
- side-by-side diff
- A view showing old and new code next to each other so you can accept or reject a change.
- Activity Bar
- The column of icons on the edge of VS Code for switching between views.
- integrated terminal
- The terminal built into VS Code, where the standalone claude command can run.
- diagnostics
- Errors and warnings reported by VS Code's language tools for your files.