Claude Blog Anthropic ★ 83 6 min

Claude Code in the cloud: a field guide to cloud sessions

Best practices

🔗 https://claude.dev/blog/claude-code-in-the-cloud/

📌 Claude Code上雲端:三個任務同時跑,各自一臺機器不互撞

TL;DR:雲端session讓每個Claude Code任務跑在獨立VM上,平行作業不再搶檔案、搶port。

你在自己的筆電上同時開兩個Claude Code工作階段,大概會遇到兩個麻煩:它們共用同一份working tree,可能改到同一個檔案、搶同一個port;而且只要筆電睡著或Wi-Fi斷線,工作就停了。Anthropic這篇指南示範的雲端session,把這兩個麻煩直接解決掉。

🤔 本機session的三個先天限制

本機執行的Claude Code session有三個特性:共用你的working tree(兩個session同時跑同一個repository會互相干擾檔案與port)、使用你本人的credentials、電腦睡眠或斷網就會停止。

🧩 雲端session怎麼運作

雲端session讓Claude Code跑在屬於自己的機器上。每個任務都會拿到一臺全新的虛擬機器,repository會被clone到一個新分支上,而且環境設定已經事先裝好。你可以從claude.ai/code、Claude手機App、桌面App、終端機,或是Slack啟動一個雲端session,再透過瀏覽器、手機、桌面App追蹤進度。工作完成後,成果會停在一個分支上,你可以直接把它變成pull request。

雲端session內含在Pro、Max、Team、Enterprise方案裡,不額外收費,用量算在Claude Code原有的額度裡(依方案不同,組織擁有者可能需要先手動開啟)。文中也提到現有Pro、Max個人訂閱戶可以在10月7日前申請一次性雲端session獎勵額度,Pro方案100美元、Max方案250美元,額度將在11月4日到期,用完或過期後回歸一般方案用量,且不適用於Projects或Routines。

📊 實測:三個任務、三臺機器、同一份repository

作者用一個名叫tidepool(預測三個虛構港口潮汐的小型Node API)的範例repository,在16秒內依序啟動三個雲端session,各自處理一個問題:

  1. npm test大約四次會跑出一次失敗——找出根因並修好,再連續跑30次以上驗證
  2. docs/API.md跟src/server.js的內容對不上——重寫文件讓每個endpoint、參數、預設值、回應格式都對齊程式碼,並實際啟動伺服器用curl逐一驗證
  3. 讓src/logger.js輸出每行一個JSON物件,保留LOG_LEVEL,並記錄method、path、status、duration_ms等欄位,同時補上測試

三個session分別跑了61秒、65秒、72秒,全部在第一個啟動後87秒內完成(其中重建repository的setup步驟就佔了每個任務三分之一到一半以上的時間,正式使用GitHub clone時可以省略)。結果:第一個session在TtlCache.get裡找到一個競態條件(cache在loader執行完才存值,導致同一個key在載入中被再次呼叫會重複觸發loader),改成先存進行中的promise、載入失敗就移除該項,並連續跑了40次npm test零失敗。第二個session啟動伺服器、對每個endpoint跑curl,找出文件裡五個錯誤(列出API實際不會回傳的欄位、文件了一個程式碼根本沒讀的days參數、把公尺寫成英尺、漏掉/next-highendpoint、沒寫錯誤回應),還發現一個不在任務範圍內的bug(from=格式錯誤時回傳200加空列表)但選擇只記錄成caveat,沒有擅自修改程式碼。第三個session寫好JSON logger、把request log改成結構化欄位、加了五個測試,但提交時發現有一個測試失敗,重跑八次裡失敗五次,追查後發現正是第一個session在修的同一個競態條件——它提出了相同的修法,但因為超出自己任務範圍而沒有動手修改cache,並在摘要裡誠實註明測試套件並不乾淨。

💡 隔離性既是優點,也要留意銜接

