用几行 TypeScript,改变 Claude Code 的行为与外观。
Change how Claude Code behaves and looks with a few lines of TypeScript.
今天,我们推出 Mods:用于改变 Claude Code 工作方式的小型 TypeScript 函数。一个 Mod 可以改写提示词、添加新的 UI、替换内置功能,或加入全新的能力。你可以自己编写 Mod,也可以让 Claude Code 帮你写。Mods 随插件一起分发,因此安装和分享方式与其他插件相同。它们可以在 Claude Code CLI 和桌面应用中使用。
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 对你的计算机拥有与 Claude Code 本身相同的访问权限。它们不在沙箱中运行,因此你应当只安装来自可信来源的 Mods,就像在计算机上安装其他代码一样。
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.
想了解 Mods 能做什么,请阅读我们的首个 Mod 构建指南。
To see what mods can do, read our guide to building your first mod.
我们为什么开发 Mods
Why we built mods
开发者希望更自主地控制 Claude Code 的工作方式,而无须等待我们发布某项功能。Hooks 已经提供了其中一部分控制能力,但 Hooks 无法改写事件、绘制新的 UI 或替换功能。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.
我们希望 Claude Code 能成为真正属于你的工具,让你按照自己的工作方式塑造它。为收集开发者的反馈,我们在发布前就在 GitHub 上分享了 Mods 的设计。感谢每一位提出意见的人。
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.
Mods 如何工作
How mods work
Claude Code 每次执行操作时,都会发出一个事件,例如调用工具、请求权限或绘制部分屏幕界面。Mod 是一个接入此类事件的函数。它可以在事件发生之前、之后运行,也可以代替事件本身执行。它还可以包裹事件,在前后都运行代码。只用一个函数,Mod 就能够:
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:
- 在提示词送达模型之前改写它。
- 阻止、改写或重试工具调用。
- 批准或拒绝权限请求。
- 在 Claude 读取工具输出之前,隐去其中的机密信息。
- 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.
Mod 也能改变你看到的内容。它可以编辑或替换 Claude Code 绘制的部分界面,例如工具结果或 Claude 提出的问题。它可以添加按钮和输入控件,其他 Mods 则可以在你按下这些控件时作出响应。目前,一个 Mod 可以面向终端、桌面应用,或者同时面向两者。
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.
当多个 Mods 接入同一事件时,它们会按照加载顺序运行。最先加载的 Mod 最先看到事件,最后看到结果。这样,你就可以叠加使用不同作者编写的 Mods。
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.
你也可以用 Claude Code 为 Claude Code 编写 Mod。让 Claude 创建一个 Mod,它就可以编写 TypeScript、完成安装,并在当前会话中热重载。
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
Claude Code 的一些内置功能现在已经以 Mods 的形式提供。例如,内置的 /diff 功能现在就是一个 Mod,因此你可以在 /plugin 中关闭它,或用自己的版本替换它。我们计划逐步将更多内置功能迁移为 Mods,让你能够将 Claude Code 精简到一个小型核心,再只加回自己需要的功能。
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
Mods for teams and enterprises
Mods 随插件一起分发,因此现有的插件管理控制同样适用。管理员可以允许或屏蔽插件市场。在 Team 和 Enterprise 套餐中,由所有者在管理控制台中设置。在 Claude API 和第三方 API 套餐中,管理员向用户计算机推送托管设置。
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.
在 Team 和 Enterprise 套餐中,以及任何应用了托管设置的计算机上,一个名为 sec-default(“默认安全设置”)的内置 Mod 会最先加载。它会阻止用户安装的 Mods 执行有风险的操作,例如覆盖你的权限拒绝规则。你可以查看源代码,了解它施加了哪些限制。管理员也可以改为优先加载自己的 Mods。如果这样做,请将 sec-default 加入加载列表,以保留它的限制。
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.
团队也可以利用 Mods 构建自己的控制机制和功能。例如:
Teams can also use mods to build their own controls and functionality. For example:
- CI/CD 状态:Mod 可以在对话旁的面板中显示流水线状态,并在构建成功或失败时更新。
- 生产环境保护:Mod 可以要求在任何命令涉及生产环境配置之前先进行确认。
- 审计日志:最先加载的 Mod 可以记录其他每个 Mod 发出的每一次调用。
- 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 即日起可在 Claude Code CLI 和桌面应用中使用。你可以从 Claude 目录安装包含 Mods 的插件,也可以在 CLI 中运行 /plugin 进行安装。要分享一个 Mod,请将其打包为插件,并提交到目录。
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.
— 全文完 —
原文来自 Anthropic,中文为非官方学习译文。
查看原始出处 ↗