官方更新 Claude Blog 2026-10-02T00:01 正文 ok 742 words

使用 Mods 自定义 Claude Code

英文标题:Customize Claude Code with mods

Anthropic 推出 Claude Code Mods:可通过小型 TypeScript 函数改变 Claude Code 的提示词、工具调用、权限处理和界面行为。Mods 随插件分发,支持 Claude Code CLI 和桌面应用,开发者既可自行编写,也可让 Claude Code 协助创建、安装并热重载。该机制让用户能够替换内置功能、叠加不同作者的扩展,并为团队提供 CI/CD 状态展示、生产环境防护和审计日志等定制能力。由于 Mods 拥有与 Claude Code 相同的本机访问权限且未受沙箱隔离,用户和企业管理员需要仅安装可信来源的插件,并利用托管设置与 `sec-default` 等机制实施安全控制。
打开原文相关 3.6 · 机会 1
media49.2 KB media403 B media27.9 KB media10.7 KB media13.7 KB media6.9 KB media67.2 KB

中文

今天,我们推出 Mods:用于改变 Claude Code 工作方式的小型 TypeScript 函数。一个 Mod 可以改写提示词、添加新的 UI、替换内置功能,或增加全新的功能。你可以自己编写 Mod,也可以让 Claude Code 为你编写。Mods 随插件一起发布,因此你可以像安装和分享其他插件一样安装和分享它们。它们可在 Claude Code CLI 和桌面应用中运行。

Mods 对你的计算机拥有与 Claude Code 本身相同的访问权限。它们未在沙箱中运行,因此你应当只安装来自可信来源的 Mods,就像在计算机上安装其他代码一样。

如需了解 Mods 能做什么,请阅读我们的首个 Mod 构建指南。

我们为何构建 Mods

开发者希望能更好地控制 Claude Code 的工作方式,而无需等待我们推出某项功能。Hooks 已经帮助用户获得部分这类控制能力,但 hooks 无法改写事件、绘制新的 UI 或替换功能。Mods 可以。

我们希望 Claude Code 能让你感觉它真正属于你,使你可以按照自己的工作方式来塑造它。我们在发布前已于 GitHub 上分享了 Mods 的设计方案,以获取开发者反馈。感谢所有参与讨论的开发者。

Mods 的工作方式

每当 Claude Code 执行某项操作时,都会发出一个事件。例如,调用工具、请求权限和绘制部分屏幕内容都会产生事件。Mod 是挂接到这些事件之一的函数。Mod 可以在事件之前、之后或替代事件运行;它也可以包装事件,即同时在事件前后运行代码。通过一个函数,Mod 可以:

  • 在提示词到达模型之前对其进行改写。
  • 阻止、改写或重试一次工具调用。
  • 批准或拒绝权限请求。
  • 在 Claude 读取工具输出前,从中隐去机密信息。

Mod 也可以改变你看到的内容。它可以编辑或替换 Claude Code 绘制的部分界面,例如工具结果或 Claude 提出的问题。它可以添加按钮和输入控件,其他 Mods 可以在你点击这些控件时作出响应。目前,Mod 可以面向终端、桌面应用,或两者同时生效。

当多个 Mods 挂接同一个事件时,它们会按照加载顺序运行。最先加载的 Mod 最先看到事件、最后看到结果。这使你能够叠加使用来自不同作者的 Mods。

你还可以使用 Claude Code 来改造 Claude Code。让 Claude 创建一个 Mod,它就能编写 TypeScript 代码、安装该 Mod,并在你的会话中对其进行热重载。

用自己的功能替换内置功能

Claude Code 的部分内置功能现在以 Mods 的形式发布。例如,内置的 /diff 功能现在就是一个 Mod,因此你可以将其关闭(通过 /plugin),或用自己的版本替换它。我们计划随着时间推移将更多内置功能迁移为 Mods,让你可以把 Claude Code 精简为一个小型核心,再只添加你需要的功能。

面向团队和企业的 Mods

Mods 随插件一起发布,因此你现有的插件控制机制同样适用。管理员可以允许或阻止插件市场。在 Team 和 Enterprise 计划中,所有者可在管理控制台中进行设置。在 Claude API 和第三方 API 计划中,管理员会将托管设置推送至用户的计算机。

