Skip to content

Chapter 14 · IDE Integration ​

Chapter goals: Master Claude Code's integration with mainstream IDEs — VS Code extension, JetBrains plugin, terminal-embedded linkage, and common keybinding mappings,实现 "seamlessly calling AI inside the editor."

14.1 VS Code Extension ​

Claude Code provides a VS Code extension; after installing, use it directly from the editor sidebar:

bash
# Method 1: Install via command palette
# Ctrl+Shift+P → Extensions → Search "Claude Code"

# Method 2: CLI install
claude install-vscode

After installation, a Claude Code icon appears in the sidebar. Clicking opens a对话 panel; the extension自动感知s the currently open file and workspace context.

Core capabilities:

  • Ask Claude about selected code: select a段 of code in the editor, right-click "Ask Claude"; the对话 automatically附带s the selected content;
  • Inline diff preview: when Claude修改s files, VS Code展示s changes in a diff view; you can accept or reject each line;
  • Terminal sharing: the extension共享s session state with the claude command in the terminal.
json
// .vscode/settings.json — extension config example
{
  "claude-code.autoStart": true,
  "claude-code.defaultModel": "sonnet",
  "claude-code.showDiffOnEdit": true
}

14.2 JetBrains Plugin ​

IntelliJ IDEA / WebStorm / PyCharm and other JetBrains IDEs install via the plugin marketplace:

  1. Open Settings → Plugins → Marketplace;
  2. Search "Claude Code" and install;
  3. Restart the IDE; find the Claude Code panel in the右侧 toolbar.

The JetBrains plugin's core功能 is similar to VS Code: code selection asking, diff review, terminal integration. Additionally supports Action prompts (Alt+Enter) — quickly调用 Claude at the cursor for refactoring or fixing.

14.3 Terminal-Embedded Editor Linkage ​

Even without installing the IDE extension, Claude Code running in the terminal can感知 your editor environment:

bash
# Claude Code自动 detect$s $EDITOR and use it to display long text
export EDITOR="code --wait"
claude

After setting EDITOR, when Claude Code needs you to edit multi-line text (e.g. writing CLAUDE.md or a commit message), it automatically opens a临时 file in VS Code; after saving and closing, the content回传s to Claude Code.

14.4 Keybinding Mappings ​

以下是 Claude Code中最常用的键盘快捷键:

ShortcutFunction
Ctrl+CInterrupt current operation
Ctrl+DExit session
EscapeCancel current input
Shift+TabSwitch permission mode (normal → auto-accept → plan)
Alt+MToggle multi-line input mode
Ctrl+RSearch历史对话

keybindingFlavor Setting

v2.1.238 introduced the keybindingFlavor setting. Set it to "readline" to let Ctrl+W delete the previous word按 Bash习惯 in the prompt box (default "classic" behavior unchanged):

json
{
  "keybindingFlavor": "readline"
}

Chapter Summary ​

  • The VS Code extension provides a sidebar对话, ask-about-selection, and diff preview;
  • The JetBrains plugin supports Alt+Enter quick calls;
  • The $EDITOR environment variable lets Claude Code use your preferred editor for multi-line text;
  • keybindingFlavor可自定义 keybinding styles.

🧪 随堂测验

点击你认为正确的选项。答错时会展示正确答案与原因解析。

1. How do you quickly ask Claude a question about selected code in VS Code?

2. Which environment variable controls which editor Claude Code uses for multi-line text?

3. What does the `keybindingFlavor: "readline"` setting do?

4. What does Shift+Tab do in Claude Code?

🛠️ Hands-on Practice ​

  1. Install the VS Code extension (or JetBrains plugin); select a段 of code and ask Claude a question.
  2. Set the EDITOR environment variable to code --wait;体验 editing commit messages in VS Code.
  3. Try Shift+Tab to switch between the threepermission modes; observe the behavior differences.

After mastering IDE integration, proceed to Chapter 15 to learn about SDK programmatic调用.