plugins

Plugins 允许通过 TypeScript 代码扩展 Claude Code 的功能。

设计理念

Skills 提供上下文,但无法添加新功能。Plugins 提供完整的扩展能力:

  • 添加新工具

  • 修改核心行为

  • 集成外部系统

  • 自定义 UI 组件

Plugin 结构

基本格式

// .kiro/plugins/my-plugin.ts

import { Plugin, Tool } from '@anthropic-ai/claude-code';

export default {
  name: 'my-plugin',
  version: '1.0.0',
  description: 'My custom plugin',
  
  // 提供的工具
  tools: [
    new MyCustomTool(),
  ],
  
  // 生命周期钩子
  onLoad: async (context) => {
    console.log('Plugin loaded');
  },
  
  onUnload: async () => {
    console.log('Plugin unloaded');
  },
} satisfies Plugin;

Plugin 接口

创建自定义工具

实现 Tool 接口

使用外部库

Plugin 生命周期

onLoad

Plugin 加载时调用:

onUnload

Plugin 卸载时调用:

Plugin 配置

配置文件

读取配置

示例 Plugin

数据库查询工具

Plugin 发现

自动加载

下一步