<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>claude code归档 - Liao&#039;s blog</title>
	<atom:link href="https://www.laobaiblog.top/tag/claude-code/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.laobaiblog.top/tag/claude-code/</link>
	<description>路漫漫其修远兮，吾将上下而求索</description>
	<lastBuildDate>Tue, 17 Mar 2026 12:17:51 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.laobaiblog.top/wp-content/uploads/2022/01/cropped-tyuu-32x32.png</url>
	<title>claude code归档 - Liao&#039;s blog</title>
	<link>https://www.laobaiblog.top/tag/claude-code/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>🚀 Claude Code × VSCode：开发者的 AI 终端利器配置指南</title>
		<link>https://www.laobaiblog.top/2026/03/17/%f0%9f%9a%80-claude-code-x-vscode%ef%bc%9a%e5%bc%80%e5%8f%91%e8%80%85%e7%9a%84-ai-%e7%bb%88%e7%ab%af%e5%88%a9%e5%99%a8%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97/</link>
		
		<dc:creator><![CDATA[大白]]></dc:creator>
		<pubDate>Tue, 17 Mar 2026 12:04:22 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[Anthropic]]></category>
		<category><![CDATA[claude code]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[vscode]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://www.laobaiblog.top/?p=602</guid>

					<description><![CDATA[<p>Claude Code × VSCode TL;DR：手把手带你从零安装 Claude Code，并 &#8230;</p>
<p><a href="https://www.laobaiblog.top/2026/03/17/%f0%9f%9a%80-claude-code-x-vscode%ef%bc%9a%e5%bc%80%e5%8f%91%e8%80%85%e7%9a%84-ai-%e7%bb%88%e7%ab%af%e5%88%a9%e5%99%a8%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97/">🚀 Claude Code × VSCode：开发者的 AI 终端利器配置指南</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></description>
										<content:encoded><![CDATA[<h1>Claude Code × VSCode</h1>
<blockquote><p>
  <strong>TL;DR</strong>：手把手带你从零安装 Claude Code，并在 VSCode 里解锁最强 AI 编程体验。
</p></blockquote>
<hr />
<h2>前言</h2>
<p><strong>Claude Code</strong> 是 Anthropic 推出的 CLI 工具，它不只是代码补全——它能读懂整个项目上下文、自主修改文件、执行命令、跑测试，像一个真正的结对编程伙伴坐在你的终端里。</p>
<p>配合 VSCode 扩展，你会得到一个无缝嵌入编辑器的 AI Agent。</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/2026/03/17/%f0%9f%9a%80-claude-code-x-vscode%ef%bc%9a%e5%bc%80%e5%8f%91%e8%80%85%e7%9a%84-ai-%e7%bb%88%e7%ab%af%e5%88%a9%e5%99%a8%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97/%e5%be%ae%e4%bf%a1%e5%9b%be%e7%89%87_20260317201323_45_3/"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/微信图片_20260317201323_45_3.jpg" alt="" /></a></p>
<hr />
<h2>环境准备</h2>
<h3>前置依赖</h3>
<table>
<thead>
<tr>
<th>工具</th>
<th>最低版本</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>Node.js</td>
<td><code>&gt;= 18.x</code></td>
<td>运行时环境</td>
</tr>
<tr>
<td>npm</td>
<td><code>&gt;= 9.x</code></td>
<td>随 Node.js 附带</td>
</tr>
<tr>
<td>VSCode</td>
<td><code>&gt;= 1.90</code></td>
<td>编辑器本体</td>
</tr>
</tbody>
</table>
<p>检查当前环境：</p>
<pre><code class="language-bash line-numbers">node -v
npm -v
</code></pre>
<hr />
<h2>安装 Claude Code</h2>
<h3>全局安装 CLI</h3>
<p>npm（通用，所有平台）：</p>
<pre><code class="language-bash line-numbers">npm install -g @anthropic-ai/claude-code
</code></pre>
<p>WinGet（Windows，我使用的）：</p>
<pre><code class="language-bash line-numbers">winget install Anthropic.ClaudeCode
</code></pre>
<p>Homebrew（macOS / Linux）：</p>
<pre><code class="language-bash line-numbers">brew install claude
</code></pre>
<p>macOS / Linux / WSL：</p>
<pre><code class="language-bash line-numbers">curl -fsSL https://claude.ai/install.sh | bash
</code></pre>
<p>Windows PowerShell：</p>
<pre><code class="language-powershell line-numbers">irm https://claude.ai/install.ps1 | iex
</code></pre>
<p>Windows CMD：</p>
<pre><code class="language-bash line-numbers">curl -fsSL https://claude.ai/install.cmd -o install.cmd &amp;&amp; install.cmd &amp;&amp; del install.cmd
</code></pre>
<p>安装完成后验证：</p>
<pre><code class="language-bash line-numbers">claude --version
</code></pre>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_04f8e275fb5034a031ebe0e29f40be21.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_04f8e275fb5034a031ebe0e29f40be21.jpg" alt="" /></a></p>
<hr />
<h2>🚨 国内用户必读：代理配置</h2>
<blockquote><p>
  <strong>问题根源</strong>：Anthropic 屏蔽了来自中国 IP 的 API 访问，影响所有环节——OAuth 登录、API 调用、CLI 和 VSCode 扩展。即使拥有付费的 Claude Max 订阅，从中国 IP 发出的请求一律返回 403。<strong>必须先配置代理，再启动 Claude Code。</strong>
</p></blockquote>
<p><a class="wp-editor-md-post-content-link" href="https://gist.github.com/docularxu/db0053008b9f41328f29d39ffcf7c2b2?permalink_comment_id=6005883">常见报错</a>：</p>
<pre><code class="line-numbers">OAuth error: Failed to fetch user roles: Request failed with status code 403
</code></pre>
<pre><code class="line-numbers">Unable to connect to Anthropic services
Failed to connect to api.anthropic.com: ERR_BAD_REQUEST
Note: Claude Code might not be available in your country.
</code></pre>
<p>以 v2rayN 为例（设置里查看端口，默认本地代理端口 <code>10808</code>，clash默认端口改为<code>7890</code>），需将 <code>HTTPS_PROXY</code> 环境变量指向本地代理。</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_95fd419c81c7226bf3a36406d56cda20.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_95fd419c81c7226bf3a36406d56cda20.jpg" alt="" /></a></p>
<h3>临时设置（仅当前窗口有效）</h3>
<p><strong>CMD：</strong></p>
<pre><code class="language-cmd line-numbers">set HTTPS_PROXY=http://127.0.0.1:10808
</code></pre>
<p><strong>PowerShell：</strong></p>
<pre><code class="language-powershell line-numbers">$env:HTTPS_PROXY = "http://127.0.0.1:10808"
</code></pre>
<p>设置后在<strong>同一窗口</strong>直接运行 <code>claude</code> 即可。</p>
<h3>永久设置（推荐，重启后仍有效）</h3>
<p><strong>方式一：图形界面（新手推荐）</strong></p>
<ol>
<li><code>Win + I</code> → 搜索「高级系统设置」→ 点击「环境变量」</li>
<li>在「用户变量」区域点击「新建」</li>
<li>变量名：<code>HTTPS_PROXY</code>，变量值：<code>http://127.0.0.1:10808</code></li>
<li>确定保存，重新打开命令行窗口生效</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_bc687a080f0be69a91791c495e677b77.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_bc687a080f0be69a91791c495e677b77.jpg" alt="" /></a></p>
<p><strong>方式二：命令行一键设置</strong></p>
<pre><code class="language-powershell line-numbers">[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://127.0.0.1:10808", [EnvironmentVariableTarget]::User)
</code></pre>
<p>执行后重新打开命令行窗口即可，无需重启电脑。</p>
<h3>验证是否生效</h3>
<pre><code class="language-cmd line-numbers">:: CMD
echo %HTTPS_PROXY%
</code></pre>
<pre><code class="language-powershell line-numbers"># PowerShell
echo $env:HTTPS_PROXY
</code></pre>
<p>输出 <code>http://127.0.0.1:10808</code> 即为设置成功，之后再启动 Claude Code。</p>
<hr />
<h2>启动 Claude Code</h2>
<p>进入你的项目目录，直接启动：</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_bdbdecc37df57fb8c89920f4e96421b8.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_bdbdecc37df57fb8c89920f4e96421b8.jpg" alt="" /></a></p>
<pre><code class="language-bash line-numbers">cd your-project
claude
</code></pre>
<p>弹出以下提示，选择 1 即可继续：</p>
<pre><code class="line-numbers">Accessing workspace: C:\Users\...
Quick safety check: Is this a project you created or one you trust?
❯ 1. Yes, I trust this folder
  2. No, exit
Enter to confirm · Esc to cancel
</code></pre>
<blockquote><p>
  若遇到连接报错。
</p></blockquote>
<pre><code class="line-numbers">Unable to connect to Anthropic services  
Failed to connect to api.anthropic.com: ERR_BAD_REQUEST  
Please check your internet connection and network settings.  
Note: Claude Code might not be available in your country. Check supported countries at https://anthropic.com/supported-countries
</code></pre>
<p><strong>Windows下操作:</strong></p>
<p>按下键盘 Win + R 键，输入 cmd 后回车，打开命令行程序<br />
在命令行中运行以下命令后回车</p>
<pre><code class="language-bash line-numbers">powershell -Command "<span class="katex math inline">f='%USERPROFILE%\.claude.json';</span>j=Get-Content <span class="katex math inline">f|ConvertFrom-Json;</span>j|Add-Member -NotePropertyName 'hasCompletedOnboarding' -NotePropertyValue <span class="katex math inline">true -Force;</span>j|ConvertTo-Json|Set-Content $f"
</code></pre>
<p>重启你的Claude Cli</p>
<p>首次启动会有简短的引导流程，授权完成后即可使用。</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_51a2e21b2bcccac52ea6d6ed8911fb34.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_51a2e21b2bcccac52ea6d6ed8911fb34.jpg" alt="" /></a></p>
<hr />
<h2>VSCode 扩展安装与配置</h2>
<h3>安装扩展</h3>
<p>打开 VSCode，按 <code>Ctrl+Shift+X</code> 打开扩展市场，搜索：</p>
<pre><code class="line-numbers">Claude Code
</code></pre>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_bc9879addb1c7d8307862eda8f54d09f.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2026/03/wp_editor_md_bc9879addb1c7d8307862eda8f54d09f.jpg" alt="" /></a></p>
<p>找到 <strong>Anthropic</strong> 官方发布的扩展，点击 Install。</p>
<p>或者直接通过命令行安装：</p>
<pre><code class="language-bash line-numbers">code --install-extension anthropic.claude-code
</code></pre>
<h3>扩展功能一览</h3>
<p>安装完成后，你将解锁以下能力：</p>
<ul>
<li><strong>内嵌聊天面板</strong> — 不离开编辑器，直接和 Claude 对话</li>
<li><strong>选中代码提问</strong> — 高亮代码后右键，发送给 Claude 分析</li>
<li><strong>差异视图</strong> — Claude 的修改建议以 diff 形式展示，一键接受或拒绝</li>
<li><strong>终端集成</strong> — Claude 可直接在 VSCode 内置终端执行命令</li>
</ul>
<hr />
<h2>核心用法速查</h2>
<h3>基础对话</h3>
<pre><code class="language-bash line-numbers"># 启动交互式会话
claude

# 单次提问（非交互模式）
claude -p "解释一下这个项目的架构"
</code></pre>
<h3>常用快捷指令</h3>
<p>在 Claude Code 会话中，输入 <code>/</code> 触发命令列表：</p>
<table>
<thead>
<tr>
<th>命令</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>/help</code></td>
<td>查看帮助</td>
</tr>
<tr>
<td><code>/clear</code></td>
<td>清空上下文</td>
</tr>
<tr>
<td><code>/compact</code></td>
<td>压缩对话历史，节省 token</td>
</tr>
<tr>
<td><code>/model</code></td>
<td>切换模型</td>
</tr>
<tr>
<td><code>/cost</code></td>
<td>查看本次会话消耗</td>
</tr>
<tr>
<td><code>/review-pr</code></td>
<td>PR 代码审查</td>
</tr>
<tr>
<td><code>/init</code></td>
<td>初始化项目，生成 <code>CLAUDE.md</code></td>
</tr>
</tbody>
</table>
<h3>让 Claude 读懂你的项目</h3>
<p>在项目根目录启动 Claude，进入交互式会话后执行：</p>
<pre><code class="line-numbers">/init
</code></pre>
<p>这会生成一个 <code>CLAUDE.md</code>，你可以在里面写：</p>
<ul>
<li>项目架构说明</li>
<li>技术栈约定</li>
<li>代码风格要求</li>
<li>不希望 Claude 修改的文件</li>
</ul>
<p>Claude 每次启动都会自动读取这个文件。</p>
<hr />
<h2>VSCode 进阶配置</h2>
<h3>settings.json 推荐配置</h3>
<p>打开 <code>Ctrl+Shift+P</code> → <code>Open User Settings (JSON)</code>，添加：</p>
<pre><code class="language-json line-numbers">{
  "terminal.integrated.defaultProfile.windows": "Git Bash"
}
</code></pre>
<blockquote><p>
  其他 Claude Code 相关选项可在 VSCode 设置页（<code>Ctrl+,</code>）搜索 <code>claude-code</code> 查看完整列表，按需开启。
</p></blockquote>
<h3>自定义键位绑定</h3>
<p>打开 <code>Ctrl+Shift+P</code> → <code>Open Keyboard Shortcuts (JSON)</code>：</p>
<pre><code class="language-json line-numbers">[
  {
    "key": "ctrl+shift+a",
    "command": "claude-code.openChat"
  },
  {
    "key": "ctrl+shift+r",
    "command": "claude-code.reviewSelection"
  }
]
</code></pre>
<hr />
<h2>权限模式说明</h2>
<p>Claude Code 在执行文件读写、命令时会请求权限，分三种模式：</p>
<table>
<thead>
<tr>
<th>模式</th>
<th>行为</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>默认</strong></td>
<td>每次操作都询问你</td>
</tr>
<tr>
<td><code>--dangerously-skip-permissions</code></td>
<td>全自动，不询问（仅限受信任环境）</td>
</tr>
<tr>
<td><code>--allowedTools</code></td>
<td>精确指定允许的工具范围，例如 <code>--allowedTools Bash,Edit</code></td>
</tr>
<tr>
<td><code>--print</code> / <code>-p</code></td>
<td>非交互模式，单次执行后退出，适合脚本集成</td>
</tr>
</tbody>
</table>
<hr />
<h2>Hooks 机制（进阶）</h2>
<p>Claude Code 支持配置 Hooks，在特定事件触发时执行自定义脚本。</p>
<p>编辑 <code>~/.claude/settings.json</code>：</p>
<pre><code class="language-json line-numbers">{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo '[HOOK] 即将执行 Bash 命令'"
          }
        ]
      }
    ]
  }
}
</code></pre>
<p>可以用来：审计命令执行、拦截危险操作、记录日志。</p>
<hr />
<h2>常见问题排查</h2>
<h3>Q：claude: command not found</h3>
<pre><code class="language-bash line-numbers"># 检查 npm 全局安装路径是否在 PATH 中
npm config get prefix
# 将 {prefix}/bin 加入 PATH
</code></pre>
<h3>Q：403 / 无法连接 Anthropic 服务（国内常见）</h3>
<p>先配置代理，参考上方「国内用户必读」章节。代理配置完成后，在<strong>同一终端窗口</strong>再次执行 <code>claude</code>。</p>
<h3>Q：VSCode 扩展无法连接</h3>
<p>代理环境变量必须在启动 VSCode 的终端中生效，或永久写入系统环境变量，VSCode 扩展才能继承代理设置。确认终端中 <code>claude</code> 命令可以正常执行后，重启 VSCode。</p>
<h2>小技巧 &amp; 最佳实践</h2>
<ul>
<li><strong>用 <code>CLAUDE.md</code> 约束行为</strong>：写明&#8221;不要修改 <code>config/</code> 目录下的文件&#8221;之类的规则，Claude 会遵守。</li>
<li><strong>善用 <code>/compact</code></strong>：长对话会消耗大量 token，及时压缩可以降低成本。</li>
<li><strong>选中代码再提问</strong>：在 VSCode 里高亮代码后打开 Claude 面板，上下文更精准。</li>
<li><strong>让 Claude 写测试</strong>：直接说&#8221;给这个函数写单元测试&#8221;，效果出奇得好。</li>
<li><strong>多模型切换</strong>：复杂推理用 Opus，日常编码用 Sonnet，速度与效果自由切换。</li>
</ul>
<hr />
<h2>总结</h2>
<pre><code class="line-numbers">安装 CLI → 装 VSCode 扩展 → 初始化 CLAUDE.md → 开始 vibe coding
</code></pre>
<p>Claude Code 最大的价值不是补全代码，而是<strong>理解项目、自主行动</strong>。把它当作一个真正的协作者，而不是一个更聪明的 Tab 键。</p>
<hr />
<p><em>本文基于 Claude Code 最新版本（2026年3月）编写，部分功能随版本更新可能有所变化。</em></p>
<p><a href="https://www.laobaiblog.top/2026/03/17/%f0%9f%9a%80-claude-code-x-vscode%ef%bc%9a%e5%bc%80%e5%8f%91%e8%80%85%e7%9a%84-ai-%e7%bb%88%e7%ab%af%e5%88%a9%e5%99%a8%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97/">🚀 Claude Code × VSCode：开发者的 AI 终端利器配置指南</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