logger session完全不知道cache修復正在進行中,正好說明了雲端session的隔離特性:每個session有自己的repository副本、自己的程序、自己的分支,文件session和logger session都各自啟動了API伺服器來測試,彼此互不影響。但這也意味著拆分平行任務時,最好沿著檔案邊界切分,依合理順序合併分支,並預期某個session回報的問題,可能正是另一個session正在處理的。

🧩 雲端session底層架構的四個關鍵

每個任務都拿到專屬機器:全新VM搭配clone到新分支的repository,session之間碰不到彼此的檔案或port。你的GitHub token不會進入VM:由一個proxy代持,session拿到的是只能推送到自己working分支的短期憑證。repository的Claude設定會跟著走:CLAUDE.md、rules、skills、agents、commands都會隨repo帶上,但你個人的設定不會跟著走。閒置的VM會被回收:重新打開session會拿到全新VM並還原對話紀錄,所以在意的工作要記得commit。

🎯 實務啟示

雲端session不是要取代本機session,而是兩者互補。需要同時跑多個獨立任務、任務會長時間執行、或是不想讓本機熄屏中斷工作時,雲端session是更合適的選擇;而需要即時互動、或任務需要存取本機SSH金鑰、雲端CLI等本機才有的資源時,本機session仍是必要的。拆分平行任務時建議沿檔案邊界切,並對分支合併順序與session之間的資訊落差有心理準備。

🔗 來源

#ClaudeCode #Anthropic #CloudComputing #DeveloperTools #CICD #AIAgents #SoftwareEngineering #ParallelComputing #GitHubIntegration #DevOps

原始資料 Claude Blog · 收集於 2026-10-07
來源原標題
Claude Code in the cloud: a field guide to cloud sessions
機構
Anthropic
原始標籤
Best practices
原始連結
https://claude.dev/blog/claude-code-in-the-cloud/

摘要原文

