VS Code Integration
Use the Claude Code extension in VS Code
VS Code Integration¶
In addition to using Claude Code CLI in the terminal, you can use the VS Code extension to access Claude Code directly in the editor for a more convenient development experience.
Prerequisites¶
Before configuring the VS Code extension, ensure:
- Claude Code CLI is installed and working
- See Installation Guide to complete installation
-
See Environment Configuration to complete setup
-
VS Code version >= 1.75.2
Installation Steps¶
Step 1: Install VS Code¶
If VS Code is not installed, visit the VS Code website to download and install.
Step 2: Install Claude Code Extension¶
In VS Code:
- Open the Extensions panel (
Ctrl+Shift+X/Cmd+Shift+X) - Search for "Claude Code for VS Code"
- Click Install
Or install via command line:
code --install-extension anthropic.claude-code
Step 3: Configure primaryApiKey¶
This is a critical step! The Claude Code extension requires primaryApiKey in the configuration file.
Windows¶
Edit or create the config file C:\Users\YourUsername\.claude\config.json:
{
"primaryApiKey": "qcode"
}
macOS¶
Edit or create the config file ~/.claude/config.json:
# Create directory (if it doesn't exist)
mkdir -p ~/.claude
# Create config file
cat > ~/.claude/config.json << 'EOF'
{
"primaryApiKey": "qcode"
}
EOF
Linux¶
Edit or create the config file ~/.claude/config.json:
# Create directory (if it doesn't exist)
mkdir -p ~/.claude
# Create config file
cat > ~/.claude/config.json << 'EOF'
{
"primaryApiKey": "qcode"
}
EOF
Note: The value of
primaryApiKeycan be anything (likeqcode). You just need to have this field configured. The actual API authentication still uses theANTHROPIC_AUTH_TOKENyou configured in environment variables.Important: The config file is
config.json, NOTsettings.json. Please distinguish between these two files carefully.
Step 4: Restart VS Code¶
After configuration, restart VS Code for changes to take effect.
Usage¶
Keyboard Shortcuts¶
| Shortcut | Function |
|---|---|
Cmd+Esc / Ctrl+Esc |
Open/Close Claude Code panel |
Cmd+Shift+P / Ctrl+Shift+P |
Open command palette, search for Claude commands |
Common Features¶
- Code Explanation
- Select code
- Right-click and choose "Ask Claude" or use shortcut
-
Enter your question, e.g., "Explain this code"
-
Code Generation
- Open Claude panel
- Describe the feature you need
-
Claude will generate code with insert options
-
Code Refactoring
- Select code to refactor
- Ask Claude to help refactor
-
Preview and apply changes
-
Error Fixing
- When code has errors
- Select the error code or message
- Ask Claude to analyze and provide fixes
Configuration Options¶
In VS Code settings, you can configure Claude Code extension behavior:
- Open Settings (
Ctrl+,/Cmd+,) - Search for "Claude Code"
- Adjust options as needed
Common Settings¶
{
"claude-code.autoSuggest": true,
"claude-code.inlineChat": true
}
Using with Terminal CLI¶
The VS Code extension and terminal CLI can be used together:
| Scenario | Recommended Tool |
|---|---|
| Quick code edits | VS Code extension |
| Complex project analysis | Terminal CLI |
| Code review | Either |
| Git operations | Terminal CLI |
| File generation | Either |
Troubleshooting¶
Extension Won't Start¶
- Confirm Claude Code CLI is properly installed
- Check environment variable configuration
- Verify
config.jsonfile format is correct
primaryApiKey Error¶
- Confirm file path is correct:
- Windows:
C:\Users\YourUsername\.claude\config.json - macOS/Linux:
~/.claude/config.json - Confirm it's
config.jsonnotsettings.json - Confirm JSON format is valid
Connection Timeout¶
- Check network connection
- Verify
ANTHROPIC_BASE_URLenvironment variable - Try running
claudein terminal to confirm CLI works
Next Steps¶
- See Cursor Integration for using Claude Code in Cursor
- Explore CLI Tips to boost efficiency
- Learn Workflow Tips to optimize development flow