Claude Code shell classifier routing:v2.1.193 让每条命令进入 policy

Claude Code shell classifier routing 在 v2.1.193 增加 classifyAllShell 和 assistant-response OTEL,迫使 operator 同时审计命令策略与遥测隐私。

TheRouter Newsroom来源 Anthropic Claude Code
Claude Code shell classifier routing 策略面板,展示 shell policy lanes、denial reasons、OTEL logging 和 background agent controls

Claude Code shell classifier routing 在 v2.1.193 成为最值得 operator 关注的变化。这个版本加入了 autoMode.classifyAllShell,可以把每条 Bash 和 PowerShell 命令都送入 auto-mode classifier,而不只是已经命中 arbitrary-code-execution pattern 的命令。它还把 denial reason 写入 transcript 和 permission history,并新增可能包含模型回复文本的 claude_code.assistant_response OpenTelemetry event。对通过 AI gateway 运行 coding agent 的团队来说,Claude Code shell classifier routing 现在同时是 command-safety lane 和 telemetry-governance decision。

发生了什么

Anthropic 官方 Claude Code v2.1.193 release 是一次紧凑但重要的 control-plane 更新。Operator 最需要关注的是:

  • autoMode.classifyAllShell 可以把所有 Bash 和 PowerShell 命令送入 auto-mode classifier,而不仅是已匹配 arbitrary-code-execution pattern 的命令。
  • Auto-mode denial reason 现在会出现在 transcript、denial toast 和 /permissions recent denials 中。
  • claude_code.assistant_response 是新的 OpenTelemetry log event,包含模型回复文本。除非设置 OTEL_LOG_ASSISTANT_RESPONSES=1,否则会被 redacted;如果该变量未设置,它会跟随 OTEL_LOG_USER_PROMPTS,所以已经记录 prompt content 的部署升级后可能开始收到 response content,除非设置 OTEL_LOG_ASSISTANT_RESPONSES=0。
  • Bash mode 增加 live file path autocomplete,很实用,但也扩大了 operator 需要审视的 local-context surface。
  • 需要认证的 MCP server 会在启动时提示用户查看 /mcp。
  • Idle background shell command 可以在 memory pressure 下自动回收,除非设置 CLAUDE_CODE_DISABLE_BG_SHELL_PRESSURE_REAP=1。
  • Background-agent 行为被收紧:carry-over task 不会被误判为 abandoned,pinned agent 不会在 auto-update 后反复收到续写提示,main turn 也不会再生成 phantom resumed subagent。

因此,这次 release 不只是 UX 更新。它把 shell command classification、denial evidence、observability content、MCP auth visibility 和 background-agent lifecycle 拉到了同一个 operator policy surface。

为什么对 AI 工程团队重要

过去的 routing 问题常常是:“哪个模型来处理这个 coding task?”现在更好的问题是:“这条 command、这段 transcript 和这个 background process 应该走哪条 execution lane?”Claude Code shell classifier routing 让这个变化变得清晰。看似无害的 shell command 仍可能泄露 secret、修改 workspace,或制造 deployment drift。把每条 Bash 和 PowerShell 命令都送入 classifier,可以为 enterprise 提供更严格的默认值,但也让 review latency、denial quality 和 false-positive handling 更重要。

OpenTelemetry 变化同样关键。Observability 能帮助团队调试 agent 行为,但 response text 可能包含生成的 secret、客户数据、repository context,或复制过来的 prompt material。如果某个部署已经开启 prompt logging,v2.1.193 可能让 response logging 跟随该设置,除非团队显式关闭。这是 routing policy 问题:敏感项目可能需要 no-response-log lane,而内部 sandbox 项目可以允许更丰富的 trace 用于 debugging。

对 TheRouter 用户来说,这个模式符合 TheRouter docs 中的 gateway 实践:agent workload 应携带 command risk、credential exposure、telemetry scope 和 session lifecycle 的 policy metadata。Claude Code shell classifier routing 不是单个 toggle,而是 execution safety 与 observability privacy 交汇的地方。

路由与运维视角

先把 coding-agent session 分成三条 lane。

  1. Strict command lane:对包含 production credentials、deployment scripts、regulated data 或 destructive infrastructure commands 的 repo 启用 autoMode.classifyAllShell。把 denial reason 当成 audit evidence,而不只是 UI feedback。
  2. Standard developer lane:保留常规 command classification,但对 denied command、重复 approval prompt 和 high-risk directory 做 sampling 与 review。
  3. Sandbox experimentation lane:只在 disposable workspace 中允许更宽松的 command execution,并配合 short-lived credentials、limited egress,以及默认禁用 response logging。

然后把 telemetry 绑定到这些 lane。不要让 OTEL_LOG_ASSISTANT_RESPONSES 意外继承行为。在每个 managed environment 中显式设置它。对多数 production coding-agent fleet 来说,OTEL_LOG_ASSISTANT_RESPONSES=0 是更安全的默认值;团队仍可以保留 metrics、spans 和 redacted denial events,而不保存完整模型回复。

最后,把 background agent 当成 long-lived process 路由。Automatic memory-pressure reaping 很有用,但 operator 仍需要 session ID、owner ID、workspace path、active commands 和 last-output timestamp。能跨 update boundary 存活的 background agent,也应该被审查 shell command 的同一个 policy engine 看见。

TheRouter 用户应关注或尝试什么

把 v2.1.193 升级当作 policy migration,而不是普通 CLI bump。在全面启用 Claude Code shell classifier routing 之前,先在一个包含 scripts、package managers、MCP tools 和 background agents 的代表性 repo 上分阶段测试。

使用这份 checklist:

  • 决定哪些 workspace 必须启用 autoMode.classifyAllShell,并记录 exception path。
  • 确认 denial reason 会进入 transcript,并以 security reviewer 可检索的形式导出。
  • 显式设置 OTEL_LOG_ASSISTANT_RESPONSES;不要依赖 prompt-logging 的继承行为。
  • 测试会读取文件、修改 git state、安装 package 和调用 deployment tool 的 Bash / PowerShell 命令。
  • 验证 MCP auth startup notice 给出可恢复路径,而不是让 tool 静默消失。
  • 在 memory pressure 下观察 background shell reaping,并确认没有 active deployment 或 migration task 在缺少 operator evidence 的情况下被杀掉。
  • 对照之前的 Claude Code MCP reliability routing 分析,因为 v2.1.193 延续了同一个 control-plane 主题。

实际结论是:Claude Code shell classifier routing 把 shell execution 变成一等 gateway decision。最好的设置不是最宽松的设置,而是能证明每条 command、每次 denial、每段 response log、每个 MCP auth prompt 和每个 background agent 都在触碰 production-like code 前走了正确 lane 的设置。

帮助与联系