制作第一个 Mod
最快的方式是直接用一句话让 Claude 来做。Claude Code 内置了制作 Mod 的 plugin-authoring 技能。
用一句话让 Claude 做
Section titled “用一句话让 Claude 做”在对话旁边做一个窗口,统计本次会话的工具调用次数Claude 在 Mod 文件夹里写下第一个文件时,会询问 “Enable hot reloading for this session?”。选择 Enable for this session 后,每个回合结束时,修改的内容都会立即重新加载。
-
创建清单。
.claude-plugin/plugin.json { "name": "first-mod", "version": "0.1.0", "description": "统计工具调用次数" } -
写明钩子模块的位置。路径以这个文件为基准。
hooks/hooks.json { "modules": ["./register.ts"] } -
注册钩子。窗口用
$.ui.open打开,由ui.render钩子绘制其中的内容。hooks/register.tsx import type { Register } from 'claude-code'let calls = 0export const register: Register = on => {on('session.start', async ($, e, next) => {await $.command.register({ name: 'calls', description: '打开工具调用次数窗口' })return next(e)})on('command.run', { command: 'calls' }, async $ => {await $.ui.open({ id: 'calls', title: 'Tool calls' })return { text: '窗口已打开。' }})on('tool.call', async ($, e, next) => {calls += 1$.ui.invalidate('ui.render')return next(e)})on('ui.render', { component: 'Pane', requestId: 'calls' }, async ($, e) => {const { Text } = $.ui.resolve(e)return <Text>工具调用 {calls} 次</Text>})} -
在一个会话中加载试用。
终端窗口 claude --plugin-dir ./first-mod
claude plugin validate ./first-mod # 钩子和调用列表,以及引擎会拒绝的部分claude plugin test ./first-mod # 运行 *.test.ts(x)测试使用 claude-code/testing 的 test、expect、mock。用测试中的 on 在引擎的位置铺设假响应,再用 $.ui.mount 把窗口按终端、桌面的界面原样绘制出来,点击按钮并检查结果。类型由引擎安装在 Mod 文件夹的 .claude-plugin/types/ 中,加载一次之后,就可以用 tsc -p <文件夹> 检查。
在仓库根目录放一个插件市场文件就完成了。
{ "name": "first-mod", "owner": { "name": "you" }, "plugins": [{ "name": "first-mod", "source": "./" }]}其他人这样安装。
/plugin install first-mod --marketplace you/first-mod给 GitHub 仓库加上 claude-code-mod topic,社区目录会在几小时内收录。
非官方社区指南,与 Anthropic 无关联,也未获其认可。Claude 与 Claude Code 是 Anthropic 的商标。