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:
# Method 1: Install via command palette
# Ctrl+Shift+P → Extensions → Search "Claude Code"
# Method 2: CLI install
claude install-vscodeAfter 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
claudecommand in the terminal.
// .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:
- Open Settings → Plugins → Marketplace;
- Search "Claude Code" and install;
- 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:
# Claude Code自动 detect$s $EDITOR and use it to display long text
export EDITOR="code --wait"
claudeAfter 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中最常用的键盘快捷键:
| Shortcut | Function |
|---|---|
Ctrl+C | Interrupt current operation |
Ctrl+D | Exit session |
Escape | Cancel current input |
Shift+Tab | Switch permission mode (normal → auto-accept → plan) |
Alt+M | Toggle multi-line input mode |
Ctrl+R | Search历史对话 |
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):
{
"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
$EDITORenvironment 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
- Install the VS Code extension (or JetBrains plugin); select a段 of code and ask Claude a question.
- Set the
EDITORenvironment variable tocode --wait;体验 editing commit messages in VS Code. - Try
Shift+Tabto switch between the threepermission modes; observe the behavior differences.
After mastering IDE integration, proceed to Chapter 15 to learn about SDK programmatic调用.