Skip to content

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.

13 min read0/4 questions

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

  1. Open the Extensions view: Cmd+Shift+X on macOS, Ctrl+Shift+X on Windows and Linux.
  2. 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.
  3. 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.
  4. Sign in when asked.
How the pieces connect
You: type and reviewYoutype and reviewEditor: open file, selectionEditoropen file, selectionClaude panel: bundled Claude CodeClaude panelbundled Claude CodeYour project: files, tests, gitYour projectfiles, tests, gitDiff view: accept or rejectDiff viewaccept or rejectrequestcontextread, runproposed editreview

You type a request in the Claude panel, just like in the terminal.

1/4

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.

ShortcutWhat it does
Cmd+EscToggle focus between the editor and Claude
Option+KInsert an @-mention of your current selection
Shift+TabCycle permission modes
Cmd+Shift+XOpen 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.
Quick check
You select lines 12 to 20 of cart.ts and press Option+K (Alt+K). What appears in the prompt?
Need a nudge? A hint rules out a wrong answer.

Prompts that use the editor well

The editor lets you write shorter prompts that are also more precise. Compare:

VaguePrecise, 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 the pairs0/4 matched

Match each feature to what it gives you.

Choose an item, then its match on the other side.

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.

Building a Clear cart button
YouClaude panelEditorTestsplan: Clear cart buttonplan as a documentapproved, write tests firstrun the test suite1 failing (expected)diff: Cart.tsxrun againall passing

Switch to plan mode with Shift+Tab. Open Cart.tsx, select the cart header, press Option+K / Alt+K, and ask for a plan.

1/8

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 it in order5 steps

Put the editor workflow in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

Extension or terminal?

They are the same agent, so the choice is about where you are working.

Use the extension whenUse the terminal when
You want to point at code by selecting itYou work over SSH or on a server
You prefer reviewing edits as visual diffsYou want to script it with claude -p
You are making focused changes to files you have openYou run several sessions side by side
You want plan comments next to each stepYou 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.

Quick check
You want a nightly job that asks Claude to summarise new error logs and save the result to a file. Which surface fits best?
Need a nudge? A hint rules out a wrong answer.

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.

Key terms
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.