Claude Code:
最近刷屏這個詞:Claude Code 以后叫 CC,它是?Anthropic 的一款智能編程工具,幾個特點:
- 在終端運行?像使用命令行工具一樣,無需圖形用戶界面 GUI
- 深度理解整個代碼庫?
- 使用自然語言 讓其修復 bug、生成代碼、重構代碼、甚至運行測試。
- 代理式編程工具?"Agentic Coding Tool"?提供代碼建議,還能直接在你的開發環境中編輯文件并執行命令,實現自動化編程
總而言之,CC 就是在你終端里工作的 AI 助手,能理解你的代碼,并依照你給出的自然語言指令,來幫助你完成編寫、修改以及調試代碼。
可憐的京東云用戶:
在準備安裝環境時,我還以為 京東云 輕量應用服務器 VPS?掉線了。看下面截圖:、
Apt 源都是清華,都是運行同樣的命令:
sudo apt update && sudo apt upgrade -y
這臺是 北京-騰訊云 4Mbps 帶寬 VPS:?2C2G50GB
這臺是 北京-京東云 帶寬?5Mbps,?VPS: 2C4G60GB
看看騰訊在小日本兒-京東?VPS:2C2G50GB 網絡 30Mbps
下面這個 VPS 在美國,1C1G10GB 網絡 50Mbps,不到?$13/yr 含一個公網IP
再看看從國外源的下載速度:
騰訊-北京云:
京東-北京云:
這就是我為什么開工單,要 “京東” 調整, 說好的 5Mbps 帶寬,到了國際出口就 100.8Kbps ,只有?1/50 性能
開個工單:
運行商信息:
供應商 | 配置 | 帶寬 | 每月-流量 | 費用 |
京東-北京云 | 2C4G60GB | 5Mbps | 雙向 500GB | 36個月:498/原價2459.16 |
騰訊-北京云 | 2C2G50GB | 4Mbps | 單向 1024GB | 12個月:99元 |
騰訊-日本京東云 | 2C2G50GB | 30Mbps | 單向 300GB | 12個月:99元 |
美國加州 | 1C1G10GB | 50Mbps | 雙向 512GB | 12個月:不到 95元 |
注:C=CPU's core,G=內存,GB=硬盤
安裝 Claude Code
參考:Set up Claude Code - Anthropic??
????????? ?https://docs.anthropic.com/en/docs/claude-code/setup
1 確保 Ubuntu 24 是最新的系統
sudo apt update && sudo apt upgrade -y
2 安裝 Node.js 18以上的版本 與 npm?
sudo apt remove nodejs npm
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
校驗 Node.js / npm 安裝的版本:
node --version # Should show v20.x.x
npm --version # Should show 10.x.x or higher
root@usw:~# sudo apt remove nodejs npm
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'nodejs' is not installed, so not removed
Package 'npm' is not installed, so not removed
The following packages were automatically installed and are no longer required:
? linux-image-6.8.0-35-generic linux-modules-6.8.0-35-generic linux-modules-extra-6.8.0-35-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2025-06-23 07:50:58 - Installing pre-requisites
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Get:2 https://pkgs.tailscale.com/stable/ubuntu noble InRelease ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Get:3 http://nova.clouds.archive.ubuntu.com/ubuntu noble InRelease [256 kB] ? ? ? ? ? ? ? ? ? ? ? ??
Hit:4 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:5 http://nova.clouds.archive.ubuntu.com/ubuntu noble-backports InRelease
Fetched 262 kB in 2s (170 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apt-transport-https is already the newest version (2.8.3).
ca-certificates is already the newest version (20240203).
curl is already the newest version (8.5.0-2ubuntu10.6).
The following packages were automatically installed and are no longer required:
? linux-image-6.8.0-35-generic linux-modules-6.8.0-35-generic linux-modules-extra-6.8.0-35-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
? dirmngr gnupg-utils gpg-agent gpgsm keyboxd libksba8 pinentry-curses
Suggested packages:
? pinentry-gnome3 tor parcimonie xloadimage gpg-wks-server scdaemon pinentry-doc
Recommended packages:
? gnupg-l10n gpg-wks-client
The following NEW packages will be installed:
? dirmngr gnupg gnupg-utils gpg-agent gpgsm keyboxd libksba8 pinentry-curses
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 1485 kB of archives.
After this operation, 3411 kB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libksba8 amd64 1.6.6-1build1 [122 kB]
Get:2 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 dirmngr amd64 2.4.4-2ubuntu17.2 [323 kB]
Get:3 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 gnupg-utils amd64 2.4.4-2ubuntu17.2 [109 kB]
Get:4 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 pinentry-curses amd64 1.2.1-3ubuntu5 [35.2 kB]
Get:5 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg-agent amd64 2.4.4-2ubuntu17.2 [227 kB]
Get:6 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgsm amd64 2.4.4-2ubuntu17.2 [232 kB]
Get:7 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 keyboxd amd64 2.4.4-2ubuntu17.2 [78.3 kB]
Get:8 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 gnupg all 2.4.4-2ubuntu17.2 [359 kB]
Fetched 1485 kB in 0s (4153 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libksba8:amd64.
(Reading database ... 55112 files and directories currently installed.)
Preparing to unpack .../0-libksba8_1.6.6-1build1_amd64.deb ...
Unpacking libksba8:amd64 (1.6.6-1build1) ...
Selecting previously unselected package dirmngr.
Preparing to unpack .../1-dirmngr_2.4.4-2ubuntu17.2_amd64.deb ...
Unpacking dirmngr (2.4.4-2ubuntu17.2) ...
Selecting previously unselected package gnupg-utils.
Preparing to unpack .../2-gnupg-utils_2.4.4-2ubuntu17.2_amd64.deb ...
Unpacking gnupg-utils (2.4.4-2ubuntu17.2) ...
Selecting previously unselected package pinentry-curses.
Preparing to unpack .../3-pinentry-curses_1.2.1-3ubuntu5_amd64.deb ...
Unpacking pinentry-curses (1.2.1-3ubuntu5) ...
Selecting previously unselected package gpg-agent.
Preparing to unpack .../4-gpg-agent_2.4.4-2ubuntu17.2_amd64.deb ...
Unpacking gpg-agent (2.4.4-2ubuntu17.2) ...
Selecting previously unselected package gpgsm.
Preparing to unpack .../5-gpgsm_2.4.4-2ubuntu17.2_amd64.deb ...
Unpacking gpgsm (2.4.4-2ubuntu17.2) ...
Selecting previously unselected package keyboxd.
Preparing to unpack .../6-keyboxd_2.4.4-2ubuntu17.2_amd64.deb ...
Unpacking keyboxd (2.4.4-2ubuntu17.2) ...
Selecting previously unselected package gnupg.
Preparing to unpack .../7-gnupg_2.4.4-2ubuntu17.2_all.deb ...
Unpacking gnupg (2.4.4-2ubuntu17.2) ...
Setting up libksba8:amd64 (1.6.6-1build1) ...
Setting up pinentry-curses (1.2.1-3ubuntu5) ...
Setting up gpg-agent (2.4.4-2ubuntu17.2) ...
Created symlink /etc/systemd/user/sockets.target.wants/gpg-agent.socket → /usr/lib/systemd/user/gpg-agent.socket.
Created symlink /etc/systemd/user/sockets.target.wants/gpg-agent-ssh.socket → /usr/lib/systemd/user/gpg-agent-ssh.socket.
Created symlink /etc/systemd/user/sockets.target.wants/gpg-agent-extra.socket → /usr/lib/systemd/user/gpg-agent-extra.socket.
Created symlink /etc/systemd/user/sockets.target.wants/gpg-agent-browser.socket → /usr/lib/systemd/user/gpg-agent-browser.socket.
Setting up gpgsm (2.4.4-2ubuntu17.2) ...
Setting up dirmngr (2.4.4-2ubuntu17.2) ...
Created symlink /etc/systemd/user/sockets.target.wants/dirmngr.socket → /usr/lib/systemd/user/dirmngr.socket.
Setting up keyboxd (2.4.4-2ubuntu17.2) ...
Created symlink /etc/systemd/user/sockets.target.wants/keyboxd.socket → /usr/lib/systemd/user/keyboxd.socket.
Setting up gnupg-utils (2.4.4-2ubuntu17.2) ...
Setting up gnupg (2.4.4-2ubuntu17.2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Get:2 https://deb.nodesource.com/node_20.x nodistro InRelease [12.1 kB] ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Get:3 http://nova.clouds.archive.ubuntu.com/ubuntu noble InRelease [256 kB] ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Get:4 https://pkgs.tailscale.com/stable/ubuntu noble InRelease ? ? ? ? ? ? ? ? ? ? ??
Get:5 https://deb.nodesource.com/node_20.x nodistro/main amd64 Packages [11.5 kB] ? ?
Hit:6 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:7 http://nova.clouds.archive.ubuntu.com/ubuntu noble-backports InRelease
Fetched 286 kB in 2s (176 kB/s)
Reading package lists... Done
2025-06-23 07:51:13 - Repository configured successfully.
2025-06-23 07:51:13 - To install Node.js, run: apt-get install nodejs -y
2025-06-23 07:51:13 - You can use N|solid Runtime as a node.js alternative
2025-06-23 07:51:13 - To install N|solid Runtime, run: apt-get install nsolid -y?Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
? linux-image-6.8.0-35-generic linux-modules-6.8.0-35-generic linux-modules-extra-6.8.0-35-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
? nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.0 MB of archives.
After this operation, 199 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_20.x nodistro/main amd64 nodejs amd64 20.19.2-1nodesource1 [32.0 MB]
Fetched 32.0 MB in 5s (6893 kB/s)?
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package nodejs.
(Reading database ... 55243 files and directories currently installed.)
Preparing to unpack .../nodejs_20.19.2-1nodesource1_amd64.deb ...
Unpacking nodejs (20.19.2-1nodesource1) ...
Setting up nodejs (20.19.2-1nodesource1) ...
root@usw:~#?
root@usw:~#?
root@usw:~#?
root@usw:~# node --version # Should show v20.x.x
npm --version ?# Should show 10.x.x or higher
v20.19.2
10.8.2
root@usw:~#?
3 配置 npm
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
添加路徑:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
添加依賴包(可選)
sudo apt install -y git ripgrep
4 安裝 CC
npm install -g @anthropic-ai/claude-code
root@usw:~# mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
root@usw:~# echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
root@usw:~# sudo apt install -y git ripgrep
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
git is already the newest version (1:2.43.0-1ubuntu7.2).
The following packages were automatically installed and are no longer required:
? linux-image-6.8.0-35-generic linux-modules-6.8.0-35-generic linux-modules-extra-6.8.0-35-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
? ripgrep
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1551 kB of archives.
After this operation, 5335 kB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu noble/universe amd64 ripgrep amd64 14.1.0-1 [1551 kB]
Fetched 1551 kB in 0s (3722 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package ripgrep.
(Reading database ... 60606 files and directories currently installed.)
Preparing to unpack .../ripgrep_14.1.0-1_amd64.deb ...
Unpacking ripgrep (14.1.0-1) ...
Setting up ripgrep (14.1.0-1) ...
root@usw:~# npm install -g @anthropic-ai/claude-codeadded 3 packages in 12s
2 packages are looking for funding
? run `npm fund` for details
5 啟動 CC
創建項目文件夾
mkdir ~/projects
復制項目到文件夾
root@usw:~/projects# ll
total 12
drwxr-xr-x 3 root root 4096 Jun 23 08:22 ./
drwx------ 12 root root 4096 Jun 23 08:25 ../
drwxr-xr-x 6 root root 4096 Jun 23 08:23 48.removebg/
root@usw:~/projects#
進入項目的文件夾中,運行 claude
root@usw:~/projects# cd 48.removebg/
root@usw:~/projects/48.removebg# claude?
claude
第一次運行 CC
1 配置顯示風格
柔光用 1,我最后選的 3 為了看清楚些。
2 訂閱用戶登錄或使用 API 付費
打折時付了年度會員,用的 1,如下:
用瀏覽器打開上面的鏈接,會拿到驗證碼:
粘貼到屏幕提示區
成功后,如圖:
下一頁,安全須知
3 進入項目
總結:
在沒有 GUI 的環境里 Claude Code 是一個玩美的終端上使用 AI 的方案。如果你也是 Claude 訂閱用戶 ( Claude Pro ),你的 $20/月的 Claude Pro 訂閱本身就包含了在終端使用 Claude Code 的權限,并且會提供比免費用戶更多的使用量。?
如上圖中,Anthropic 也提供另一種方式:API 令牌使用費來使用 CC,這種按量付費模式獨立于你的 $20 訂閱,對于需要更高使用量、靈活或特定需求的用戶。
以上是在加州服務器運行,如果你的終端在國內,就要使用工具。
在國內安裝 CC
使用本地代理安裝 Claude Code
npm config set proxy http://127.0.0.1:1081
npm config set https-proxy http://127.0.0.1:1081
npm install -g @anthropic-ai/claude-code
注: socket port 1081 根據你自己的實際情況修改
最后把 npm anthropic 有關域加到路由,如: (以前有篇文章 用 DELETED tunel 組網)
{"type": "field","domain": ["registry.npmjs.org","*.npmjs.org","npmjs.com","*.npmjs.com","anthropic.com","*.anthropic.com","console.anthropic.com","api.anthropic.com","claude.ai","*.claude.ai"],"outboundTag": "usw_outbound"
}
修改后要重啟應用
下面是日志反映出主機路由的變化,BJN:
USW:
這樣在北京的主機上就可以使用 CC 來維護代碼