@ampcode/plugin

中文文档
0.0.0-20261106001255-g161ec3f发布于 2026/11/06Amp Commercial LicenseTypeScriptES Module零依赖近 30 天下载 14.4万

Amp Plugin API

原始使用文档
文档目录4 节
  1. Locations
  2. Minimal Plugin
  3. Documentation
  4. Acknowledgment

Amp Plugin API

Amp plugins are TypeScript files that extend and customize Amp.

Plugins can:

  • Handle events — amp.on(...) for tool calls, tool results, and agent lifecycle events
  • Add tools — amp.registerTool(...) for custom tools the agent can call
  • Bundle skills — await amp.registerSkill(...) to register skill directories
  • Add commands — amp.registerCommand(...) for command palette actions
  • Show UI — ctx.ui.notify(...), ctx.ui.confirm(...), ctx.ui.input(...), and ctx.ui.select(...)
  • Use AI — amp.ai.ask(...) for thread-scoped yes/no classification that defaults to no reasoning unless { reasoningEffort } is set
  • Decide fast — amp.ai.decide(...), amp.ai.choice(...), amp.ai.noul(...), and amp.ai.score(...) for typed decisions with calibrated probabilities and no generated text, answered by TypeSafe's Jev, or by OpenAI's Decisions API when you pass { model: 'openai/gpt-6-luna' }
  • Label threads — ctx.thread.labels(), ctx.thread.addLabels(...), and ctx.thread.setLabels(...) to read and change the current thread's labels
  • Upload attachments — amp.attachments.upload(...) to upload image bytes and get back a URL for URL-backed { type: 'image', mimeType, url } tool result blocks, keeping large images out of thread state

Locations

Amp loads plugins from three locations:

  • Project plugins — .amp/plugins/*.ts
  • System plugins — ~/.config/amp/plugins/*.ts
  • Global plugins — configured in workspace settings (limited experimental release)

Minimal Plugin

import type { PluginAPI } from '@ampcode/plugin'

export const description = 'Shows a notification when a thread session starts'

export default function (amp: PluginAPI) {
    amp.logger.log('Plugin initialized')

    amp.on('session.start', async (event, ctx) => {
        await ctx.ui.notify(`Thread ${event.thread.id} started.`)
    })
}

The optional description named export must be a static string literal of at most 300 characters. Amp shows it in plugin settings and ignores missing, dynamic, or longer values.

Code in the exported function runs when the plugin loads. Use session.start only for work that should run when Amp starts a specific thread session.

After changing a plugin, open the command palette and run plugins: reload, or restart Amp.

Documentation

Plugins execute code, so only use plugins from people and workspaces you trust.

Acknowledgment

Amp's plugin API is inspired by pi's extension API, created by Mario Zechner.

版本与发布记录

@ampcode/plugin 共发布 265 个版本,首次发布于 2026/02/25;过去 12 个月发布了 265 个版本。

版本发布日期距今
0.0.0-20261106001255-g161ec3flatest2026/11/061 天前
0.0.0-20261105001227-g2499c302026/11/052 天前
0.0.0-20261104001221-gc8c68be2026/11/043 天前
0.0.0-20261103001141-ga6248e32026/11/034 天前
0.0.0-20261102001236-gf10f41a2026/11/025 天前
0.0.0-20261101001405-ga7b498d2026/11/016 天前

关于 @ampcode/plugin 的常见问题

@ampcode/plugin 是什么?

Amp Plugin API

如何安装 @ampcode/plugin?

在项目目录运行 npm install @ampcode/plugin,或使用 pnpm add / yarn add / bun add。

@ampcode/plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ampcode/plugin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ampcode/plugin 可以商用吗?

@ampcode/plugin 使用 Amp Commercial License 许可。声明的许可为 Amp Commercial License,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@ampcode/plugin 的下载量有多少?

根据 npm 官方下载统计,@ampcode/plugin 在 2026/10/06 – 2026/11/04 这 30 天内被下载 144,189 次,日均约 4,806 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ampcode/plugin 还在维护吗?

最新版本 0.0.0-20261106001255-g161ec3f 发布于 2026/11/06(1 天前);至今共发布 265 个版本,其中过去 12 个月发布了 265 个;首次发布于 2026/02/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。