在 Team 和 Enterprise 计划中,以及任何启用了托管设置的计算机上,一个名为 sec-default(“安全默认值”)的内置 Mod 会最先加载。它会阻止用户安装的 Mods 执行高风险操作,例如覆盖你的权限拒绝规则。你可以查看源代码,了解它限制了哪些行为。管理员也可以让自己的 Mods 最先加载。如果这样做,请将 sec-default 加入你的列表,以保留其限制措施。

团队还可以使用 Mods 构建自己的控制机制和功能。例如:

  • **CI/CD 状态:**Mod 可以在对话旁的窗格中显示你的流水线状态,并在构建成功或失败时更新状态。
  • **生产环境防护:**Mod 可以要求在任何命令触及生产环境配置之前进行确认。
  • **审计日志:**最先加载的 Mod 可以记录其他每个 Mod 发起的每一次调用。

开始使用

Mods 现已在 Claude Code CLI 和桌面应用中可用。你可以从 Claude directory 安装包含 Mods 的插件,或在 CLI 中运行 /plugin。如需分享 Mod,请将其打包为插件,并提交至目录。

如需构建自己的 Mods,请阅读我们的入门指南,或参阅文档。

English / 原文

Today we're introducing mods, small TypeScript functions that change how Claude Code works. A mod can rewrite a prompt, add new UI, replace a built-in feature, or add entirely new functionality. You can write a mod yourself, or ask Claude Code to write one for you. Mods ship inside plugins, so you install and share them like any plugin. They work in the Claude Code CLI and desktop app.

Mods run with the same access to your machine as Claude Code itself. They aren’t sandboxed, and you should only install mods from sources you trust, the same way you'd install any code on your computer.

To see what mods can do, read our guide to building your first mod.

Why we built mods

Developers have asked for more control over how Claude Code works, without waiting for us to ship a feature. Hooks helped give users some of this control, but hooks can't rewrite events, draw new UI, or replace features. Mods can.

We want Claude Code to feel like yours, so you can shape it to the way you work. We shared the design for mods on GitHub before launch to get feedback from developers. Thank you to everyone who weighed in.

How mods work

Each time Claude Code does something, it emits an event. Examples include calling a tool, asking for permission, and drawing part of the screen. A mod is a function that hooks into one of these events. A mod can run before the event, after it, or instead of it. It can also wrap the event, running code both before and after. With one function, a mod can:

  • Rewrite a prompt before it reaches the model.
  • Block, rewrite, or retry a tool call.
  • Approve or deny a permission request.
  • Redact secrets from tool output before Claude reads it.

A mod can also change what you see. It can edit or replace part of the interface Claude Code draws, like a tool result or a question from Claude. It can add buttons and inputs, and other mods can respond when you press them. Today, a mod can target the terminal, the desktop app, or both.

When several mods hook the same event, they run in the order they load. The first mod to load sees the event first and the result last. This lets you stack mods from different authors.

You can also use Claude Code to mod Claude Code. Ask Claude to create a mod, and it can write the TypeScript, install it, and hot reload it in your session.

Swap built-in features for your own

Some built-in features of Claude Code now ship as mods. For example, the built-in /diff feature is now a mod, so you can turn it off (in /plugin) or replace it with your own version. We plan to move more built-in features to mods over time, so you can pare Claude Code down to a small core and add back only what you want.

Mods for teams and enterprises

Mods ship inside plugins, so your existing plugin controls apply. Admins can allow or block plugin marketplaces. On Team and Enterprise plans, an owner sets this in the admin console. On Claude API and third-party API plans, admins push managed settings to users' machines.

On Team and Enterprise plans, and on any machine with managed settings, a built-in mod called sec-default (“security default”) loads first. It stops mods that users install from doing risky things, like overriding your permission deny rules. You can view the source code to see what it restricts. Admins can load their own mods first instead. If you do, add sec-default to your list to keep its restrictions.

Teams can also use mods to build their own controls and functionality. For example:

  • CI/CD status: a mod can show your pipeline’s status in a pane beside the conversation, and update it as builds pass or fail.
  • Production safeguards : a mod can require confirmation before any command touches production config.
  • Audit logging: a mod that loads first can record every call that every other mod makes.

Getting started

Mods are available today in the Claude Code CLI and desktop app. Install plugins that include mods from the Claude directory or by running /plugin in the CLI. To share a mod, package it in a plugin and submit it to the directory.

To build your own mods, read our getting started guide or see the documentation.