You probably run Claude Code in a terminal on your own laptop. That session depends on the laptop in three ways: It shares your working tree, so two sessions on one repository can edit the same files and fight over the same port. It runs with your credentials. It stops when your computer sleeps or the Wi-Fi drops. A cloud session runs Claude Code on a machine of its own. Each task gets a fresh virtual machine with your repository cloned onto a new branch and your environment's setup already done. You can start one from claude.ai/code , the Claude mobile app , the Desktop app , your terminal , and Slack . You can then follow it from the browser, the mobile app, and Desktop. When the work is done, it sits on a branch you can turn into a pull request. Cloud sessions come with your Pro, Max, Team, or Enterprise plan at no additional cost: there's no separate charge for the cloud machine, and sessions draw on the same usage limits as the rest of Claude Code. Depending on your plan, an organization owner may need to turn on cloud sessions first. Bonus credit for cloud sessions. Existing individual Pro and Max subscribers can claim a one-time bonus credit for cloud sessions, on top of their plan limits: $100 on Pro and $250 on Max. Claim it by October 7 at claude.ai/code/claim-credit or with /claim-credit in Claude Code. The credit expires on November 4. After it's used or expires, your plan's regular usage applies. It isn't eligible for Projects or Routines. See the Promotional Credit Offer Terms . For this guide I ran four real cloud sessions against a small sample repository. Their transcripts, diffs, and timings appear throughout. The repository and the user in the screenshots are made up. The work, the output, and the numbers come from those sessions. One of the main advantages of cloud sessions is that you can run several tasks at once without them getting in each other's way. Here are three I started within 16 seconds of each other, each on its own machine. On my laptop, I'd have run these one after another, or spent my time keeping them out of each other's way. Play video FIG A Pause The real timeline of three cloud sessions on one repository, in seconds from the first start. Hatched bars are the setup step that recreated the sample repository (a GitHub clone replaces it in normal use), and each dot is one tool call. THREE TASKS, ONE REPOSITORY, THREE MACHINES The sample repository is tidepool , a small Node API that predicts tides for three fictional harbors. It had three ordinary problems: one test failed about one run in four, the API docs described parameters the code no longer read, and the logger built its lines by concatenating strings. I started three cloud sessions within 16 seconds of each other, one per problem. I started them programmatically, and because tidepool isn't on GitHub, each session first recreated the repository from files in its prompt. With a real repository you'd skip that step, and from a terminal each session is one claude --cloud command. Shortened, the three prompts were: CODE Shell Copy claude --cloud "npm test fails maybe one run in four. Find the flaky test, fix the root cause in the code (not the test), and prove it by running the suite at least 30 times in a row." claude --cloud "docs/API.md is out of date with src/server.js. Rewrite it so every endpoint, parameter, default and response shape matches the code. Start the server and run each curl example to check it." claude --cloud "Make src/logger.js emit one JSON object per line, keep LOG_LEVEL, and log method, path, status and duration_ms as fields. Add a test for the logger." The sessions ran for 61, 65 and 72 seconds, and all three were done 87 seconds after the first one started. Recreating the repository took roughly a third to just over half of each run. Here are the results. The flaky test. Claude found a race in TtlCache.get . The cache stored a value only after the loader finished, so a second get for the same key during a load called the loader again. Claude changed the cache to store the in-flight promise, dropped the entry when a load fails, and ran npm test 40 times in a row with zero failures. The docs. Claude started the server, ran a curl against every endpoint, and found five ways the old doc was wrong. It listed fields the API never returns, documented a days parameter the code ignores, gave heights in feet when they are metres, skipped the /next-high endpoint, and left out the error responses. It also found that a malformed from= value returns an empty list with a 200, and documented that as a caveat instead of changing server code it wasn't asked to touch. The logger. Claude wrote the JSON logger, moved the request log to structured fields, and added five tests. Its commit went in with one failing test, so Claude reran the cache test eight times, saw it fail in five of them, and traced the failure to the same race the first session was fixing. It proposed the same fix, left the cache alone because that was outside its task, and said in its summary that the suite wasn't clean. FIG B The three sessions in the claude.ai/code interface, running locally and replaying their real transcripts. Setup steps are trimmed, paths show under /home/user, the bottom three sidebar titles are filler, and the mode chip shows the default. FIG C The Fix the flaky test session FIG D The Update the tidepool API docs session FIG E A 20-second recording of the same local build: clicking between the three sessions, then scrolling the logger session's transcript The logger result shows why cloud sessions suit parallel work. Each session had its own copy of the repository, its own processes and its own branch. The docs session and the logger session each started the API server to test against it, and neither affected the other. On a single laptop, two agents working in one checkout would edit the same files, and would collide on a port unless each picked its own. Because of that isolation, the logger session had no access to the cache fix the first session was making. Split parallel tasks along file boundaries, merge the branches in a sensible order, and expect a session to report problems that another session is already fixing. UNDER THE HOOD OF A CLAUDE CODE CLOUD SESSION A cloud session is a Claude Code session running on Anthropic-managed infrastructure, or on your organization's own machines with a self-hosted environment . The figure shows the parts. The four takeaways after it are the ones that change how you work. FIG F Anatomy of a cloud session. Everything the agent can touch sits inside the VM. Your GitHub token and the network policy sit outside it. Every task gets its own machine. A fresh VM with your repository cloned onto a new branch, so sessions can't touch each other's files or ports. See what's installed . Your GitHub token never enters the VM. A proxy holds it, and the session gets a short-lived credential that can push only to its own working branch. See the GitHub proxy . The repository's Claude config comes along. Your personal one doesn't. CLAUDE.md , rules, skills, agents, and commands travel with the repo, and your ~/.claude stays on your laptop. See settings in cloud sessions . Idle VMs get reclaimed. Reopen the session and you get a fresh VM with the conversation restored, so commit work you care about. See environment expiry . For specs, permission modes , and network levels, see the cloud environments docs . LOCAL OR CLOUD? Cloud sessions don't replace local ones, and most people use both. The table shows where they differ, and the paragraphs after it say when each one fits. Local session Cloud session Runs on Your machine A fresh VM for each task Laptop asleep or offline The session stops The session keeps going Several tasks on one repo Separate worktrees, ports and care One VM and one branch per task What the agent can reach Anything your user account can, including SSH keys, cloud CLIs and ~/.

由 claude-code/sonnet 自動生成