Claude Code v2.1.332:支持MCP技能与PreSkillShellCommand钩子
v2.1.332
推荐理由
本次更新引入了 MCP 技能支持与关键的 PreSkillShellCommand 钩子,改变了 Agent 对 Shell 命令的控制能力,建议开发者关注并测试新钩子的集成。
What's changed
变更内容
- Added skills from MCP servers (beta). They show as server:skill in the / menu; other skills keep their names
- Added a PreSkillShellCommand hook event that can refuse a skill or command's inline shell commands as it loads; on 2.1.331 and older, a settings file naming it opens a dialog at start
- Added "Always deliver" to the prompt for held messages from other sessions
- Added a footer line that stays while a flagged message has your session on a different model, until you pick one with /model
- Added an OpenTelemetry assistant_response event for text Claude sends through SendUserMessage or Cowork's message tool, when response logging is on
- Added a warning in VS Code and Desktop's Code tab when part of a session couldn't be saved, saying how to save it with /compact
- Added a notice in VS Code and Desktop's Code tab when a resumed session's earlier messages weren't loaded, as the terminal already shows
- Added your Cyber Verification Program access tier to the startup header, beside the model name when your tier applies to that model and you're signed in with a claude.ai account
- Fixed claude auth login reporting Login successful. when a claude.ai login could not be saved: it now exits 1 and says what to check, such as a leftover lock file or a full disk
- Fixed Read, @-mentions and compaction hanging on a named pipe that nothing writes to, such as a .env mounted by a locked secrets manager; the read now fails after 20 seconds
- Fixed turns ending in "Prompt is too long" after repeated auto-compaction failures when one more compaction at the context limit could have kept them going
- Fixed compaction failing when a summary kept running past the output limit: after three cut-off replies, the last try now asks for a shorter summary
- Fixed a freeze when a permission rule or hook condition with several wildcards was checked against a long command
- Fixed freezes and runaway memory use in most cases while a hook prints output without end
- Fixed a freeze and context overflow when a hook blocks or fails during a turn, or after /compact, with a very large log; text over about 50,000 characters is now shortened
- Fixed the terminal freezing, and ignoring Ctrl+C, while a local MCP server floods its standard output
- Fixed a freeze when a prompt or piped input holds an @ followed by a very long unbroken string, such as minified CSS with an embedded font
- Fixed a long freeze when opening a rewind point after a large tracked file was rewritten
- Fixed SSE MCP servers hanging or refusing every tool call after their event stream was cut and came back on a new endpoint or not at all, until reconnected by hand
- Fixed Remote Control showing a session in the desktop app, VS Code or the Agent SDK as running while it waited there on a dialog or an MCP server's question
- Fixed a usage limit being reported as reached to Remote Control, IDE and SDK clients after it had already reset
- Fixed CLAUDE.md and rules files being sent to the model a second time, in most cases, after a session moves into a worktree under .claude/worktrees with EnterWorktree or is resumed there
- Fixed tool calls that never ran being counted as done in a claude.ai chat's summary line after you declined a permission prompt in a session that had restarted
- Linux: Fixed the Bash edit diff showing an unchanged symlink as edited after Claude had read the file through it
- Fixed resuming a session and /stats freezing for seconds when a transcript holds many damaged lines
- Fixed a family name such as sonnet in --fallback-model being dropped when availableModels allows only an older version of it
- Fixed keys lagging for seconds while /stats reads large session transcripts, also after the dialog is closed, and with debug logging on while a language server floods its stderr
- Fixed a session failing when the cloud refused its default model and an availableModels list that isn't enforced named neither it nor an older model of that family
- Fixed an enforced list of older models failing on Google Cloud's Agent Platform and Foundry when the first is refused: it now steps down to the next in that family, if listed newest first
- Fixed opus failing on Bedrock, Google Cloud's Agent Platform and Foundry behind a gateway that refuses a model in its own words: it now steps down to an older model that answers
- Fixed the start-up model upgrade offer on Bedrock and Google Cloud's Agent Platform naming a model that your availableModels list leaves out
- Fixed Bedrock sub-agents failing when your account lists no profile for their model in the parent's region: they now use the model's own profile, which can be outside that region
- Fixed Foundry sessions leaving a model family when an admin's list blocks the version sonnet, opus or haiku points to: they now use its newest allowed version under a built-in or mapped name
- Fixed the sonnet alias on Bedrock Mantle resolving to Haiku 4.5: it now means Sonnet 5, not Sonnet 5.5, and an account without Sonnet 5 gets an error, so enable it first
- Fixed Ctrl+C at the prompt starting a new turn, and a double Ctrl+C not exiting, when a background agent it stopped had an unread subagent report
- Fixed /install-github-app ticking a workflow again after going back with Esc
- Fixed dictated text past 10,000 characters being lost
- Fixed raw "JSON Parse error" and "The operation was aborted." API errors when the non-streaming retry got a broken response or was interrupted
- Fixed Esc not stopping computer use between actions on macOS when Claude Code's window or an app you allowed is in front; an Esc meant for that app's popup now stops computer use instead
- Fixed a rare hang when a helper command, such as an API key helper, ran past its time limit
- Fixed selecting text in fullscreen pushing the footer's right-hand label onto a second row, which moved the text under the mouse and could copy the wrong line
- Fixed a PreToolUse hook's reason for asking not showing on terminal Read, Grep, Glob, Edit and Write prompts (#102892, #105343)
- Fixed temp_* folders piling up in ~/.claude/plugins/cache when a downloaded plugin couldn't be copied into place
- Fixed --effort being ignored when starting an interactive session with --environment while CLAUDE_CODE_EFFORT_LEVEL is set to the same level
- Fixed headless and cloud sessions reporting a foreground fork's Agent call as finished the moment the fork started
- Fixed local MCP servers seeing a new session ID after a Remote Control session's process restarts
- Fixed idle compaction being skipped for subscribers still well under their weekly limit
- Fixed an @-mentioned text file with an extension being silently dropped when even its first 2,000 lines exceed the read limit; Claude is now told its size and how to read it
- Fixed the plugin "not cached" error pointing to /plugin instead of /reload-plugins, the command that reloads plugins
- Fixed self-hosted runner sessions failing their first clone under Anthropic-managed git when the machine's git config has an includeIf "gitdir:" or (git 2.44 to 2.46) "onbranch:" section
- Fixed replies that start with phrases like "You've used" or "You've hit your" showing as a red usage limit error
- Fixed a resumed conversation sometimes missing its last messages after a crash or kill on Bedrock, Google Cloud's Agent Platform, Foundry and other third-party providers
- Fixed NotebookEdit saving an invalid notebook when an edit changes a cell's type; turning a cell with attachments into code is now refused
- Fixed a long README in a design system moved from standalone Claude Design losing its list of files to load when Claude starts a deck or design
- Fixed MCP tool calls failing with "malformed task handle" when the server's task ID is longer than 128 characters; IDs of up to 1,024 characters now work
- Self-hosted runner: Fixed --configure-git sometimes reporting a hung git --version as a git that isn't on PATH
- 新增来自 MCP 服务器的技能(测试版)。它们在 / 菜单中显示为 server:skill;其他技能保留其原有名称
- 新增 PreSkillShellCommand 钩子事件,可在加载时拒绝技能或命令的内联 shell 命令;在 2.1.331 及更早版本中,命名该事件的设置文件会在启动时打开对话框
- 在来自其他会话的待处理消息提示中新增“始终发送”选项
- 新增一行页脚,当标记的消息所在会话处于不同模型时持续显示,直到你通过 /model 选择一个模型为止
- 新增 OpenTelemetry assistant_response 事件,用于记录 Claude 通过 SendUserMessage 或 Cowork 的消息工具发送的文本,前提是已开启响应日志记录
- 在 VS Code 和桌面版的代码标签页中,当会话的部分内容无法保存时新增警告行,说明如何通过 /compact 进行保存
- 在 VS Code 和桌面版的代码标签页中,当恢复的会话未加载早期消息时新增通知,如同终端中已显示的那样
- 在启动页头中新增你的 Cyber Verification Program 访问层级,当你的层级适用于该模型且使用 claude.ai 账户登录时,会显示在模型名称旁边
- 修复了 claude auth login 在无法保存 claude.ai 登录信息时仍报告“登录成功”的问题:现在退出码为 1,并提示需要检查的内容,例如残留的锁文件或磁盘已满
- 修复了 Read、@提及和压缩在无写入内容的命名管道(如被锁定密钥管理器挂载的 .env)上挂起的问题:读取操作现将在 20 秒后失败
- 修复了在重复自动压缩失败后,若再进行一次达到上下文限制的压缩本可继续处理的对话轮次却以“提示过长”结束的问题
- 修复了在摘要生成超出输出限制时压缩失败的问题:经过三次截断回复后,最后一次尝试现请求更短的摘要
- 修复了在针对长命令检查包含多个通配符的权限规则或钩子条件时发生的冻结问题
- 修复了在大多数情况下,当钩子无限打印输出时导致的冻结和内存泄漏问题
- 修复了在对话轮次期间或 /compact 之后,当钩子阻塞或失败且日志非常大时引发的冻结和上下文溢出问题:超过约 50,000 个字符的文本现会被缩短
- 修复了本地 MCP 服务器向其标准输出大量发送数据时终端冻结以及忽略 Ctrl+C 的问题
- 修复了当提示或管道输入中包含 @ 符号后跟随一个非常长的不间断字符串(如嵌入字体的最小化 CSS)时发生的冻结问题
- 修复了在重写大型跟踪文件后打开回滚点时出现的长时间冻结问题
- 修复了 SSE MCP 服务器在事件流被切断后,若未在新端点恢复或完全断开连接,则挂起或拒绝所有工具调用的问题,直到手动重新连接
- 修复了远程控制在桌面应用、VS Code 或 Agent SDK 中显示会话正在运行,而实际上该会话正等待对话框或 MCP 服务器提问的问题
- 修复了在用量限制已重置后,仍向远程控制、IDE 和 SDK 客户端报告已达上限的问题
- 修复了在使用 EnterWorktree 将会话移入 .claude/worktrees 下的工作树或在该处恢复会话时,CLAUDE.md 和规则文件在大多数情况下被第二次发送给模型的问题
- 修复了在重启后的会话中拒绝权限提示时,从未执行的工具调用在 claude.ai 聊天摘要行中被计为已完成的问题
- Linux:修复了 Bash 编辑差异在 Claude 通过符号链接读取文件后,将未更改的符号链接显示为已编辑的问题
- 修复了当转录记录包含大量损坏行时,恢复会话和 /stats 命令出现数秒冻结的问题
- 修复了当 availableModels 仅允许其较旧版本时,--fallback-model 中的家族名称(如 sonnet)被丢弃的问题
- 修复了 /stats 读取大型会话转录记录期间按键延迟数秒的问题,包括对话框关闭后以及语言服务器在调试日志开启状态下向其 stderr 大量输出时的情况
- 修复了当云服务拒绝其默认模型,且未强制执行的 availableModels 列表既不包含该模型也不包含该家族的较旧模型时,会话失败的问题
- 修复了当第一个模型被拒绝时,Google Cloud 的 Agent Platform 和 Foundry 上强制使用的较旧模型列表失败的问题:现在它会降级到该家族中的下一个模型(如果按从新到旧列出)
- 修复了 opus 在 Bedrock、Google Cloud 的 Agent Platform 和 Foundry 上因网关以其自身理由拒绝某模型而失败的问题:现在它会降级到能响应的较旧模型
- 修复了 Bedrock 和 Google Cloud 的 Agent Platform 上的启动模型升级提议命名了 availableModels 列表中未包含的模型的问题
- 修复了当父级区域中账户未列出其模型的配置文件时,Bedrock 子代理失败的问题:现在它们使用该模型自身的配置文件,该配置文件可能位于该区域之外
- 修复了当管理员的列表阻止了 sonnet、opus 或 haiku 所指向的版本时,Foundry 会话脱离模型家族的问题:现在它们在内置或映射名称下使用其最新允许的版本
- 修复了 Bedrock Mantle 上的 sonnet 别名解析为 Haiku 4.5 的问题:现在它表示 Sonnet 5,而非 Sonnet 5.5;且没有 Sonnet 5 的账户会收到错误,因此需先启用它
- 修复了在提示符下按 Ctrl+C 开始新对话时,以及连续按两次 Ctrl+C 未能退出的问题,当后台代理停止时有未读的子代理报告
- 修复了 /install-github-app 命令在按 Esc 返回后再次勾选工作流的问题
- 修复了超过 10,000 字符的语音输入文本丢失的问题
- 修复了非流式重试获取到损坏响应或被中断时,出现原始 "JSON Parse error" 和 "The operation was aborted." API 错误的问题
- 修复了在 macOS 上,当 Claude Code 窗口或你允许的应用程序位于前台时,Esc 键无法在操作之间停止计算机使用的问题;现在针对该应用程序弹出窗口的 Esc 按键将改为停止计算机使用
- 修复了辅助命令(如 API 密钥辅助工具)运行超出时间限制时偶尔出现的挂起问题
- 修复了在全屏模式下选中文本会将页脚右侧标签推至第二行,导致鼠标下的文本移动并可能复制错误行的问题
- 修复了 PreToolUse 钩子中请求的原因未在终端 Read、Grep、Glob、Edit 和 Write 提示中显示的问题 (#102892, #105343)
- 修复了当下载的插件无法复制到指定位置时,~/.claude/plugins/cache 目录中 temp_* 文件夹堆积的问题
- 修复了在使用 --environment 启动交互式会话且 CLAUDE_CODE_EFFORT_LEVEL 设置为相同级别时,--effort 参数被忽略的问题
- 修复了无头模式和云模式会话在分叉进程刚开始时就报告其前台分叉的 Agent 调用已完成的问题
- 修复了本地 MCP 服务器在远程控制会话进程重启后看到新的会话 ID 的问题
- 修复了对于远低于每周限制的订阅者跳过空闲压缩的问题
- 修复了当带扩展名的 @提及文本文件的前 2,000 行甚至超过读取限制时,该文件被静默丢弃的问题;现在会告知 Claude 该文件的大小及如何读取它
- 修复了插件“未缓存”错误指向 /plugin 而非 /reload-plugins(用于重新加载插件的命令)的问题
- 修复了在 Anthropic 管理的 git 环境下,当机器的 git 配置包含 includeIf "gitdir:" 部分或 (git 2.44 至 2.46) "onbranch:" 部分时,自托管运行器会话首次克隆失败的问题
- 修复了以“您已使用”或“您已达到”等短语开头的回复显示为红色用量限制错误的问题
- 修复了在 Bedrock、Google Cloud 的 Agent Platform、Foundry 和其他第三方提供商上,崩溃或强制终止后恢复的对话有时丢失最后几条消息的问题
- 修复了 NotebookEdit 在编辑更改单元格类型时保存无效笔记本的问题;现在拒绝将带有附件的单元格转换为代码
- 修复了从独立部署的 Claude Design 迁移到设计系统后,README 文件过长导致在 Claude 启动 deck 或设计时丢失需要加载的文件列表的问题
- 修复了当服务器的任务 ID 超过 128 个字符时 MCP 工具调用因“格式错误的任务句柄”而失败的问题;现在支持长度达 1,024 个字符的 ID
- 自托管运行器:修复了 --configure-git 有时将挂起的 git --version 误报为 PATH 中不存在的 git 的问题
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力