为纪念 35 周年:《Terminator 2: Judgment Day》将在全球影院重映
2026-07-13
2026-07-14 0
上一篇我们看了 Claude Code 在"推理自主性"这条轴上的进化。这篇看另一条轴:从单线程终端工具到多端协同的自动化平台。

Claude Code 最初只是"你在终端里打字,它回答"。现在呢?它能后台跑任务、事件驱动响应、定时调度、手机远程操控、浏览器里直接开 session、多个实例组队协作。这些特性组合起来,构成了一个完整的"Agent 自动化生态"。
Background Tasks 让长时间运行的操作异步执行——跑测试、构建 Docker、部署——你可以继续和 Claude 聊别的。
User: Run the full test suite in the backgroundClaude: Starting tests in background (task-id: bg-1234)You can continue working while tests run.[你继续和 Claude 聊别的]Claude: Background task bg-1234 completed:245 tests passed3 tests failed
/task list # 列出所有任务/task status bg-1234 # 查看进度/task show bg-1234 # 查看输出/task cancel bg-1234 # 取消任务
{"backgroundTasks": {"enabled": true,"maxConcurrentTasks": 5,"notifyOnCompletion": true,"autoCleanup": true,"logOutput": true}}
User: Run the build in the background → bg-5001User: Also run the linter in background → bg-5002User: While those run, let's implement the new API endpoint[Claude 一边实现 API,后台在跑 build 和 lint]Claude: Build completed successfully (bg-5001)Claude: Linter found 12 issues (bg-5002)
这就是 Claude Code 的"多线程"体验——一个对话窗口,多个并行任务。
Monitor(v2.1.98)解决的是一个 token 经济学问题:以前用 /loop 或 sleep 轮询,每次循环都烧一个完整的 API round-trip,不管有没有变化。Monitor 在命令静默时消耗 零 token,有事件时立即唤醒。
Stream filter —— 监听持续输出的流:
tail -f /var/log/app.log | grep --line-buffered "ERROR"
Poll-and-emit filter —— 周期性检查,有变化时才输出:
last=$(date -u +%Y-%m-%dT%H:%M:%SZ)while true; dogh api "repos/owner/repo/issues/123/comments?since=$last" || truelast=$(date -u +%Y-%m-%dT%H:%M:%SZ)sleep 30done
"Start my dev server and monitor it for errors."
Claude 启动服务器作为后台任务,挂上 Monitor filter(tail -F server.log | grep --line-buffered -E "ERROR|FATAL"),然后 session 进入静默。日志出现错误的瞬间,Claude 被唤醒——自动重启服务器、修 bug、或通知你。
1. /loop —— 间隔执行:
/loop 5m check if the deployment finished/loop check build status every 30 minutes
2. 一次性提醒:
remind me at 3pm to push the release branchin 45 minutes, run the integration tests
3. /schedule —— 云端持久调度:
/schedule daily at 9am run the test suite and report failures
| 维度 | /loop (CronCreate) | /schedule (Cloud) |
|---|---|---|
| 持久性 | Session-scoped,重启后消失 | 云端持久,不需要本地运行 |
| 限制 | 最多 50 个/session,3 天自动过期 | 持久 |
| 要求 | 无 | Pro/Max OAuth(API key 用户不可用) |
| 漏跑 | 不补跑 | 云端保证执行 |
| 维度 | 说明 |
|---|---|
| 循环抖动 | 最多 10% 间隔(最大 15 分钟) |
| 一次性抖动 | :00/:30 边界上最多 90 秒 |
| 漏跑处理 | 不补跑——Claude Code 没运行就跳过 |
| 上限 | 50 个/session |
/loop 5m check the deployment status of the staging environment.If the deploy succeeded, notify me and stop looping.If it failed, show the error logs.
claude -p(Print Mode)是非交互模式——输入一段 prompt,Claude 执行完输出结果,不需要人工交互。这是把 Claude Code 嵌入 CI/CD 的关键。
# 基本用法claude -p "Run all tests and generate coverage report"# 结构化输出claude -p --output-format json "Analyze code quality"# 限制自主轮数claude -p --max-turns 5 "refactor this module"# Schema 验证claude -p --json-schema '{"type":"object","properties":{"issues":{"type":"array"}}}' "find bugs in this code"
# .github/workflows/code-review.ymlname: AI Code Reviewon: [pull_request]jobs:review:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Install Claude Coderun: npm install -g @anthropic-ai/claude-code- name: Run Claude Code Reviewenv:ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}run: |claude -p --output-format json --max-turns 3 "Review this PR for:- Code quality issues- Security vulnerabilities- Performance concerns- Test coverageOutput results as JSON" > review.json- name: Post Review Commentuses: actions/github-script@v7with:script: |const fs = require('fs');const review = JSON.parse(fs.readFileSync('review.json', 'utf8'));github.rest.issues.createComment({issue_number: context.issue.number,owner: context.repo.owner,repo: context.repo.repo,body: JSON.stringify(review, null, 2)});
claude --safe-mode# 或CLAUDE_CODE_SAFE_MODE=1 claude
Remote Control(v2.1.51+)让你从手机、平板或任何浏览器继续控制本地运行的 Claude Code session。本地在跑,远程在看——不是把代码搬到云上。
# 启动claude remote-controlclaude remote-control --name "Auth Refactor"# 或在 session 内/remote-control
| 方式 | 说明 |
|---|---|
| Session URL | 启动时打印,浏览器打开即可 |
| QR Code | 按空格键显示可扫描的二维码 |
| 按名查找 | 在 claude.ai/code 或 Claude 手机 app 里找到 |
- 不在本机开任何入站端口- 仅出站 HTTPS over TLS- 多个短期、窄范围 token- Session 隔离
| 维度 | Remote Control | Claude Code on Web |
|---|---|---|
| 执行位置 | 你的机器 | Anthropic 云端 |
| 本地工具 | 完整访问 MCP、文件、CLI | 无本地依赖 |
| 场景 | 从手机继续本地工作 | 从任何浏览器开始全新工作 |
Remote Control 激活时,在 /config 里启用"Push when Claude decides",Claude 会在长任务完成或需要你输入时发手机推送。
{"disableRemoteControl": true}
# 从 CLI 创建云端 sessionclaude --remote "implement the new API endpoints"# 从云端拉回本地claude --teleport# 或在 session 内/teleport
Web Sessions 跑在 Anthropic 云端——关掉浏览器 session 还在跑。和 Remote Control 的区别:Remote Control 是"本地跑,远程看",Web Sessions 是"云端跑,随时看"。
Desktop App(macOS + Windows)提供了比终端更丰富的界面:
| Feature | 说明 |
|---|---|
| Diff view | 文件级 visual review + inline comments,Claude 读评论后修改 |
| App preview | 自动启动 dev server + 内嵌浏览器实时验证 |
| PR monitoring | GitHub CLI 集成,CI 失败自动修复,checks 全过自动 merge |
| Parallel sessions | 侧边栏多 session + 自动 Git worktree 隔离 |
| Scheduled tasks | 循环任务(每小时/每天/工作日/每周),app 打开时执行 |
| Connectors | GitHub / Slack / Linear / Notion / Asana / Calendar |
// .claude/launch.json{"command": "npm run dev","port": 3000,"readyPattern": "ready on","persistCookies": true}
从 CLI session 一键交接到 Desktop App:
/desktop
Channels(Research Preview)让外部服务通过 MCP servers 把事件推送到运行中的 Claude Code session——不需要轮询。
claude --channels discord,telegram,imessage,webhooks
| 集成 | 能力 |
|---|---|
| Discord | 接收/回复 Discord 消息 |
| Telegram | 接收/回复 Telegram 消息 |
| iMessage | 接收 iMessage 通知 |
| Webhooks | 接收任意 webhook 事件 |
1. MCP servers 作为 channel plugins 连接外部服务2. 消息/事件被推送到活跃的 Claude Code session3. Claude 在 session context 中读取并回复4. 不需要轮询——实时推送
{"allowedChannelPlugins": ["discord", "telegram"]}
Chrome Integration(beta,v2.0.73+)连接 Claude Code 到你的 Chrome 或 Edge 浏览器,实现 live web automation 和调试。
claude --chrome# 启用claude --no-chrome # 禁用/chrome# session 内切换
| 能力 | 说明 |
|---|---|
| Live debugging | 实时读 console logs、检查 DOM、调试 JavaScript |
| Design verification | 对比渲染页面和设计稿 |
| Form validation | 测试表单提交、输入验证、错误处理 |
| Web app testing | 操作有登录态的 app(Gmail、Notion 等) |
| Data extraction | 抓取网页内容 |
| Session recording | 录制浏览器操作为 GIF |
Chrome extension 管理逐站权限——你授权哪个网站,Claude 才能操作哪个。遇到登录页或 CAPTCHA,Claude 暂停等你手动处理。
claude --worktree # 或 claude -w
启动后 Claude 在 创建隔离 worktree,不影响主 working directory。
baseRef(v2.1.133)——worktree 从哪个 commit 分支:
{"worktree": {"baseRef": "fresh" // 默认:从 origin/
bgIsolation(v2.1.143)——后台 session 是否隔离:
{"worktree": {"bgIsolation": "none" // 后台 session 直接编辑当前 working copy// 默认是创建独立 worktree}}
Sparse Checkout for Monorepos:
{"worktree": {"sparsePaths": ["packages/my-package", "shared/"]}}
| 工具/事件 | 说明 |
|---|---|
EnterWorktree | 进入 worktree(v2.1.157 可中途切换) |
ExitWorktree | 退出并清理 |
WorktreeCreate hook | worktree 创建时触发 |
WorktreeRemove hook | worktree 移除时触发 |
| 无变更自动清理 | session 结束时,没有改动的 worktree 自动删除 |
Sandboxing 在 OS 层面限制 Claude 执行的 Bash 命令——文件系统访问和网络连接都被隔离。
claude --sandbox # 启用claude --no-sandbox# 禁用/sandbox # session 内切换
{"sandbox": {"enabled": true,"failIfUnavailable": true,"filesystem": {"allowWrite": ["/Users/me/project"],"allowRead": ["/Users/me/project", "/usr/local/lib"],"denyRead": ["/Users/me/.ssh", "/Users/me/.aws"]},"network": {"allowedDomains": ["*.example.com"],"deniedDomains": ["evil.example.com"]},"enableWeakerNetworkIsolation": true}}
{"sandbox": {"network": {"allowedDomains": ["*.example.com"],"deniedDomains": ["evil.example.com"]}}}
{"sandbox": {"bwrapPath": "/opt/bubblewrap/bin/bwrap","socatPath": "/opt/socat/bin/socat"}}
Agent Teams 让多个 Claude Code 实例协作完成一个任务——一个 team lead 协调,多个 teammates 独立工作。
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
Team Lead(协调者)├── Teammate A(独立 context window)├── Teammate B(独立 context window)└── Teammate C(独立 context window)共享:Task List(自协调)角色定义:.claude/agents/ 目录或 --agents 标志
claude --teammate-mode in-process# 默认:同一终端进程内claude --teammate-mode tmux# 每个 teammate 一个 tmux split paneclaude --teammate-mode auto# 自动选择
| 维度 | Dynamic Workflows | Agent Teams |
|---|---|---|
| 编排方式 | 确定性脚本(Claude 编写并执行) | Team Lead 动态协调 |
| 通信机制 | 输入/输出传递 | 共享 Task List |
| 数量级 | 几十到几百 subagent | 少量 teammates(通常 2-5) |
| 状态 | 正式特性(v2.1.154) | 实验性 |
| 适用 | 大规模并行覆盖(审计/迁移) | 角色分工协作 |
把所有特性放到一张地图上:
┌─────────────────────────────────────────┐│Claude Code 自动化生态│└─────────────────────────────────────────┘│┌───────────────────────────┼───────────────────────────┐│ │ │┌─────▼─────┐┌───────▼───────┐ ┌──────▼──────┐│后台异步││ 多端接入 │ │定时调度│└─────┬─────┘└───────┬───────┘ └──────┬──────┘│││Background TasksRemote Control/loop (session)Monitor ToolWeb Sessions/schedule (cloud)Dynamic Workflows Desktop App RoutinesChrome IntegrationChannels (push)│┌─────────▼─────────┐│ 协作与隔离 │└─────────┬─────────┘│Agent Teams (多实例)Git Worktrees (隔离)Sandboxing (安全)
| 我想... | 用什么 |
|---|---|
| 跑测试同时写代码 | Background Tasks |
| 监控日志,有错误自动响应 | Monitor Tool |
| 每天定时跑一个任务 | /schedule (云端) |
| 手机上看 Claude 进度 | Remote Control |
| 不在本地跑,纯云端 | Web Sessions / Desktop Remote |
| Claude 响应 Discord 消息 | Channels |
| 自动化 CI/CD code review | Headless Mode (claude -p) |
| 多人分工大重构 | Agent Teams |
| 并行几十个审计任务 | Dynamic Workflows (ultracode) |
| 操作浏览器里的 web app | Chrome Integration |
| 安全隔离不信任的操作 | Sandboxing + Worktrees |
| 版本 | 变更 |
|---|---|
| v2.0.73 | Chrome Integration beta |
| v2.1.51 | Remote Control 上线 |
| v2.1.72 | Scheduled Tasks 上线 |
| v2.1.98 | Monitor Tool 上线 |
| v2.1.110 | TUI Mode + Push Notifications + Desktop App |
| v2.1.113 | Sandbox deniedDomains |
| v2.1.128 | Channels 支持 API-key auth |
| v2.1.133 | worktree.baseRef + bwrapPath/socatPath |
| v2.1.139 | /schedule 对 API-key 用户静默禁用 |
| v2.1.143 | worktree.bgIsolation + PowerShell default on Windows |
| v2.1.154 | Dynamic Workflows + ultracode |
| v2.1.157 | EnterWorktree 可中途切换 |
Claude Code 的自动化能力在 2026 上半年经历了爆发式扩展:
后台异步层面:Background Tasks 让你不被阻塞,Monitor Tool 让事件驱动替代轮询(省 token、响应快),Dynamic Workflows 让多 Agent 确定性协作。
多端接入层面:Remote Control 让手机操控本地 Agent,Web Sessions 让云端全天候运行,Desktop App 提供比终端更丰富的 review 界面,Chrome Integration 打通浏览器自动化,Channels 让外部消息实时推送进 session。
调度与隔离层面:/loop 做 session 级调度,/schedule 做云端持久调度,Git Worktrees 提供隔离的并行工作空间,Sandboxing 在 OS 层面提供安全边界,Agent Teams 让多个实例角色分工。
核心判断:这些特性单独看都不复杂,组合使用时才展现真正的威力。一个完整的自动化工作流可能是这样的:
Auto Mode + Background Tasks + Monitor + Remote Control + /schedule= 你设定好规则,Claude 自主运行,有事推送你手机,每天定时汇报
这已经不是"终端聊天工具"了——这是一个 Agent 操作系统的雏形。
本文素材来源:luongnv89/claude-howto/09-advanced-features