Context

Discord 對話:使用者想把本機的 Claude Code 環境完整搬到一台乾淨的 Ubuntu VPS,保留所有設定、MCP server、skills、memory。

Key Insights

  • ~/.claude/ 就是整個 Claude Code 的「設定大腦」,rsync 過去就能複製 90% 的環境,包含 settings.json、CLAUDE.md、MCP 設定、skills、memory
  • 最大坑:硬編碼路徑。 settings.json 裡的 hooks、statusLine、MCP server command 路徑通常是絕對路徑(如 /Users/lookoutking/...),rsync 後 VPS 的 username 和目錄結構不同就全部失效。rsync 完必須手動修正路徑。特別注意 hooksstatusLine.command 都有各自的硬編碼路徑。
  • 認證(OAuth)不能複製,要在 VPS 執行 claude 讓它產生授權 URL,在本機瀏覽器完成授權
  • MCP server 的本地依賴(node_modules、Python venv)不在 ~/.claude/,需要在 VPS 重新安裝
  • Discord MCP tool 的參數名踩坑:replytext 不是 contentfetch_messageschannel 不是 chat_id,傳錯不報警告,直接變 undefined 在 runtime 炸掉

本機環境依賴清單(VPS 需手動安裝)

工具用途VPS 安裝方式
Claude Code主程式curl -fsSL https://claude.ai/install.sh | bash
bunDiscord plugin 執行(server.ts)curl -fsSL https://bun.sh/install | bash
uvPython 套件管理(MCP server 依賴)curl -LsSf https://astral.sh/uv/install.sh | sh
nodeMCP server、pluginscurl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && sudo apt-get install -y nodejs
ghGitHub CLI(settings.json 中有 allow 規則)sudo apt install gh 或官方 deb
jqJSON 處理sudo apt install jq
git版本控制通常已預裝,sudo apt install git

步驟速查

# 0. VPS 安裝依賴工具
curl -fsSL https://claude.ai/install.sh | bash
curl -fsSL https://bun.sh/install | bash
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
# node、gh、jq 用 apt 裝(需 sudo)
 
# 1. 複製設定(從本機執行)
rsync -avz ~/.claude/ user@vps:~/.claude/
 
# 2. 修正硬編碼路徑(在 VPS 上執行)
# 確認帳號名稱
whoami
 
# 替換所有本機路徑(把 lookoutking 換成你的 VPS 帳號)
sed -i 's|/Users/lookoutking|/home/your_vps_user|g' ~/.claude/settings.json
 
# 驗證沒有殘留
grep -r "lookoutking" ~/.claude/settings.json
# 無輸出 = 乾淨
 
# 3. 複製專案(從本機執行)
rsync -avz ~/dev/bot_vault/ user@vps:~/dev/bot_vault/
 
# 4. VPS 上重新安裝 MCP server 依賴
# 例如 Discord plugin:進入 server 目錄執行 bun install
 
# 5. VPS 上認證
claude  # 產生 URL,本機瀏覽器授權

Connections