modified
--- a/create.md +++ b/create.md @@ -25,7 +25,7 @@ When Claude saves the first file, Claude Code asks whether to enable hot reloading for the session. Hot reloading runs the mods Claude writes in this session and picks up each later change. You don’t see this question in a session that loads new mods without asking or can’t load them.Choose one of these answers: - * **Turn them on** : the mods in the session’s mods folder load when the turn ends, and reload at the end of each turn that changes them. Your answer lasts for the session, including after you resume it. + * **Turn them on** : the mods in the session’s mods folder load when the turn ends, and reload at the end of each turn that changes their code. Your answer lasts for the session, including after you resume it. * **Not now** : nothing loads for now. The files stay where Claude wrote them, and the mods load the next time that session starts. To keep a mod from ever loading, delete its directory. 3 @@ -38,7 +38,7 @@ Try the mod -Use what you asked for. For the example prompt, the current branch name appears above the prompt box. If the mod doesn’t do what you wanted, tell Claude what to change. The mod reloads at the end of each turn that changes its files, so you can try the change as soon as Claude finishes.If a transcript line that starts with the mod’s name says the [change didn’t load](</docs/en/plugins/mods/troubleshoot#this-mods-change-didnt-load>), paste that line into your next message when you ask Claude for a fix. Claude doesn’t see the line unless you paste it. +Use what you asked for. For the example prompt, the current branch name appears above the prompt box. To adjust the mod, tell Claude what to change. The mod reloads at the end of each turn that changes its code, so you can try the change as soon as Claude finishes.If a transcript line that starts with the mod’s name says the [change didn’t load](</docs/en/plugins/mods/troubleshoot#this-mods-change-didnt-load>), paste that line into your next message when you ask Claude for a fix. Claude doesn’t see the line unless you paste it. ### Use the mod in other sessions @@ -122,7 +122,7 @@ Write the code -This file is the mod’s code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](</docs/en/plugins/mods/reference#the-hook-function>). Each call to `on` registers an event handler, called a hook, for the event it names.Save this as `first-mod/hooks/register.js`: +This file is the mod’s code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](</docs/en/plugins/mods/events#how-a-hook-handles-an-event>). Each call to `on` registers an event handler, called a hook, for the event it names.Save this as `first-mod/hooks/register.js`: first-mod/hooks/register.js @@ -166,10 +166,10 @@ The file keeps a count in `calls` and registers four hooks: - * **[`session.start`](</docs/en/plugins/mods/reference#session>)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code. - * **[`tool.call`](</docs/en/plugins/mods/reference#tools>)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again. - * **[`command.run`](</docs/en/plugins/mods/reference#commands-and-configuration>)** runs when you type `/tally`. It returns the text to print. - * **[`ui.render`](</docs/en/plugins/mods/reference#interface>)** runs each time Claude Code draws the spinner. It adds the count after the spinner’s word. + * **[`session.start`](</docs/en/plugins/mods/api#add-a-command-or-a-tool>)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code. + * **[`tool.call`](</docs/en/plugins/mods/events#guard-or-change-a-tool-call>)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again. + * **[`command.run`](</docs/en/plugins/mods/api#add-a-command>)** runs when you type `/tally`. It returns the text to print. + * **[`ui.render`](</docs/en/plugins/mods/interface#pick-where-to-draw>)** runs each time Claude Code draws the spinner. It adds the count after the spinner’s word. How the example mod works explains the three arguments each hook takes and what each one returns. @@ -213,8 +213,8 @@ Each function you pass to `on` is a hook, which is an event handler. Claude Code passes every hook the same three arguments: - * **The mods API** , named `$`: every method a mod can call to reach outside itself, in [namespaces](</docs/en/plugins/mods/reference#mods-api-methods>) such as `$.ui` and `$.command` - * **The event** , named `e`: the [event’s input](</docs/en/plugins/mods/reference#events>) as plain data, such as a tool call’s name and arguments + * **The mods API** , named `$`: every method a mod can call to reach outside itself, in [namespaces](</docs/en/plugins/mods/api>) such as `$.ui` and `$.command` + * **The event** , named `e`: the [event’s input](</docs/en/plugins/mods/events#how-a-hook-handles-an-event>) as plain data, such as a tool call’s name and arguments * **The next handler** , named [`next`](</docs/en/plugins/mods/events#how-a-hook-handles-an-event>): a function that passes the event on to the other mods and then to Claude Code’s own behavior, and returns the result The hooks in `first-mod` handle their events in these ways: @@ -223,7 +223,7 @@ * **Answer** : the `command.run` hook returns its own result and never calls `next`. The second argument to `on`, `{ command: 'tally' }`, is a filter, called a [matcher](</docs/en/plugins/mods/events#filter-which-events-a-hook-handles>), so the hook runs only for `/tally`. * **Rewrite** : the `ui.render` hook calls `next` with a copy of `e` whose `suffix` holds the count, so Claude Code draws its usual spinner with your text after the word -Claude Code watches a directory loaded with `--plugin-dir` and hot-reloads the hooks module when a file in it changes. Each reload runs `register` again, so `calls` resets to `0` and `/tally` starts counting again. To keep a value across reloads, see [Keep state](</docs/en/plugins/mods/interface#keep-state>). +When you change the hooks module’s code during an interactive `--plugin-dir` session, Claude Code hot-reloads the module. Each reload runs `register` again, so `calls` resets to `0` and `/tally` starts counting again. To keep a value across reloads, see [Keep state](</docs/en/plugins/mods/interface#keep-state>). ## Keep working on a mod @@ -235,7 +235,7 @@ claude --plugin-dir ./first-mod -Then ask for the change, for example `add a /tally-reset command to this mod that sets the tally back to zero`. Claude edits the hooks module, runs `claude plugin validate`, and fixes what it reports. A directory you load with `--plugin-dir` is a [protected path](</docs/en/permission-modes#protected-paths>), so in `default` and `acceptEdits` modes you’re asked to approve each of Claude’s edits to the mod. The protected paths table gives the result for the other permission modes. Files Claude saves during its turn reload when the turn ends, so you can try `/tally-reset` as soon as Claude finishes. +Then ask for the change, for example `add a /tally-reset command to this mod that sets the tally back to zero`. Claude edits the hooks module, runs `claude plugin validate`, and fixes what it reports. A directory you load with `--plugin-dir` is a [protected path](</docs/en/permission-modes#protected-paths>), so in `default` and `acceptEdits` modes you’re asked to approve each of Claude’s edits to the mod. The protected paths table gives the result for the other permission modes. The mod reloads when Claude’s turn ends, so you can try `/tally-reset` as soon as Claude finishes. ### Get type definitions for your version @@ -245,11 +245,11 @@ ---|--- `claude-code/index.d.ts`| Every event and its input and result, every mods API namespace and method, and the elements each surface can draw `claude-code-tools/index.d.ts`| The built-in tools’ inputs and results, so that checking `e.tool === 'Bash'` narrows `e` -`claude-code-mcp/index.d.ts`| The inputs of the MCP tools that were connected the last time you saved a file in the mod +`claude-code-mcp/index.d.ts`| The inputs of the session’s MCP tools, updated when the mod hot-reloads with a server connected `index.d.ts` in a directory named for a plugin| What that plugin adds to the mods API. There’s one directory for each plugin your `plugin.json` lists under `dependencies`. `tsconfig.json`| Compiler options that fit a hooks module -If your mod has no `tsconfig.json` of its own, Claude Code adds one at the mod’s root that extends the generated one, so your editor and `tsc -p ./first-mod` type-check the mod without more setup. The events and methods can change between releases, so trust these files over any page, this one included, when they disagree. `claude-code/index.d.ts` is the fullest reference for your build, with a comment and an example for every mods API method. To look something up, search the file for its name, such as `'tool.call'`. +If your mod has no `tsconfig.json` of its own, Claude Code adds one at the mod’s root that extends the generated one, so your editor and `tsc -p ./first-mod` type-check the mod without more setup. Events and methods can change between releases, so use these files as the reference for your version. To look up an event or method, [search `claude-code/index.d.ts`](</docs/en/plugins/mods/reference#look-up>) for its name, such as `'tool.call'`. ### Check what Claude Code reads from your mod
modified
--- a/create.md +++ b/create.md @@ -264,15 +264,19 @@ ✔ Validation passed -Check the `hooks:` line for the events your module hooks, each with its filter in braces, and `calls:` for every mods API method it calls. If your module reads or sets environment variables, look for `env reads:` and `env writes:` lines too, and `state reads:` and `state writes:` if it uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>). You also see one line for each hook that can refuse an action, such as `gating hook without .catch: tool.call`, which says whether that hook has a [`.catch` handler](</docs/en/plugins/mods/events#handle-a-hook-that-fails>). If an event you meant to handle is missing from the `hooks:` lines, Claude Code won’t call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`. Follow these rules so that static analysis can find every hook and call: - - * Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. You can pass `$` to a function declared at the top level of the same file, and for a function of yours named `loadNotes`, the `calls:` line then reads `$.store.get (via loadNotes)`. Passing `$` to a method, a function defined inside the hook, or a function you import from another of your files fails validation. The `read` and `update` functions that [`$.state`](</docs/en/plugins/mods/interface#keep-state>) uses are the imports that can take it. Don’t assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`. +Check the `hooks:` line for the events your module hooks, each with its filter in braces, and `calls:` for every mods API method it calls. If your module reads or sets environment variables, look for `env reads:` and `env writes:` lines too, and `state reads:` and `state writes:` if it uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>). You also see one line for each hook that can refuse an action, such as `gating hook without .catch: tool.call`, which says whether that hook has a [`.catch` handler](</docs/en/plugins/mods/events#handle-a-hook-that-fails>). If an event you meant to handle is missing from the `hooks:` lines, Claude Code won’t call that hook either. Check each event name against the types for your build, because validation doesn’t catch every typo. For example, `tool.calls` fails with `"tool.calls" is not an event`, but `tol.call` passes validation and the mod then doesn’t load. Follow these rules so that static analysis can find every hook and call: + + * Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. Don’t assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`. * Write the event name in each `on` call as a string literal, such as `'tool.call'`. A variable, or a loop over a list of names, fails with `the event name passed to on() is not a string literal`. * Inside `register`, don’t declare a second variable or parameter named `on`. Validation fails with `"on" is declared again (shadowed)`. * Import only from files inside the plugin directory, by relative path. The one bare import allowed is `claude-code`, for types and a few helpers. * Use `import` declarations at the top of the file, as in `import { name } from './file.js'`. A dynamic `import()` fails with `a dynamic import(); a hooks module imports its own files with an import declaration`. * Write every file as an ES module, with `import` and not `require`. The [reference](</docs/en/plugins/mods/reference#files>) lists the file extensions Claude Code loads. +#### Pass `$` to your functions + +You can pass `$` to a function declared at the top level of your hook’s file, and to the `read` and `update` functions that [`$.state`](</docs/en/plugins/mods/interface#keep-state>) uses. For a function named `loadNotes` that calls `$.store.get`, the `calls:` line reads `$.store.get (via loadNotes)`. Passing `$` to a method or to a function defined inside the hook fails validation. On Claude Code v2.1.299 or later, you can also pass `$` to a function you import from another of your files. Declare it there with the `function` keyword, as in `export function loadNotes($) { ... }`. An imported arrow function fails with `a name bound to a function expression, outside the hook's own file`. + ### Test the mod You can write automated tests for a mod and run them from your shell with `claude plugin test`, with no session, sign-in, or network. A test fires the events your hooks handle and checks what the hooks did. This test fires two tool calls, runs `/tally`, and checks that the reply counts both. Save it as `first-mod/tests/first-mod.test.ts`: @@ -318,7 +322,7 @@ * **Your whole organization** : an administrator can [install your organization’s mods](</docs/en/plugins/mods/admin#install-your-organizations-mods>) through managed settings * **Anyone** : make your marketplace’s repository public, or [submit the plugin to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>) -Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don’t reach the installed copy until you increment the version and install again. +Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an [installed copy](</docs/en/plugins/loading#in-place-and-copied-plugins>). ## Next steps
modified
Show diff (632 lines)
--- a/create.md +++ b/create.md @@ -1,325 +1,330 @@ -A plugin is a directory of skills, agents, hooks, and MCP servers, plus a `plugin.json` file, called the manifest, that names the plugin. Claude Code loads the directory as one unit, so you can share it with teammates, install it in several projects, or publish it to a marketplace. This page is for people writing their own plugins. - -These cases are covered on other pages: - - * **Installing someone else’s plugin** : see [Install plugins](</docs/en/plugins/install>) - * **Not sure you need a plugin** : see [Decide whether you need a plugin](</docs/en/plugins/overview#decide-whether-you-need-a-plugin>) on the overview - * **Your plugin’s users are on claude.ai or in Cowork** : the same folder installs there with a different subset of components. See [Plugin structure and testing](<https://claude.com/docs/plugins/build>) and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) - -Start from the section that matches what you already have: - - * **Nothing yet** : follow Create your first plugin, then Develop without a marketplace and Test and debug. - * **Files under`.claude/` already**: do the first-plugin walkthrough once to learn the layout, then follow Convert an existing `.claude/` setup. - -## Decide when to use a plugin - -Skills, agents, hooks, and MCP servers all work standalone in your project or home directory. Keep that standalone setup while it serves one project or only you. Make a plugin when you want to share the setup with teammates, install it in several projects, or publish versioned releases. When you move standalone skills, agents, hooks, and MCP config into a plugin, their location and names change: - - * **Where the files go** : under the plugin’s own directory, called the plugin root, as `skills/`, `agents/`, `hooks/hooks.json`, and `.mcp.json`. - * **How they’re named** : plugin skills and agents get the plugin name as a prefix, such as `/my-plugin:hello`, so two plugins can each provide a `hello` skill without colliding. - -To move an existing setup into a plugin, see Convert an existing `.claude/` setup. - -## Create your first plugin - -In this walkthrough, you create a plugin whose only component is one skill, a greeting, and run it with `--plugin-dir`, which loads a plugin for one session without installing it. A plugin can hold any mix of [components](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, and none is required; one skill is the smallest example that shows the layout. You need Claude Code [installed and signed in](</docs/en/quickstart#step-1-install-claude-code>). Open a terminal in the directory where you want to keep the plugin, such as `~/projects`, and run the commands in these steps from it. You can keep a plugin anywhere, because you pass its path to Claude Code when you start a session. +A mod is a Claude Code [plugin](</docs/en/plugins/overview>) with an entry file, called the hooks module: a JavaScript or TypeScript file whose functions Claude Code calls when events happen. To make one: + + * **Ask Claude to write it** : describe what you want in a Claude Code session + * **Write it yourself** : follow the tutorial to learn how a mod’s code works. You don’t need Node.js, a bundler, or a build step, because Claude Code loads `.js` and `.ts` files directly. + +If you haven’t decided whether a mod is the right tool, read the [comparison on the overview](</docs/en/plugins/mods/overview#compare-mods-settings-hooks-skills-and-mcp-servers>) first. + +Use Claude Code v2.1.287 or later. In your shell, run `claude --version` to check. To see whether mods can load for you, see [Check whether mods can load](</docs/en/plugins/mods/troubleshoot#check-whether-mods-can-load>). + +## Ask Claude for a mod + +Describe the mod you want in an interactive Claude Code session, and Claude writes it. Claude works from a built-in [skill](</docs/en/skills>) named `plugin-authoring`, which tells it where to write the mod, which events and methods your version has, and how the mod gets loaded. Claude can load the skill when you ask for a mod, or you can load it yourself by running `/plugin-authoring` at the Claude Code prompt. In `auto` and `bypassPermissions` [permission modes](</docs/en/permission-modes>), Claude Code can load the mod without asking you. To be asked first, start a new session in `default` or `acceptEdits` mode, or [switch](</docs/en/permission-modes#switch-permission-modes>) to either mode before you ask for the session’s first mod. In some sessions, the mod can’t load. 1 +Describe the mod + +Ask for the mod in your own words, for example `make a mod that shows the current git branch above the prompt`. Claude writes the mod in a directory of its own in the session’s mods folder, which is `~/.claude/dev-mods/` followed by the session’s ID. A mod’s full path looks like `~/.claude/dev-mods/3f2a9c1e-5b7d-4e8a-9c21-6d0f4b8a7e13/git-branch/`. + +In the `default` and `acceptEdits` [permission modes](</docs/en/permission-modes>), Claude Code asks you to approve each of the mod’s files before Claude creates it, because the mods folder is a [protected path](</docs/en/permission-modes#protected-paths>). Approve each file as it comes up. + +2 + +Approve the mod + +When Claude saves the first file, Claude Code asks whether to enable hot reloading for the session. Hot reloading runs the mods Claude writes in this session and picks up each later change. You don’t see this question in a session that loads new mods without asking or can’t load them.Choose one of these answers: + + * **Turn them on** : the mods in the session’s mods folder load when the turn ends, and reload at the end of each turn that changes them. Your answer lasts for the session, including after you resume it. + * **Not now** : nothing loads for now. The files stay where Claude wrote them, and the mods load the next time that session starts. To keep a mod from ever loading, delete its directory. + +3 + +Check that the mod loaded + +Run `/plugin` at the Claude Code prompt and press Tab until the **Installed** tab is selected. It lists the mod, and you can turn it off there. + +4 + +Try the mod + +Use what you asked for. For the example prompt, the current branch name appears above the prompt box. If the mod doesn’t do what you wanted, tell Claude what to change. The mod reloads at the end of each turn that changes its files, so you can try the change as soon as Claude finishes.If a transcript line that starts with the mod’s name says the [change didn’t load](</docs/en/plugins/mods/troubleshoot#this-mods-change-didnt-load>), paste that line into your next message when you ask Claude for a fix. Claude doesn’t see the line unless you paste it. + +### Use the mod in other sessions + +A mod Claude wrote loads only in the session that made it, and Claude Code deletes that session’s mods folder once it’s older than [`cleanupPeriodDays`](</docs/en/settings-reference#cleanupperioddays>). To keep the mod, copy its directory out of the mods folder to a place of your own, such as `~/mods/git-branch`. Then choose how to load it: + + * **In a session you start** : in your shell, run `claude --plugin-dir ~/mods/git-branch` + * **For other people** : add it to a marketplace so they can install it + +### Sessions that load a mod without asking + +Claude Code can enable hot reloading without asking in `auto` and `bypassPermissions` modes, and the mods load when the turn ends. When you resume a session, interactively or with `claude -p`, the mods already in its mods folder can load without asking. To keep a mod from loading when you resume, delete its directory. + +### Sessions where a mod Claude writes can’t load + +A mod Claude writes doesn’t load in these cases, and Claude Code doesn’t ask to load it: + + * **Nobody is there to approve** : the session is in [`dontAsk` mode](</docs/en/permission-modes>), or it’s the `claude -p` run that writes the mod, in `default` or `acceptEdits` mode, which can’t show you the hot reloading question. + * **An interactive session where the workspace isn’t trusted** : you haven’t accepted the trust prompt for the directory + * **Mods are disabled** : you started with `--safe-mode` or `--bare`, you set `disableAllHooks`, or your organization’s [managed settings block it](</docs/en/plugins/mods/admin#choose-how-much-to-allow>) + +## Write a mod yourself + +In this tutorial you build a mod named `first-mod` that counts the tool calls Claude makes, shows the count beside the spinner while Claude works, and adds a `/tally` command that prints it. You then read the type declarations Claude Code writes beside your mod and run `claude plugin validate`. Together they show you the events and methods your version offers and what Claude Code reads from your code. This recording shows the finished mod. The spinner counts tool calls, `/tally` prints the count, and an edit to the code takes effect while the session runs: + +You write three files: + + first-mod/ + ├── .claude-plugin/ + │ └── plugin.json + └── hooks/ + ├── hooks.json + └── register.js + + * **`plugin.json`** : the plugin’s [manifest](</docs/en/plugins/manifest-reference>) + * **`hooks.json`** : [points to your code file](</docs/en/plugins/mods/reference#files>) + * **`register.js`** : your code, called the hooks module + +1 + Create the plugin directory -Create the plugin directory, with a `.claude-plugin/` folder inside it to hold the manifest: - - mkdir -p my-first-plugin/.claude-plugin +Create the two directories that hold the files: + + * Bash or Zsh + + * PowerShell + + mkdir -p first-mod/.claude-plugin first-mod/hooks + + New-Item -ItemType Directory -Force first-mod\.claude-plugin, first-mod\hooks 2 Write the manifest -The [manifest](</docs/en/plugins/manifest-reference>) is a JSON file named `plugin.json` that tells Claude Code the plugin’s name and describes it. Save this one as `my-first-plugin/.claude-plugin/plugin.json`: - -my-first-plugin/.claude-plugin/plugin.json +A mod is a plugin, and a mod needs a [manifest](</docs/en/plugins/manifest-reference>). This mod’s manifest has no special fields. Save this as `first-mod/.claude-plugin/plugin.json`: + +first-mod/.claude-plugin/plugin.json { - "name": "my-first-plugin", - "description": "A greeting plugin to learn the basics", - "version": "1.0.0", - "author": { - "name": "Your Name" - } + "name": "first-mod", + "version": "0.1.0", + "description": "Counts Claude's tool calls, shows the count beside the spinner, and adds a /tally command", + "author": { "name": "Your Name" } } -The four fields do this: - - * **`name`** : required. It identifies the plugin and becomes the prefix on every skill and agent the plugin provides. Don’t put spaces in it. - * **`description`** : the text users see for the plugin in `/plugin`. - * **`version`** : optional. Setting it keeps users on that version until you change it; [Release a new version](</docs/en/plugins/host-marketplace#release-a-new-version>) says when to set or omit it. - * **`author`** : who to credit. `name` is required inside it; `email` and `url` are optional. - -Other fields are on the [manifest reference](</docs/en/plugins/manifest-reference#fields>).Only `plugin.json` goes inside `.claude-plugin/`. The skill you add next goes directly under `my-first-plugin/`, next to that folder. - 3 -Add a skill - -This plugin’s one component is a skill. Each skill is a directory under `skills/` that contains a `SKILL.md` file. Create the skill’s directory: - - mkdir -p my-first-plugin/skills/hello - -Then create `my-first-plugin/skills/hello/SKILL.md` with this content: - -my-first-plugin/skills/hello/SKILL.md - - --- - name: hello - description: Greet the user with a friendly message - disable-model-invocation: true - --- - - Greet the user warmly and ask how you can help them today. - -The `disable-model-invocation: true` line means Claude doesn’t run the skill on its own. Remove that line from a skill you want Claude to run on its own. The skill’s command combines the plugin name and the skill’s name, so you run this one as `/my-first-plugin:hello`. For the other frontmatter fields, see the [skill frontmatter reference](</docs/en/skills#frontmatter-reference>). +Tell Claude Code where your code is + +When Claude Code loads a plugin, it reads the plugin’s `hooks/hooks.json`. The `modules` key in that file gives the path to your code, and having it is what makes the plugin a mod. List one path, relative to `hooks.json`. Here it points to `register.js`, which you write in the next step.Save this as `first-mod/hooks/hooks.json`: + +first-mod/hooks/hooks.json + + { + "description": "The first-mod hooks module", + "modules": ["./register.js"] + } 4 -Validate the plugin - -Check the manifest and the skill’s frontmatter before you run anything: - - claude plugin validate ./my-first-plugin - -The command prints the manifest path it checked and `✔ Validation passed`. If it prints `✘ Validation failed` instead, each line above that result line names the field to fix. Look up each message under [`claude plugin validate` reports errors](</docs/en/plugins/troubleshooting#claude-plugin-validate-reports-errors>). +Write the code + +This file is the mod’s code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](</docs/en/plugins/mods/reference#the-hook-function>). Each call to `on` registers an event handler, called a hook, for the event it names.Save this as `first-mod/hooks/register.js`: + +first-mod/hooks/register.js + + // The count, shared by the hooks below + let calls = 0 + + // Claude Code calls this once when the mod loads + export function register(on) { + // Runs when the session starts, before your first prompt + on('session.start', async ($, e, next) => { + // Add the /tally command + await $.command.register({ + name: 'tally', + description: 'Show how many tool calls Claude has made', + }) + // Let the session start as usual + return next(e) + }) + + // Runs each time Claude is about to use a tool + on('tool.call', async ($, e, next) => { + calls += 1 + // Ask Claude Code to draw the interface again, so the new count shows + $.ui.invalidate('ui.render') + // Let the tool run as usual + return next(e) + }) + + // Runs when you type /tally, and only then, because of the matcher + on('command.run', { command: 'tally' }, async () => { + // The text to print in the transcript + return { text: 'Claude has made ' + calls + ' tool calls since this mod loaded' } + }) + + // Runs each time Claude Code draws the spinner + on('ui.render', { component: 'Spinner' }, async ($, e, next) => { + // Keep Claude Code's spinner, with the count added after its word + return next({ ...e, props: { ...e.props, suffix: ' · tool calls: ' + calls + '…' } }) + }) + } + +The file keeps a count in `calls` and registers four hooks: + + * **[`session.start`](</docs/en/plugins/mods/reference#session>)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code. + * **[`tool.call`](</docs/en/plugins/mods/reference#tools>)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again. + * **[`command.run`](</docs/en/plugins/mods/reference#commands-and-configuration>)** runs when you type `/tally`. It returns the text to print. + * **[`ui.render`](</docs/en/plugins/mods/reference#interface>)** runs each time Claude Code draws the spinner. It adds the count after the spinner’s word. + +How the example mod works explains the three arguments each hook takes and what each one returns. 5 -Run Claude Code with the plugin - -Start a session with the plugin loaded: - - claude --plugin-dir ./my-first-plugin - -Once Claude Code starts, run the skill: - - /my-first-plugin:hello - -Claude replies with a greeting. - -The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. To have Claude scaffold and check a larger plugin with you, [install](</docs/en/plugins/install#install-a-plugin>) Anthropic’s `plugin-dev` plugin from the `claude-plugins-official` marketplace, which adds skills and agents for writing components such as skills, hooks, and MCP servers and for validating the finished plugin. Once it’s installed, run `/plugin-dev:create-plugin` followed by a description of the plugin you want, and Claude walks you through designing, creating, and validating it. - -### Share your plugin - -A plugin you built with Create your first plugin exists only on your machine. When it’s ready for other people, there are three ways to get it to them: - - * **Send it to a few people directly** : give them the plugin’s directory or a `.zip` of it, and nothing needs to be published. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>). - * **List it in your own marketplace** : teammates add your marketplace once and install the plugin by name, and they receive your updates. See [Publish through your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>). - * **Submit it to Anthropic’s directory** : after it passes review, people can add it on claude.ai and in Cowork, and it reaches Claude Code through their account. See [Submit to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>). - -### Plugin layout - -Each kind of [component](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, goes in a fixed directory under the plugin root, which is the directory you pass to `--plugin-dir`. Add only the directories you use. To click through a complete plugin directory and read what each file does, open the [plugin explorer](</docs/en/plugins/components#explore-the-plugin-directory>). The table lists the directories most plugins start with, and the [full layout](</docs/en/plugins/manifest-reference#standard-layout>) lists the rest. - -Location| Contents +Load the mod + +Start Claude Code with the `--plugin-dir` flag, which loads a plugin directory for one session without installing it: + + claude --plugin-dir ./first-mod + +6 + +Try the mod + +Ask Claude to do something that takes a few tool calls, such as `list the files here and read the README`. While Claude works, the spinner’s word is followed by a count that rises, as in `Thinking · tool calls: 2…`. When Claude finishes, type `/tally` and press Enter. The transcript shows `first-mod: Claude has made 2 tool calls since this mod loaded`, with your own count. Claude Code puts the plugin’s name in front of the command’s text.To check the command without an interactive session, run it in non-interactive mode: + + claude -p "/tally" --plugin-dir ./first-mod + + first-mod: Claude has made 0 tool calls since this mod loaded + +If `/tally` isn’t in the command list, the module didn’t load. See [Find out why a mod does nothing](</docs/en/plugins/mods/troubleshoot#find-out-why-a-mod-does-nothing>). + +7 + +Change the code while the session runs + +Leave the session open. In `register.js`, change `' · tool calls: '` to `' · tools used: '` in the `ui.render` hook and save. The highlighted line is the one that changes: + +first-mod/hooks/register.js + + // Runs each time Claude Code draws the spinner + on('ui.render', { component: 'Spinner' }, async ($, e, next) => { + // Keep Claude Code's spinner, with the count added after its word + return next({ ...e, props: { ...e.props, suffix: ' · tools used: ' + calls + '…' } }) + }) + +A line in the transcript says `first-mod` reloaded and lists its hooks, and the next spinner uses the new text, as in `Thinking · tools used: 1…`. + +### How the example mod works + +Each function you pass to `on` is a hook, which is an event handler. Claude Code passes every hook the same three arguments: + + * **The mods API** , named `$`: every method a mod can call to reach outside itself, in [namespaces](</docs/en/plugins/mods/reference#mods-api-methods>) such as `$.ui` and `$.command` + * **The event** , named `e`: the [event’s input](</docs/en/plugins/mods/reference#events>) as plain data, such as a tool call’s name and arguments + * **The next handler** , named [`next`](</docs/en/plugins/mods/events#how-a-hook-handles-an-event>): a function that passes the event on to the other mods and then to Claude Code’s own behavior, and returns the result + +The hooks in `first-mod` handle their events in these ways: + + * **Observe** : the `session.start` hook registers the command, and the `tool.call` hook counts the call and asks for a redraw. Both return `next(e)`, so the session starts and the tool runs as usual. + * **Answer** : the `command.run` hook returns its own result and never calls `next`. The second argument to `on`, `{ command: 'tally' }`, is a filter, called a [matcher](</docs/en/plugins/mods/events#filter-which-events-a-hook-handles>), so the hook runs only for `/tally`. + * **Rewrite** : the `ui.render` hook calls `next` with a copy of `e` whose `suffix` holds the count, so Claude Code draws its usual spinner with your text after the word + +Claude Code watches a directory loaded with `--plugin-dir` and hot-reloads the hooks module when a file in it changes. Each reload runs `register` again, so `calls` resets to `0` and `/tally` starts counting again. To keep a value across reloads, see [Keep state](</docs/en/plugins/mods/interface#keep-state>). + +## Keep working on a mod + +Once a mod loads, you can have Claude change it, check your code against the type definitions for your version, list the events and calls Claude Code finds in it, and test it. + +### Change a mod with Claude + +To change a mod you already have, start the session with `--plugin-dir` pointed at the mod’s directory, so that what Claude writes loads in the same session: + + claude --plugin-dir ./first-mod + +Then ask for the change, for example `add a /tally-reset command to this mod that sets the tally back to zero`. Claude edits the hooks module, runs `claude plugin validate`, and fixes what it reports. A directory you load with `--plugin-dir` is a [protected path](</docs/en/permission-modes#protected-paths>), so in `default` and `acceptEdits` modes you’re asked to approve each of Claude’s edits to the mod. The protected paths table gives the result for the other permission modes. Files Claude saves during its turn reload when the turn ends, so you can try `/tally-reset` as soon as Claude finishes. + +### Get type definitions for your version + +When Claude Code loads a mod from `--plugin-dir` in an interactive session, or a mod Claude wrote for you, it writes TypeScript declaration files into the mod’s `.claude-plugin/types/` directory. They describe the exact events, mods API methods, and elements in the Claude Code version you’re running, so your editor can autocomplete and type-check your hooks. The directory holds these files: + +Path| What it declares ---|--- -`.claude-plugin/plugin.json`| The manifest. When you load a plugin with `--plugin-dir` and it has no manifest, Claude Code names the plugin after its directory -`skills/`| One `<name>/SKILL.md` directory per skill -`commands/`| Flat Markdown files, the older form of skills. Use `skills/` for new plugins -`agents/`| One Markdown file per subagent -`hooks/hooks.json`| Hook configuration: a top-level `"hooks"` key whose value has the same shape as `hooks` in a settings file -`.mcp.json`| MCP server definitions - -Only `plugin.json` goes inside `.claude-plugin/`. Components saved there don’t load.The plugin root is the plugin’s own directory, not `~/.claude/` itself. A `.mcp.json` saved at `~/.claude/.mcp.json` doesn’t load. - -## Develop without a marketplace - -You don’t need a [marketplace](</docs/en/plugins/overview#get-plugins-from-a-marketplace>) to run a plugin you’re writing. Load it directly from disk or a URL instead: - - * `--plugin-dir`: loads a directory or `.zip` archive for one session. - * `--plugin-url`: fetches a `.zip` archive from a URL for one session. - * `claude plugin init`: scaffolds a plugin under `~/.claude/skills/` that loads across sessions. - -If two plugins loaded in different ways share a name, see [Name conflicts](</docs/en/plugins/loading#name-conflicts>) for which one Claude Code keeps. - -### Load a plugin for one session - -You can load a plugin for a single session in three ways: - - * From a directory or `.zip` archive on disk with `--plugin-dir` - * From a URL with `--plugin-url` - * From an environment variable when you can’t add a flag - -When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. - -#### Load a plugin from a directory or `.zip` - -When you start `claude` from your shell, pass `--plugin-dir` with the plugin’s root directory or a `.zip` archive of it. Repeat the flag to load several plugins: - - claude --plugin-dir ./my-first-plugin --plugin-dir ./other-plugin.zip - -#### Load a folder of plugins - -To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. You can also pass a folder that keeps a `.claude-plugin/marketplace.json` beside its plugin folders. As long as that `.claude-plugin/` directory holds no `plugin.json`, the plugin folders still load. Nothing is installed or enabled from the marketplace file, because Claude Code doesn’t read it. Loading plugins from such a folder requires Claude Code v2.1.281 or later. In an interactive session, you can also add and remove plugins in the folder after startup: - - * A subfolder you add loads as a new plugin once its manifest exists. - * When you remove a subfolder, its plugin unloads. - -A message appears in the session for each of these changes. If loading or unloading a plugin mid-conversation would [invalidate the prompt cache](</docs/en/prompt-caching#enabling-or-disabling-a-plugin>), the change is held instead, and the message tells you to run `/reload-plugins` to apply it. - -#### Load a plugin from a URL - -When you start `claude` from your shell, pass `--plugin-url` with the address of a `.zip` archive, such as a build artifact your CI publishes: - - claude --plugin-url https://example.com/my-first-plugin.zip - -Claude Code downloads the archive at startup. To load several, repeat the flag or pass the URLs space-separated in one quoted argument. Point the flag only at archives you control or trust. If Claude Code can’t fetch the archive, or the archive is invalid, it starts without the plugin and records a plugin load error that you can review in the `/plugin` manager’s **Errors** tab. - -#### Load plugins from an environment variable - -To load plugins in a session where you can’t add the `--plugin-dir` flag, list their absolute paths in the [`CLAUDE_CODE_PLUGIN_DIRS`](</docs/en/env-vars#variables>) environment variable instead. Claude Code loads each path as it loads a `--plugin-dir` path. These plugins load in addition to any you pass with `--plugin-dir`. [Project and local settings can’t set this variable](</docs/en/settings-reference#variables-claude-code-ignores-in-env>). `CLAUDE_CODE_PLUGIN_DIRS` requires Claude Code v2.1.280 or later. Managed settings can turn off `--plugin-dir` and `CLAUDE_CODE_PLUGIN_DIRS`. See [Flags that load a plugin for one session](</docs/en/plugins/cli-reference#flags-that-load-a-plugin-for-one-session>). To test a plugin together with a plugin it depends on, see [Test a plugin and its dependency locally](</docs/en/plugins/dependencies#test-a-plugin-and-its-dependency-locally>). - -### Make a plugin load in every session - -Your personal skills directory is `~/.claude/skills/`, and a folder there that contains a `.claude-plugin/plugin.json` is a skills-directory plugin. Unless your administrator has [blocked skills-directory plugins](</docs/en/plugins/loading#skills-directory-plugins-blocked-by-managed-settings>), Claude Code loads each one when a session starts, with no flag and no install step. `claude plugin init` scaffolds one for you. - -#### Scaffold the plugin with `claude plugin init` - -`claude plugin init` writes a starter plugin under `~/.claude/skills/`. Scaffold one from your shell: - - claude plugin init my-tool - -The command creates `~/.claude/skills/my-tool/` with a `.claude-plugin/plugin.json` and a root `SKILL.md`. It prints `✔ Created plugin "my-tool" at ~/.claude/skills/my-tool` followed by `It will auto-load next session as my-tool@skills-dir. Run /reload-plugins to load it now.` Pass `--with skills` to have `claude plugin init` scaffold a skill under `skills/` for you. The other `--with` values are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-init>). - -#### Name the plugin’s skills - -The root skill at `~/.claude/skills/my-tool/SKILL.md` is also a personal skill, so you invoke it as `/my-tool`, not `/my-tool:my-tool`. Skills you add under `skills/` inside the plugin get the plugin-name prefix, such as `/my-tool:example`. - -#### Stop loading the plugin - -To stop loading a scaffolded plugin, delete its directory, or run `claude plugin disable my-tool@skills-dir` in your shell with the `my-tool@skills-dir` name that `claude plugin init` printed. In the ID `my-tool@skills-dir`, `skills-dir` stands where a marketplace name would, because the plugin loads from your skills directory rather than from a marketplace. - -#### Share the plugin through a repository - -`claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, which all your projects on this machine share. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. - -## Test and debug - -When a change to your plugin doesn’t show up, work through these checks in order. Each one tells you what Claude Code did with the plugin: - - 1. In your shell, run `claude plugin validate <path>`. It checks the manifest and the frontmatter of every skill, agent, and command file, and exits `0` on `Validation passed`. Add `--strict` to fail on warnings too. Exit codes and directory handling are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-validate>). - 2. In the running session, run `/reload-plugins` to apply edits you made on disk. It prints one `Reloaded:` line with counts. Then confirm a skill loaded by typing its `/plugin-name:skill` command, or by finding the plugin in the `/plugin` **Installed** tab. - 3. In the same session, run `/plugin`. The **Installed** tab lists your plugin and, in the plugin’s details, the components Claude Code found. The **Errors** tab lists what failed to load and why, such as a path in your manifest that doesn’t exist. - 4. Back in your shell, run `claude plugin list`. It prints session-only and skills-directory plugins in their own sections with `Status: ✔ loaded` or the load error. To include the plugin you’re developing, pass `--plugin-dir` with its path before `plugin list`. - 5. If your plugin is in a skills directory and `claude plugin list` doesn’t print it, with no error there or in `/plugin`, see [Skills-directory plugins blocked by managed settings](</docs/en/plugins/loading#skills-directory-plugins-blocked-by-managed-settings>). - -To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, turn on debug logging as [Debug hooks](</docs/en/hooks#debug-hooks>) describes and trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the debug log. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. - -### A component path isn’t found - -The **Errors** tab of `/plugin` shows `<component> path not found: <path>`, for example `commands path not found`. A component path in your manifest, such as `commands`, `skills`, `agents`, or `hooks`, points at nothing. Fix the path or create the directory, then run `/reload-plugins` in the session. See [`commands path not found`](</docs/en/plugins/troubleshooting#commands-path-not-found>). - -### `--plugin-dir` at a marketplace root doesn’t load the plugins under `plugins/` - -`--plugin-dir` takes the plugin’s root directory, the one that contains `.claude-plugin/plugin.json` and the component directories such as `skills/`. If you point it at a marketplace root instead, Claude Code doesn’t read `marketplace.json`, so a plugin under `plugins/` doesn’t load, and you see no error. Point the flag at one plugin’s folder, or add the marketplace. See [the troubleshooting entry](</docs/en/plugins/troubleshooting#plugin-dir-loads-a-plugin-with-no-components>). - -### The plugin loads but its skills are missing - -The `skills/` directory is inside `.claude-plugin/`, or a `skills` entry in the manifest points at a file. Move `skills/` to the plugin root, point each `skills` entry at a directory that contains `SKILL.md`, and run `/reload-plugins` in the session. See [Plugin loads but its skills are missing](</docs/en/plugins/troubleshooting#plugin-loads-but-its-skills-are-missing>). - -### The `userConfig` dialog never appears - -The dialog for your plugin’s [`userConfig`](</docs/en/plugins/components#user-configuration>) options is part of installing through `/plugin` in a session. Loading with `--plugin-dir` doesn’t show it, and neither does `claude plugin install` in the shell. With the plugin loaded, run `/plugin configure <plugin-name>` in the session to open it. See [The `userConfig` dialog never appears](</docs/en/plugins/troubleshooting#the-userconfig-dialog-never-appears>). - -### Check that the plugin changes Claude’s behavior - -A plugin that loads without errors can still fail to steer Claude the way you intend. `claude plugin eval`, which you run in your shell, runs your test cases with and without the plugin and scores the difference. See [Test plugins with evals](</docs/en/plugin-evals>), starting with [Create your first eval suite](</docs/en/plugin-evals#create-your-first-eval-suite>). - -## Convert an existing `.claude/` setup - -If you already have skills, agents, or hooks under a project’s `.claude/` directory, you can move them into a plugin without rewriting them. Run the commands in these steps from the project root, which is the directory that contains `.claude/`, because the `cp` paths are relative to it. - -1 - -Create the plugin structure - -Create the plugin directory and its `.claude-plugin/` folder alongside `.claude/`. You can move the plugin anywhere afterwards. - - mkdir -p my-plugin/.claude-plugin - -Create `my-plugin/.claude-plugin/plugin.json`: - -my-plugin/.claude-plugin/plugin.json - - { - "name": "my-plugin", - "description": "Migrated from standalone configuration", - "version": "1.0.0" - } - -2 - -Copy your existing files - -Copy each configuration directory you have to the plugin root, and skip the command for any directory you don’t have. - - cp -r .claude/commands my-plugin/ - - cp -r .claude/agents my-plugin/ - - cp -r .claude/skills my-plugin/ - -Run `ls -a my-plugin` to confirm that each directory you copied appears next to `.claude-plugin`. - -3 - -Move your hooks - -If you have hooks in `.claude/settings.json` or `.claude/settings.local.json`, create a hooks directory: - - mkdir -p my-plugin/hooks - -Create `my-plugin/hooks/hooks.json` and copy the `hooks` object from your settings file into it. The format is the same.This example shows the shape with one hook that runs a linter on each file Claude writes or edits. Replace the example with your own `hooks` object. - -my-plugin/hooks/hooks.json - - { - "hooks": { - "PostToolUse": [ - { - "matcher": "Write|Edit", - "hooks": [{ "type": "command", "command": "f=$(jq -r '.tool_input.file_path') && npm run lint:fix -- \"$f\"" }] - } - ] - } - } - -4 - -Test the migrated plugin - -Load the plugin for a session: - - claude --plugin-dir ./my-plugin - -Check each component under its new name: - - * **Skills** : run `/my-plugin:deploy` for a skill that was `/deploy`. - * **Subagents** : ask Claude to use the `my-plugin:reviewer` agent for an agent that was `reviewer`. - * **Hooks** : trigger the event each hook matches. - -If something is missing, work through Test and debug. - -While the originals are still under `.claude/`, they stay loaded alongside the plugin’s copies: - - * **Skills and agents** : the two sets don’t collide, because the plugin’s skills and agents carry the `my-plugin:` prefix. `/deploy` and `/my-plugin:deploy` both work, and Claude sees `reviewer` and `my-plugin:reviewer` as two subagents. - * **Hooks** : hooks have no prefix, so a hook that is in both your settings file and `hooks/hooks.json` runs twice each time its event fires. - -After you’ve confirmed the plugin works, delete the originals from `.claude/` and remove the `hooks` object from your settings file. +`claude-code/index.d.ts`| Every event and its input and result, every mods API namespace and method, and the elements each surface can draw +`claude-code-tools/index.d.ts`| The built-in tools’ inputs and results, so that checking `e.tool === 'Bash'` narrows `e` +`claude-code-mcp/index.d.ts`| The inputs of the MCP tools that were connected the last time you saved a file in the mod +`index.d.ts` in a directory named for a plugin| What that plugin adds to the mods API. There’s one directory for each plugin your `plugin.json` lists under `dependencies`. +`tsconfig.json`| Compiler options that fit a hooks module + +If your mod has no `tsconfig.json` of its own, Claude Code adds one at the mod’s root that extends the generated one, so your editor and `tsc -p ./first-mod` type-check the mod without more setup. The events and methods can change between releases, so trust these files over any page, this one included, when they disagree. `claude-code/index.d.ts` is the fullest reference for your build, with a comment and an example for every mods API method. To look something up, search the file for its name, such as `'tool.call'`. + +### Check what Claude Code reads from your mod + +To see your mod the way Claude Code sees it, without running your code or starting a session, use `claude plugin validate`. It checks the manifest and runs the same static analysis on the hooks module’s source that Claude Code runs when it loads a mod. In your shell, run it on the mod’s directory: + + claude plugin validate ./first-mod + +For `first-mod`, the output includes these lines. + + ❯ ./register.js hooks: session.start, tool.call, command.run{command=tally}, ui.render{component=Spinner} + ❯ ./register.js calls: $.command.register, $.ui.invalidate + + ✔ Validation passed + +Check the `hooks:` line for the events your module hooks, each with its filter in braces, and `calls:` for every mods API method it calls. If your module reads or sets environment variables, look for `env reads:` and `env writes:` lines too, and `state reads:` and `state writes:` if it uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>). You also see one line for each hook that can refuse an action, such as `gating hook without .catch: tool.call`, which says whether that hook has a [`.catch` handler](</docs/en/plugins/mods/events#handle-a-hook-that-fails>). If an event you meant to handle is missing from the `hooks:` lines, Claude Code won’t call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`. Follow these rules so that static analysis can find every hook and call: + + * Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. You can pass `$` to a function declared at the top level of the same file, and for a function of yours named `loadNotes`, the `calls:` line then reads `$.store.get (via loadNotes)`. Passing `$` to a method, a function defined inside the hook, or a function you import from another of your files fails validation. The `read` and `update` functions that [`$.state`](</docs/en/plugins/mods/interface#keep-state>) uses are the imports that can take it. Don’t assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`. + * Write the event name in each `on` call as a string literal, such as `'tool.call'`. A variable, or a loop over a list of names, fails with `the event name passed to on() is not a string literal`. + * Inside `register`, don’t declare a second variable or parameter named `on`. Validation fails with `"on" is declared again (shadowed)`. + * Import only from files inside the plugin directory, by relative path. The one bare import allowed is `claude-code`, for types and a few helpers. + * Use `import` declarations at the top of the file, as in `import { name } from './file.js'`. A dynamic `import()` fails with `a dynamic import(); a hooks module imports its own files with an import declaration`. + * Write every file as an ES module, with `import` and not `require`. The [reference](</docs/en/plugins/mods/reference#files>) lists the file extensions Claude Code loads. + +### Test the mod + +You can write automated tests for a mod and run them from your shell with `claude plugin test`, with no session, sign-in, or network. A test fires the events your hooks handle and checks what the hooks did. This test fires two tool calls, runs `/tally`, and checks that the reply counts both. Save it as `first-mod/tests/first-mod.test.ts`: + +first-mod/tests/first-mod.test.ts + + import { expect, test } from 'claude-code/testing' + + test('/tally reports the tool calls the mod has seen', async ($, on) => { + // Answer each tool call in Claude Code's place, so no tool runs + on('tool.call', () => ({ result: 'ok' })) + + // Fire two tool calls, which the mod's tool.call hook counts + await $.tool.call({ tool: 'Bash', command: 'ls' }) + await $.tool.call({ tool: 'Read', file_path: 'README.md' }) + + // Run /tally and check the text its hook returns + const answer = await $.command.run({ command: 'tally', args: '' }) + expect(answer.text).toBe('Claude has made 2 tool calls since this mod loaded') + }) + +In your shell, run the tests from the `first-mod` directory: + + claude plugin test + +The output names each test and whether it passed, with timings that vary from run to run: + + tests/first-mod.test.ts: + (pass) /tally reports the tool calls the mod has seen [22.87ms] + + 1 pass + 0 fail + Ran 1 test across 1 file. [0.19s] + +[Test a mod](</docs/en/plugins/mods/test>) covers stubbing a model call or the store, and testing timers and drawings. + +## Share your mod + +A mod is a plugin, so you version it in the manifest and people install and update it with the `/plugin` commands. How you share it depends on who it’s for: + + * **A few people** : send them the plugin’s directory or a `.zip` of it. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>) + * **Your team** : list it in [your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>), such as a private repository with one directory for each plugin. To add that marketplace for everyone who works in a repository, [register it in the repository’s settings](</docs/en/plugins/host-marketplace#register-the-marketplace-for-everyone-in-a-repository>) + * **Your whole organization** : an administrator can [install your organization’s mods](</docs/en/plugins/mods/admin#install-your-organizations-mods>) through managed settings + * **Anyone** : make your marketplace’s repository public, or [submit the plugin to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>) + +Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don’t reach the installed copy until you increment the version and install again. ## Next steps - * [Plugin components](</docs/en/plugins/components>): add agents, hooks, MCP servers, LSP servers, and user configuration to your plugin - * [Test plugins with evals](</docs/en/plugin-evals>): write eval cases and run them with `claude plugin eval` to check how reliably the plugin guides Claude’s behavior - * [Publish a plugin](</docs/en/plugins/publish>): version it, put it in a marketplace, and submit it for review - * [Plugin structure and testing](<https://claude.com/docs/plugins/build>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only, and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) lists which load on each surface - * [Plugin manifest reference](</docs/en/plugins/manifest-reference>): every `plugin.json` field, path rule, and directory - * [Skills](</docs/en/skills>): write the skills your plugin provides - * [Anthropic’s plugins in the claude-plugins-official repository](<https://github.com/anthropics/claude-plugins-official/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review` + * [Draw in the interface](</docs/en/plugins/mods/interface>): open a pane, draw above the prompt, and add buttons and text fields + * [React to events](</docs/en/plugins/mods/events>): hook tool calls, prompts, and turns + * [Use the mods API](</docs/en/plugins/mods/api>): add commands and tools, call a model, and run work on a timer + * [Test a mod](</docs/en/plugins/mods/test>): stub what Claude Code would answer, and test timers and drawings + * [Troubleshoot a mod](</docs/en/plugins/mods/troubleshoot>): the reasons a mod does nothing, and the debug log + * [Read the source of built-in mods](</docs/en/plugins/mods/overview#read-the-source-of-built-in-mods>): complete plugins, each with its hooks module and tests
modified
--- a/create.md +++ b/create.md @@ -210,7 +210,7 @@ 4. Back in your shell, run `claude plugin list`. It prints session-only and skills-directory plugins in their own sections with `Status: ✔ loaded` or the load error. To include the plugin you’re developing, pass `--plugin-dir` with its path before `plugin list`. 5. If your plugin is in a skills directory and `claude plugin list` doesn’t print it, with no error there or in `/plugin`, see [Skills-directory plugins blocked by managed settings](</docs/en/plugins/loading#skills-directory-plugins-blocked-by-managed-settings>). -To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the [debug log](</docs/en/hooks#debug-hooks>), which shows which hooks matched, their exit codes, and their output. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. +To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, turn on debug logging as [Debug hooks](</docs/en/hooks#debug-hooks>) describes and trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the debug log. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. ### A component path isn’t found
modified
Show diff (277 lines)
--- a/create.md +++ b/create.md @@ -11,11 +11,7 @@ * **Nothing yet** : follow Create your first plugin, then Develop without a marketplace and Test and debug. * **Files under`.claude/` already**: do the first-plugin walkthrough once to learn the layout, then follow Convert an existing `.claude/` setup. -## - -​ - -Decide when to use a plugin +## Decide when to use a plugin Skills, agents, hooks, and MCP servers all work standalone in your project or home directory. Keep that standalone setup while it serves one project or only you. Make a plugin when you want to share the setup with teammates, install it in several projects, or publish versioned releases. When you move standalone skills, agents, hooks, and MCP config into a plugin, their location and names change: @@ -24,11 +20,7 @@ To move an existing setup into a plugin, see Convert an existing `.claude/` setup. -## - -​ - -Create your first plugin +## Create your first plugin In this walkthrough, you create a plugin whose only component is one skill, a greeting, and run it with `--plugin-dir`, which loads a plugin for one session without installing it. A plugin can hold any mix of [components](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, and none is required; one skill is the smallest example that shows the layout. You need Claude Code [installed and signed in](</docs/en/quickstart#step-1-install-claude-code>). Open a terminal in the directory where you want to keep the plugin, such as `~/projects`, and run the commands in these steps from it. You can keep a plugin anywhere, because you pass its path to Claude Code when you start a session. @@ -64,7 +56,7 @@ * **`version`** : optional. Setting it keeps users on that version until you change it; [Release a new version](</docs/en/plugins/host-marketplace#release-a-new-version>) says when to set or omit it. * **`author`** : who to credit. `name` is required inside it; `email` and `url` are optional. -Every other field is on the [manifest reference](</docs/en/plugins/manifest-reference#fields>).Only `plugin.json` goes inside `.claude-plugin/`. The skill you add next goes directly under `my-first-plugin/`, next to that folder. +Other fields are on the [manifest reference](</docs/en/plugins/manifest-reference#fields>).Only `plugin.json` goes inside `.claude-plugin/`. The skill you add next goes directly under `my-first-plugin/`, next to that folder. 3 @@ -114,11 +106,7 @@ The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. To have Claude scaffold and check a larger plugin with you, [install](</docs/en/plugins/install#install-a-plugin>) Anthropic’s `plugin-dev` plugin from the `claude-plugins-official` marketplace, which adds skills and agents for writing components such as skills, hooks, and MCP servers and for validating the finished plugin. Once it’s installed, run `/plugin-dev:create-plugin` followed by a description of the plugin you want, and Claude walks you through designing, creating, and validating it. -### - -​ - -Share your plugin +### Share your plugin A plugin you built with Create your first plugin exists only on your machine. When it’s ready for other people, there are three ways to get it to them: @@ -126,11 +114,7 @@ * **List it in your own marketplace** : teammates add your marketplace once and install the plugin by name, and they receive your updates. See [Publish through your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>). * **Submit it to Anthropic’s directory** : after it passes review, people can add it on claude.ai and in Cowork, and it reaches Claude Code through their account. See [Submit to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>). -### - -​ - -Plugin layout +### Plugin layout Each kind of [component](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, goes in a fixed directory under the plugin root, which is the directory you pass to `--plugin-dir`. Add only the directories you use. To click through a complete plugin directory and read what each file does, open the [plugin explorer](</docs/en/plugins/components#explore-the-plugin-directory>). The table lists the directories most plugins start with, and the [full layout](</docs/en/plugins/manifest-reference#standard-layout>) lists the rest. @@ -145,11 +129,7 @@ Only `plugin.json` goes inside `.claude-plugin/`. Components saved there don’t load.The plugin root is the plugin’s own directory, not `~/.claude/` itself. A `.mcp.json` saved at `~/.claude/.mcp.json` doesn’t load. -## - -​ - -Develop without a marketplace +## Develop without a marketplace You don’t need a [marketplace](</docs/en/plugins/overview#get-plugins-from-a-marketplace>) to run a plugin you’re writing. Load it directly from disk or a URL instead: @@ -159,11 +139,7 @@ If two plugins loaded in different ways share a name, see [Name conflicts](</docs/en/plugins/loading#name-conflicts>) for which one Claude Code keeps. -### - -​ - -Load a plugin for one session +### Load a plugin for one session You can load a plugin for a single session in three ways: @@ -173,21 +149,13 @@ When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. -#### - -​ - -Load a plugin from a directory or `.zip` +#### Load a plugin from a directory or `.zip` When you start `claude` from your shell, pass `--plugin-dir` with the plugin’s root directory or a `.zip` archive of it. Repeat the flag to load several plugins: claude --plugin-dir ./my-first-plugin --plugin-dir ./other-plugin.zip -#### - -​ - -Load a folder of plugins +#### Load a folder of plugins To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. You can also pass a folder that keeps a `.claude-plugin/marketplace.json` beside its plugin folders. As long as that `.claude-plugin/` directory holds no `plugin.json`, the plugin folders still load. Nothing is installed or enabled from the marketplace file, because Claude Code doesn’t read it. Loading plugins from such a folder requires Claude Code v2.1.281 or later. In an interactive session, you can also add and remove plugins in the folder after startup: @@ -196,11 +164,7 @@ A message appears in the session for each of these changes. If loading or unloading a plugin mid-conversation would [invalidate the prompt cache](</docs/en/prompt-caching#enabling-or-disabling-a-plugin>), the change is held instead, and the message tells you to run `/reload-plugins` to apply it. -#### - -​ - -Load a plugin from a URL +#### Load a plugin from a URL When you start `claude` from your shell, pass `--plugin-url` with the address of a `.zip` archive, such as a build artifact your CI publishes: @@ -208,27 +172,15 @@ Claude Code downloads the archive at startup. To load several, repeat the flag or pass the URLs space-separated in one quoted argument. Point the flag only at archives you control or trust. If Claude Code can’t fetch the archive, or the archive is invalid, it starts without the plugin and records a plugin load error that you can review in the `/plugin` manager’s **Errors** tab. -#### - -​ - -Load plugins from an environment variable +#### Load plugins from an environment variable To load plugins in a session where you can’t add the `--plugin-dir` flag, list their absolute paths in the [`CLAUDE_CODE_PLUGIN_DIRS`](</docs/en/env-vars#variables>) environment variable instead. Claude Code loads each path as it loads a `--plugin-dir` path. These plugins load in addition to any you pass with `--plugin-dir`. [Project and local settings can’t set this variable](</docs/en/settings-reference#variables-claude-code-ignores-in-env>). `CLAUDE_CODE_PLUGIN_DIRS` requires Claude Code v2.1.280 or later. Managed settings can turn off `--plugin-dir` and `CLAUDE_CODE_PLUGIN_DIRS`. See [Flags that load a plugin for one session](</docs/en/plugins/cli-reference#flags-that-load-a-plugin-for-one-session>). To test a plugin together with a plugin it depends on, see [Test a plugin and its dependency locally](</docs/en/plugins/dependencies#test-a-plugin-and-its-dependency-locally>). -### - -​ - -Make a plugin load in every session +### Make a plugin load in every session Your personal skills directory is `~/.claude/skills/`, and a folder there that contains a `.claude-plugin/plugin.json` is a skills-directory plugin. Unless your administrator has [blocked skills-directory plugins](</docs/en/plugins/loading#skills-directory-plugins-blocked-by-managed-settings>), Claude Code loads each one when a session starts, with no flag and no install step. `claude plugin init` scaffolds one for you. -#### - -​ - -Scaffold the plugin with `claude plugin init` +#### Scaffold the plugin with `claude plugin init` `claude plugin init` writes a starter plugin under `~/.claude/skills/`. Scaffold one from your shell: @@ -236,35 +188,19 @@ The command creates `~/.claude/skills/my-tool/` with a `.claude-plugin/plugin.json` and a root `SKILL.md`. It prints `✔ Created plugin "my-tool" at ~/.claude/skills/my-tool` followed by `It will auto-load next session as my-tool@skills-dir. Run /reload-plugins to load it now.` Pass `--with skills` to have `claude plugin init` scaffold a skill under `skills/` for you. The other `--with` values are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-init>). -#### - -​ - -Name the plugin’s skills +#### Name the plugin’s skills The root skill at `~/.claude/skills/my-tool/SKILL.md` is also a personal skill, so you invoke it as `/my-tool`, not `/my-tool:my-tool`. Skills you add under `skills/` inside the plugin get the plugin-name prefix, such as `/my-tool:example`. -#### - -​ - -Stop loading the plugin +#### Stop loading the plugin To stop loading a scaffolded plugin, delete its directory, or run `claude plugin disable my-tool@skills-dir` in your shell with the `my-tool@skills-dir` name that `claude plugin init` printed. In the ID `my-tool@skills-dir`, `skills-dir` stands where a marketplace name would, because the plugin loads from your skills directory rather than from a marketplace. -#### - -​ - -Share the plugin through a repository +#### Share the plugin through a repository `claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, which all your projects on this machine share. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. -## - -​ - -Test and debug +## Test and debug When a change to your plugin doesn’t show up, work through these checks in order. Each one tells you what Claude Code did with the plugin: @@ -276,51 +212,27 @@ To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the [debug log](</docs/en/hooks#debug-hooks>), which shows which hooks matched, their exit codes, and their output. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. -### - -​ - -A component path isn’t found +### A component path isn’t found The **Errors** tab of `/plugin` shows `<component> path not found: <path>`, for example `commands path not found`. A component path in your manifest, such as `commands`, `skills`, `agents`, or `hooks`, points at nothing. Fix the path or create the directory, then run `/reload-plugins` in the session. See [`commands path not found`](</docs/en/plugins/troubleshooting#commands-path-not-found>). -### - -​ - -`--plugin-dir` at a marketplace root doesn’t load the plugins under `plugins/` +### `--plugin-dir` at a marketplace root doesn’t load the plugins under `plugins/` `--plugin-dir` takes the plugin’s root directory, the one that contains `.claude-plugin/plugin.json` and the component directories such as `skills/`. If you point it at a marketplace root instead, Claude Code doesn’t read `marketplace.json`, so a plugin under `plugins/` doesn’t load, and you see no error. Point the flag at one plugin’s folder, or add the marketplace. See [the troubleshooting entry](</docs/en/plugins/troubleshooting#plugin-dir-loads-a-plugin-with-no-components>). -### - -​ - -The plugin loads but its skills are missing +### The plugin loads but its skills are missing The `skills/` directory is inside `.claude-plugin/`, or a `skills` entry in the manifest points at a file. Move `skills/` to the plugin root, point each `skills` entry at a directory that contains `SKILL.md`, and run `/reload-plugins` in the session. See [Plugin loads but its skills are missing](</docs/en/plugins/troubleshooting#plugin-loads-but-its-skills-are-missing>). -### - -​ - -The `userConfig` dialog never appears +### The `userConfig` dialog never appears The dialog for your plugin’s [`userConfig`](</docs/en/plugins/components#user-configuration>) options is part of installing through `/plugin` in a session. Loading with `--plugin-dir` doesn’t show it, and neither does `claude plugin install` in the shell. With the plugin loaded, run `/plugin configure <plugin-name>` in the session to open it. See [The `userConfig` dialog never appears](</docs/en/plugins/troubleshooting#the-userconfig-dialog-never-appears>). -### - -​ - -Check that the plugin changes Claude’s behavior +### Check that the plugin changes Claude’s behavior A plugin that loads without errors can still fail to steer Claude the way you intend. `claude plugin eval`, which you run in your shell, runs your test cases with and without the plugin and scores the difference. See [Test plugins with evals](</docs/en/plugin-evals>), starting with [Create your first eval suite](</docs/en/plugin-evals#create-your-first-eval-suite>). -## - -​ - -Convert an existing `.claude/` setup +## Convert an existing `.claude/` setup If you already have skills, agents, or hooks under a project’s `.claude/` directory, you can move them into a plugin without rewriting them. Run the commands in these steps from the project root, which is the directory that contains `.claude/`, because the `cp` paths are relative to it. @@ -373,7 +285,7 @@ "PostToolUse": [ { "matcher": "Write|Edit", - "hooks": [{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npm run lint:fix" }] + "hooks": [{ "type": "command", "command": "f=$(jq -r '.tool_input.file_path') && npm run lint:fix -- \"$f\"" }] } ] } @@ -402,11 +314,7 @@ After you’ve confirmed the plugin works, delete the originals from `.claude/` and remove the `hooks` object from your settings file. -## - -​ - -Next steps +## Next steps * [Plugin components](</docs/en/plugins/components>): add agents, hooks, MCP servers, LSP servers, and user configuration to your plugin * [Test plugins with evals](</docs/en/plugin-evals>): write eval cases and run them with `claude plugin eval` to check how reliably the plugin guides Claude’s behavior
modified
--- a/create.md +++ b/create.md @@ -165,7 +165,13 @@ Load a plugin for one session -You can load a plugin for a single session in three ways: from a directory or `.zip` archive on disk with `--plugin-dir`, from a URL with `--plugin-url`, or from an environment variable when you can’t add a flag. Each plugin loads for that session only, and nothing is written to your settings for it. When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. +You can load a plugin for a single session in three ways: + + * From a directory or `.zip` archive on disk with `--plugin-dir` + * From a URL with `--plugin-url` + * From an environment variable when you can’t add a flag + +When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. ####
modified
--- a/create.md +++ b/create.md @@ -408,4 +408,4 @@ * [Plugin structure and testing](<https://claude.com/docs/plugins/build>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only, and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) lists which load on each surface * [Plugin manifest reference](</docs/en/plugins/manifest-reference>): every `plugin.json` field, path rule, and directory * [Skills](</docs/en/skills>): write the skills your plugin provides - * [Anthropic’s plugins in the claude-code repository](<https://github.com/anthropics/claude-code/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review` + * [Anthropic’s plugins in the claude-plugins-official repository](<https://github.com/anthropics/claude-plugins-official/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review`
modified
--- a/create.md +++ b/create.md @@ -155,7 +155,7 @@ * `--plugin-dir`: loads a directory or `.zip` archive for one session. * `--plugin-url`: fetches a `.zip` archive from a URL for one session. - * `claude plugin init`: scaffolds a plugin under `~/.claude/skills/` that loads every session. + * `claude plugin init`: scaffolds a plugin under `~/.claude/skills/` that loads across sessions. If two plugins loaded in different ways share a name, see [Name conflicts](</docs/en/plugins/loading#name-conflicts>) for which one Claude Code keeps. @@ -216,7 +216,7 @@ Make a plugin load in every session -Your personal skills directory is `~/.claude/skills/`. Claude Code loads any folder there that contains a `.claude-plugin/plugin.json` as a plugin in every session, with no flag and no install step. `claude plugin init` scaffolds one of these plugins for you. +Your personal skills directory is `~/.claude/skills/`, and a folder there that contains a `.claude-plugin/plugin.json` is a skills-directory plugin. Unless your administrator has [blocked skills-directory plugins](</docs/en/plugins/loading#skills-directory-plugins-blocked-by-managed-settings>), Claude Code loads each one when a session starts, with no flag and no install step. `claude plugin init` scaffolds one for you. #### @@ -252,7 +252,7 @@ Share the plugin through a repository -`claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, so it loads for you in every project. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. +`claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, which all your projects on this machine share. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. ## @@ -266,6 +266,7 @@ 2. In the running session, run `/reload-plugins` to apply edits you made on disk. It prints one `Reloaded:` line with counts. Then confirm a skill loaded by typing its `/plugin-name:skill` command, or by finding the plugin in the `/plugin` **Installed** tab. 3. In the same session, run `/plugin`. The **Installed** tab lists your plugin and, in the plugin’s details, the components Claude Code found. The **Errors** tab lists what failed to load and why, such as a path in your manifest that doesn’t exist. 4. Back in your shell, run `claude plugin list`. It prints session-only and skills-directory plugins in their own sections with `Status: ✔ loaded` or the load error. To include the plugin you’re developing, pass `--plugin-dir` with its path before `plugin list`. + 5. If your plugin is in a skills directory and `claude plugin list` doesn’t print it, with no error there or in `/plugin`, see [Skills-directory plugins blocked by managed settings](</docs/en/plugins/loading#skills-directory-plugins-blocked-by-managed-settings>). To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the [debug log](</docs/en/hooks#debug-hooks>), which shows which hooks matched, their exit codes, and their output. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each.
modified
--- a/create.md +++ b/create.md @@ -171,7 +171,7 @@ ​ -From a directory or `.zip` +Load a plugin from a directory or `.zip` When you start `claude` from your shell, pass `--plugin-dir` with the plugin’s root directory or a `.zip` archive of it. Repeat the flag to load several plugins: @@ -181,7 +181,7 @@ ​ -From a folder of plugins +Load a folder of plugins To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. You can also pass a folder that keeps a `.claude-plugin/marketplace.json` beside its plugin folders. As long as that `.claude-plugin/` directory holds no `plugin.json`, the plugin folders still load. Nothing is installed or enabled from the marketplace file, because Claude Code doesn’t read it. Loading plugins from such a folder requires Claude Code v2.1.281 or later. In an interactive session, you can also add and remove plugins in the folder after startup: @@ -194,7 +194,7 @@ ​ -From a URL +Load a plugin from a URL When you start `claude` from your shell, pass `--plugin-url` with the address of a `.zip` archive, such as a build artifact your CI publishes: @@ -206,7 +206,7 @@ ​ -From an environment variable +Load plugins from an environment variable To load plugins in a session where you can’t add the `--plugin-dir` flag, list their absolute paths in the [`CLAUDE_CODE_PLUGIN_DIRS`](</docs/en/env-vars#variables>) environment variable instead. Claude Code loads each path as it loads a `--plugin-dir` path. These plugins load in addition to any you pass with `--plugin-dir`. [Project and local settings can’t set this variable](</docs/en/settings-reference#variables-claude-code-ignores-in-env>). `CLAUDE_CODE_PLUGIN_DIRS` requires Claude Code v2.1.280 or later. Managed settings can turn off `--plugin-dir` and `CLAUDE_CODE_PLUGIN_DIRS`. See [Flags that load a plugin for one session](</docs/en/plugins/cli-reference#flags-that-load-a-plugin-for-one-session>). To test a plugin together with a plugin it depends on, see [Test a plugin and its dependency locally](</docs/en/plugins/dependencies#test-a-plugin-and-its-dependency-locally>).
modified
Show diff (756 lines)
--- a/create.md +++ b/create.md @@ -1,364 +1,399 @@ -A mod is a Claude Code [plugin](</docs/en/plugins/overview>) with an entry file, called the hooks module: a JavaScript or TypeScript file whose functions Claude Code calls when events happen. To make one: - - * **Ask Claude to write it** : describe what you want in a Claude Code session - * **Write it yourself** : follow the tutorial to learn how a mod’s code works. You don’t need Node.js, a bundler, or a build step, because Claude Code loads `.js` and `.ts` files directly. - -If you haven’t decided whether a mod is the right tool, read the [comparison on the overview](</docs/en/plugins/mods/overview#compare-mods-settings-hooks-skills-and-mcp-servers>) first. - -Use Claude Code v2.1.287 or later. In your shell, run `claude --version` to check. To see whether mods can load for you, see [Check whether mods can load](</docs/en/plugins/mods/troubleshoot#check-whether-mods-can-load>). - -## - -​ - -Ask Claude for a mod - -Describe the mod you want in an interactive Claude Code session, and Claude writes it. Claude works from a built-in [skill](</docs/en/skills>) named `plugin-authoring`, which tells it where to write the mod, which events and methods your version has, and how the mod gets loaded. Claude can load the skill when you ask for a mod, or you can load it yourself by running `/plugin-authoring` at the Claude Code prompt. The mod runs once you approve it, except in sessions where a mod Claude writes can’t load. +A plugin is a directory of skills, agents, hooks, and MCP servers, plus a `plugin.json` file, called the manifest, that names the plugin. Claude Code loads the directory as one unit, so you can share it with teammates, install it in several projects, or publish it to a marketplace. This page is for people writing their own plugins. + +These cases are covered on other pages: + + * **Installing someone else’s plugin** : see [Install plugins](</docs/en/plugins/install>) + * **Not sure you need a plugin** : see [Decide whether you need a plugin](</docs/en/plugins/overview#decide-whether-you-need-a-plugin>) on the overview + * **Your plugin’s users are on claude.ai or in Cowork** : the same folder installs there with a different subset of components. See [Plugin structure and testing](<https://claude.com/docs/plugins/build>) and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) + +Start from the section that matches what you already have: + + * **Nothing yet** : follow Create your first plugin, then Develop without a marketplace and Test and debug. + * **Files under`.claude/` already**: do the first-plugin walkthrough once to learn the layout, then follow Convert an existing `.claude/` setup. + +## + +​ + +Decide when to use a plugin + +Skills, agents, hooks, and MCP servers all work standalone in your project or home directory. Keep that standalone setup while it serves one project or only you. Make a plugin when you want to share the setup with teammates, install it in several projects, or publish versioned releases. When you move standalone skills, agents, hooks, and MCP config into a plugin, their location and names change: + + * **Where the files go** : under the plugin’s own directory, called the plugin root, as `skills/`, `agents/`, `hooks/hooks.json`, and `.mcp.json`. + * **How they’re named** : plugin skills and agents get the plugin name as a prefix, such as `/my-plugin:hello`, so two plugins can each provide a `hello` skill without colliding. + +To move an existing setup into a plugin, see Convert an existing `.claude/` setup. + +## + +​ + +Create your first plugin + +In this walkthrough, you create a plugin whose only component is one skill, a greeting, and run it with `--plugin-dir`, which loads a plugin for one session without installing it. A plugin can hold any mix of [components](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, and none is required; one skill is the smallest example that shows the layout. You need Claude Code [installed and signed in](</docs/en/quickstart#step-1-install-claude-code>). Open a terminal in the directory where you want to keep the plugin, such as `~/projects`, and run the commands in these steps from it. You can keep a plugin anywhere, because you pass its path to Claude Code when you start a session. 1 -Describe the mod - -Ask for the mod in your own words, for example `make a mod that shows the current git branch above the prompt`. Claude writes the mod in a directory of its own in the session’s mods folder, which is `~/.claude/dev-mods/` followed by the session’s ID. A mod’s full path looks like `~/.claude/dev-mods/3f2a9c1e-5b7d-4e8a-9c21-6d0f4b8a7e13/git-branch/`. - -In the `default` and `acceptEdits` [permission modes](</docs/en/permission-modes#protected-paths>), Claude Code asks before Claude creates each of the mod’s files, because `~/.claude` is a protected path. Approve each file as it comes up. +Create the plugin directory + +Create the plugin directory, with a `.claude-plugin/` folder inside it to hold the manifest: + + mkdir -p my-first-plugin/.claude-plugin 2 -Approve the mod - -When Claude saves the first file, Claude Code asks whether to enable hot reloading for the session. Hot reloading runs the mods Claude writes in this session and picks up each later change.Choose one of these answers: - - * **Enable for this session** : the mods in the session’s mods folder load when the turn ends, and reload at the end of each turn that changes them. Your answer lasts for the session, including after you resume it. - * **Not now** : nothing loads for now. The files stay where Claude wrote them, and the mods load the next time that session starts. To keep a mod from ever loading, delete its directory. +Write the manifest + +The [manifest](</docs/en/plugins/manifest-reference>) is a JSON file named `plugin.json` that tells Claude Code the plugin’s name and describes it. Save this one as `my-first-plugin/.claude-plugin/plugin.json`: + +my-first-plugin/.claude-plugin/plugin.json + + { + "name": "my-first-plugin", + "description": "A greeting plugin to learn the basics", + "version": "1.0.0", + "author": { + "name": "Your Name" + } + } + +The four fields do this: + + * **`name`** : required. It identifies the plugin and becomes the prefix on every skill and agent the plugin provides. Don’t put spaces in it. + * **`description`** : the text users see for the plugin in `/plugin`. + * **`version`** : optional. Setting it keeps users on that version until you change it; [Release a new version](</docs/en/plugins/host-marketplace#release-a-new-version>) says when to set or omit it. + * **`author`** : who to credit. `name` is required inside it; `email` and `url` are optional. + +Every other field is on the [manifest reference](</docs/en/plugins/manifest-reference#fields>).Only `plugin.json` goes inside `.claude-plugin/`. The skill you add next goes directly under `my-first-plugin/`, next to that folder. 3 -Check that the mod loaded - -Run `/plugin` at the Claude Code prompt and press Tab until the **Installed** tab is selected. It lists the mod, and you can turn it off there. +Add a skill + +This plugin’s one component is a skill. Each skill is a directory under `skills/` that contains a `SKILL.md` file. Create the skill’s directory: + + mkdir -p my-first-plugin/skills/hello + +Then create `my-first-plugin/skills/hello/SKILL.md` with this content: + +my-first-plugin/skills/hello/SKILL.md + + --- + name: hello + description: Greet the user with a friendly message + disable-model-invocation: true + --- + + Greet the user warmly and ask how you can help them today. + +The `disable-model-invocation: true` line means Claude doesn’t run the skill on its own. Remove that line from a skill you want Claude to run on its own. The skill’s command combines the plugin name and the skill’s name, so you run this one as `/my-first-plugin:hello`. For the other frontmatter fields, see the [skill frontmatter reference](</docs/en/skills#frontmatter-reference>). 4 -Try the mod - -Use what you asked for. For the example prompt, the current branch name appears above the prompt box. If the mod doesn’t do what you wanted, tell Claude what to change. The mod reloads at the end of each turn that changes its files, so you can try the change as soon as Claude finishes. - -### - -​ - -Use the mod in other sessions - -A mod Claude wrote loads only in the session that made it, and Claude Code deletes that session’s mods folder once it’s older than [`cleanupPeriodDays`](</docs/en/settings-reference#cleanupperioddays>). To keep the mod, copy its directory out of the mods folder to a place of your own, such as `~/mods/git-branch`. Then choose how to load it: - - * **In a session you start** : in your shell, run `claude --plugin-dir ~/mods/git-branch` - * **For other people** : add it to a marketplace so they can install it - -### - -​ - -Sessions where a mod Claude writes can’t load - -A mod Claude writes loads only after you approve it, in a trusted workspace where mods are allowed to run. In these sessions it doesn’t load: - - * **Nobody is there to approve** : the session can’t show you a prompt, as in a `claude -p` run or [`dontAsk` mode](</docs/en/permission-modes>) - * **The workspace isn’t trusted** : you haven’t accepted the trust prompt for the directory - * **Mods are disabled** : you started with `--safe-mode` or `--bare`, you set `disableAllHooks`, or your organization’s [managed settings block it](</docs/en/plugins/mods/admin#choose-how-much-to-allow>) - -## - -​ - -Write a mod yourself - -In this tutorial you build a mod named `first-mod` that counts the tool calls Claude makes, shows the count beside the spinner while Claude works, and adds a `/tally` command that prints it. You then read the type declarations Claude Code writes beside your mod and run `claude plugin validate`. Together they show you the events and methods your version offers and what Claude Code reads from your code. This recording shows the finished mod. The spinner counts tool calls, `/tally` prints the count, and an edit to the code takes effect while the session runs: - -You write three files: - - first-mod/ - ├── .claude-plugin/ - │ └── plugin.json - └── hooks/ - ├── hooks.json - └── register.js - - * **`plugin.json`** : the plugin’s [manifest](</docs/en/plugins/manifest-reference>) - * **`hooks.json`** : [points to your code file](</docs/en/plugins/mods/reference#files>) - * **`register.js`** : your code, called the hooks module +Validate the plugin + +Check the manifest and the skill’s frontmatter before you run anything: + + claude plugin validate ./my-first-plugin + +The command prints the manifest path it checked and `✔ Validation passed`. If it prints `✘ Validation failed` instead, each line above that result line names the field to fix. Look up each message under [`claude plugin validate` reports errors](</docs/en/plugins/troubleshooting#claude-plugin-validate-reports-errors>). + +5 + +Run Claude Code with the plugin + +Start a session with the plugin loaded: + + claude --plugin-dir ./my-first-plugin + +Once Claude Code starts, run the skill: + + /my-first-plugin:hello + +Claude replies with a greeting. + +The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. To have Claude scaffold and check a larger plugin with you, [install](</docs/en/plugins/install#install-a-plugin>) Anthropic’s `plugin-dev` plugin from the `claude-plugins-official` marketplace, which adds skills and agents for writing components such as skills, hooks, and MCP servers and for validating the finished plugin. Once it’s installed, run `/plugin-dev:create-plugin` followed by a description of the plugin you want, and Claude walks you through designing, creating, and validating it. + +### + +​ + +Share your plugin + +A plugin you built with Create your first plugin exists only on your machine. When it’s ready for other people, there are three ways to get it to them: + + * **Send it to a few people directly** : give them the plugin’s directory or a `.zip` of it, and nothing needs to be published. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>). + * **List it in your own marketplace** : teammates add your marketplace once and install the plugin by name, and they receive your updates. See [Publish through your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>). + * **Submit it to Anthropic’s directory** : after it passes review, people can add it on claude.ai and in Cowork, and it reaches Claude Code through their account. See [Submit to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>). + +### + +​ + +Plugin layout + +Each kind of [component](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, goes in a fixed directory under the plugin root, which is the directory you pass to `--plugin-dir`. Add only the directories you use. To click through a complete plugin directory and read what each file does, open the [plugin explorer](</docs/en/plugins/components#explore-the-plugin-directory>). The table lists the directories most plugins start with, and the [full layout](</docs/en/plugins/manifest-reference#standard-layout>) lists the rest. + +Location| Contents +---|--- +`.claude-plugin/plugin.json`| The manifest. When you load a plugin with `--plugin-dir` and it has no manifest, Claude Code names the plugin after its directory +`skills/`| One `<name>/SKILL.md` directory per skill +`commands/`| Flat Markdown files, the older form of skills. Use `skills/` for new plugins +`agents/`| One Markdown file per subagent +`hooks/hooks.json`| Hook configuration: a top-level `"hooks"` key whose value has the same shape as `hooks` in a settings file +`.mcp.json`| MCP server definitions + +Only `plugin.json` goes inside `.claude-plugin/`. Components saved there don’t load.The plugin root is the plugin’s own directory, not `~/.claude/` itself. A `.mcp.json` saved at `~/.claude/.mcp.json` doesn’t load. + +## + +​ + +Develop without a marketplace + +You don’t need a [marketplace](</docs/en/plugins/overview#get-plugins-from-a-marketplace>) to run a plugin you’re writing. Load it directly from disk or a URL instead: + + * `--plugin-dir`: loads a directory or `.zip` archive for one session. + * `--plugin-url`: fetches a `.zip` archive from a URL for one session. + * `claude plugin init`: scaffolds a plugin under `~/.claude/skills/` that loads every session. + +If two plugins loaded in different ways share a name, see [Name conflicts](</docs/en/plugins/loading#name-conflicts>) for which one Claude Code keeps. + +### + +​ + +Load a plugin for one session + +You can load a plugin for a single session in three ways: from a directory or `.zip` archive on disk with `--plugin-dir`, from a URL with `--plugin-url`, or from an environment variable when you can’t add a flag. Each plugin loads for that session only, and nothing is written to your settings for it. When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. + +#### + +​ + +From a directory or `.zip` + +When you start `claude` from your shell, pass `--plugin-dir` with the plugin’s root directory or a `.zip` archive of it. Repeat the flag to load several plugins: + + claude --plugin-dir ./my-first-plugin --plugin-dir ./other-plugin.zip + +#### + +​ + +From a folder of plugins + +To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. You can also pass a folder that keeps a `.claude-plugin/marketplace.json` beside its plugin folders. As long as that `.claude-plugin/` directory holds no `plugin.json`, the plugin folders still load. Nothing is installed or enabled from the marketplace file, because Claude Code doesn’t read it. Loading plugins from such a folder requires Claude Code v2.1.281 or later. In an interactive session, you can also add and remove plugins in the folder after startup: + + * A subfolder you add loads as a new plugin once its manifest exists. + * When you remove a subfolder, its plugin unloads. + +A message appears in the session for each of these changes. If loading or unloading a plugin mid-conversation would [invalidate the prompt cache](</docs/en/prompt-caching#enabling-or-disabling-a-plugin>), the change is held instead, and the message tells you to run `/reload-plugins` to apply it. + +#### + +​ + +From a URL + +When you start `claude` from your shell, pass `--plugin-url` with the address of a `.zip` archive, such as a build artifact your CI publishes: + + claude --plugin-url https://example.com/my-first-plugin.zip + +Claude Code downloads the archive at startup. To load several, repeat the flag or pass the URLs space-separated in one quoted argument. Point the flag only at archives you control or trust. If Claude Code can’t fetch the archive, or the archive is invalid, it starts without the plugin and records a plugin load error that you can review in the `/plugin` manager’s **Errors** tab. + +#### + +​ + +From an environment variable + +To load plugins in a session where you can’t add the `--plugin-dir` flag, list their absolute paths in the [`CLAUDE_CODE_PLUGIN_DIRS`](</docs/en/env-vars#variables>) environment variable instead. Claude Code loads each path as it loads a `--plugin-dir` path. These plugins load in addition to any you pass with `--plugin-dir`. [Project and local settings can’t set this variable](</docs/en/settings-reference#variables-claude-code-ignores-in-env>). `CLAUDE_CODE_PLUGIN_DIRS` requires Claude Code v2.1.280 or later. Managed settings can turn off `--plugin-dir` and `CLAUDE_CODE_PLUGIN_DIRS`. See [Flags that load a plugin for one session](</docs/en/plugins/cli-reference#flags-that-load-a-plugin-for-one-session>). To test a plugin together with a plugin it depends on, see [Test a plugin and its dependency locally](</docs/en/plugins/dependencies#test-a-plugin-and-its-dependency-locally>). + +### + +​ + +Make a plugin load in every session + +Your personal skills directory is `~/.claude/skills/`. Claude Code loads any folder there that contains a `.claude-plugin/plugin.json` as a plugin in every session, with no flag and no install step. `claude plugin init` scaffolds one of these plugins for you. + +#### + +​ + +Scaffold the plugin with `claude plugin init` + +`claude plugin init` writes a starter plugin under `~/.claude/skills/`. Scaffold one from your shell: + + claude plugin init my-tool + +The command creates `~/.claude/skills/my-tool/` with a `.claude-plugin/plugin.json` and a root `SKILL.md`. It prints `✔ Created plugin "my-tool" at ~/.claude/skills/my-tool` followed by `It will auto-load next session as my-tool@skills-dir. Run /reload-plugins to load it now.` Pass `--with skills` to have `claude plugin init` scaffold a skill under `skills/` for you. The other `--with` values are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-init>). + +#### + +​ + +Name the plugin’s skills + +The root skill at `~/.claude/skills/my-tool/SKILL.md` is also a personal skill, so you invoke it as `/my-tool`, not `/my-tool:my-tool`. Skills you add under `skills/` inside the plugin get the plugin-name prefix, such as `/my-tool:example`. + +#### + +​ + +Stop loading the plugin + +To stop loading a scaffolded plugin, delete its directory, or run `claude plugin disable my-tool@skills-dir` in your shell with the `my-tool@skills-dir` name that `claude plugin init` printed. In the ID `my-tool@skills-dir`, `skills-dir` stands where a marketplace name would, because the plugin loads from your skills directory rather than from a marketplace. + +#### + +​ + +Share the plugin through a repository + +`claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, so it loads for you in every project. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. + +## + +​ + +Test and debug + +When a change to your plugin doesn’t show up, work through these checks in order. Each one tells you what Claude Code did with the plugin: + + 1. In your shell, run `claude plugin validate <path>`. It checks the manifest and the frontmatter of every skill, agent, and command file, and exits `0` on `Validation passed`. Add `--strict` to fail on warnings too. Exit codes and directory handling are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-validate>). + 2. In the running session, run `/reload-plugins` to apply edits you made on disk. It prints one `Reloaded:` line with counts. Then confirm a skill loaded by typing its `/plugin-name:skill` command, or by finding the plugin in the `/plugin` **Installed** tab. + 3. In the same session, run `/plugin`. The **Installed** tab lists your plugin and, in the plugin’s details, the components Claude Code found. The **Errors** tab lists what failed to load and why, such as a path in your manifest that doesn’t exist. + 4. Back in your shell, run `claude plugin list`. It prints session-only and skills-directory plugins in their own sections with `Status: ✔ loaded` or the load error. To include the plugin you’re developing, pass `--plugin-dir` with its path before `plugin list`. + +To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the [debug log](</docs/en/hooks#debug-hooks>), which shows which hooks matched, their exit codes, and their output. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. + +### + +​ + +A component path isn’t found + +The **Errors** tab of `/plugin` shows `<component> path not found: <path>`, for example `commands path not found`. A component path in your manifest, such as `commands`, `skills`, `agents`, or `hooks`, points at nothing. Fix the path or create the directory, then run `/reload-plugins` in the session. See [`commands path not found`](</docs/en/plugins/troubleshooting#commands-path-not-found>). + +### + +​ + +`--plugin-dir` at a marketplace root doesn’t load the plugins under `plugins/` + +`--plugin-dir` takes the plugin’s root directory, the one that contains `.claude-plugin/plugin.json` and the component directories such as `skills/`. If you point it at a marketplace root instead, Claude Code doesn’t read `marketplace.json`, so a plugin under `plugins/` doesn’t load, and you see no error. Point the flag at one plugin’s folder, or add the marketplace. See [the troubleshooting entry](</docs/en/plugins/troubleshooting#plugin-dir-loads-a-plugin-with-no-components>). + +### + +​ + +The plugin loads but its skills are missing + +The `skills/` directory is inside `.claude-plugin/`, or a `skills` entry in the manifest points at a file. Move `skills/` to the plugin root, point each `skills` entry at a directory that contains `SKILL.md`, and run `/reload-plugins` in the session. See [Plugin loads but its skills are missing](</docs/en/plugins/troubleshooting#plugin-loads-but-its-skills-are-missing>). + +### + +​ + +The `userConfig` dialog never appears + +The dialog for your plugin’s [`userConfig`](</docs/en/plugins/components#user-configuration>) options is part of installing through `/plugin` in a session. Loading with `--plugin-dir` doesn’t show it, and neither does `claude plugin install` in the shell. With the plugin loaded, run `/plugin configure <plugin-name>` in the session to open it. See [The `userConfig` dialog never appears](</docs/en/plugins/troubleshooting#the-userconfig-dialog-never-appears>). + +### + +​ + +Check that the plugin changes Claude’s behavior + +A plugin that loads without errors can still fail to steer Claude the way you intend. `claude plugin eval`, which you run in your shell, runs your test cases with and without the plugin and scores the difference. See [Test plugins with evals](</docs/en/plugin-evals>), starting with [Create your first eval suite](</docs/en/plugin-evals#create-your-first-eval-suite>). + +## + +​ + +Convert an existing `.claude/` setup + +If you already have skills, agents, or hooks under a project’s `.claude/` directory, you can move them into a plugin without rewriting them. Run the commands in these steps from the project root, which is the directory that contains `.claude/`, because the `cp` paths are relative to it. 1 -Create the plugin directory - -Create the two directories that hold the files: - - * Bash or Zsh - - * PowerShell - - mkdir -p first-mod/.claude-plugin first-mod/hooks - - New-Item -ItemType Directory -Force first-mod\.claude-plugin, first-mod\hooks +Create the plugin structure + +Create the plugin directory and its `.claude-plugin/` folder alongside `.claude/`. You can move the plugin anywhere afterwards. + + mkdir -p my-plugin/.claude-plugin + +Create `my-plugin/.claude-plugin/plugin.json`: + +my-plugin/.claude-plugin/plugin.json + + { + "name": "my-plugin", + "description": "Migrated from standalone configuration", + "version": "1.0.0" + } 2 -Write the manifest - -A mod is a plugin, and a mod needs a [manifest](</docs/en/plugins/manifest-reference>). This mod’s manifest has no special fields. Save this as `first-mod/.claude-plugin/plugin.json`: - -first-mod/.claude-plugin/plugin.json +Copy your existing files + +Copy each configuration directory you have to the plugin root, and skip the command for any directory you don’t have. + + cp -r .claude/commands my-plugin/ + + cp -r .claude/agents my-plugin/ + + cp -r .claude/skills my-plugin/ + +Run `ls -a my-plugin` to confirm that each directory you copied appears next to `.claude-plugin`. + +3 + +Move your hooks + +If you have hooks in `.claude/settings.json` or `.claude/settings.local.json`, create a hooks directory: + + mkdir -p my-plugin/hooks + +Create `my-plugin/hooks/hooks.json` and copy the `hooks` object from your settings file into it. The format is the same.This example shows the shape with one hook that runs a linter on each file Claude writes or edits. Replace the example with your own `hooks` object. + +my-plugin/hooks/hooks.json { - "name": "first-mod", - "version": "0.1.0", - "description": "Counts Claude's tool calls, shows the count beside the spinner, and adds a /tally command", - "author": { "name": "Your Name" } + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit", + "hooks": [{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npm run lint:fix" }] + } + ] + } } -3 - -Tell Claude Code where your code is - -When Claude Code loads a plugin, it reads the plugin’s `hooks/hooks.json`. The `modules` key in that file gives the path to your code, and having it is what makes the plugin a mod. List one path, relative to `hooks.json`. Here it points to `register.js`, which you write in the next step.Save this as `first-mod/hooks/hooks.json`: - -first-mod/hooks/hooks.json - - { - "description": "The first-mod hooks module", - "modules": ["./register.js"] - } - 4 -Write the code - -This file is the mod’s code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](</docs/en/plugins/mods/reference#the-hook-function>). Each call to `on` registers an event handler, called a hook, for the event it names.Save this as `first-mod/hooks/register.js`: - -first-mod/hooks/register.js - - // The count, shared by the hooks below - let calls = 0 - - // Claude Code calls this once when the mod loads - export function register(on) { - // Runs when the session starts, before your first prompt - on('session.start', async ($, e, next) => { - // Add the /tally command - await $.command.register({ - name: 'tally', - description: 'Show how many tool calls Claude has made', - }) - // Let the session start as usual - return next(e) - }) - - // Runs each time Claude is about to use a tool - on('tool.call', async ($, e, next) => { - calls += 1 - // Ask Claude Code to draw the interface again, so the new count shows - $.ui.invalidate('ui.render') - // Let the tool run as usual - return next(e) - }) - - // Runs when you type /tally, and only then, because of the matcher - on('command.run', { command: 'tally' }, async () => { - // The text to print in the transcript - return { text: 'Claude has made ' + calls + ' tool calls since this mod loaded' } - }) - - // Runs each time Claude Code draws the spinner - on('ui.render', { component: 'Spinner' }, async ($, e, next) => { - // Keep Claude Code's spinner, with the count added after its word - return next({ ...e, props: { ...e.props, suffix: ' · tool calls: ' + calls + '…' } }) - }) - } - -The file keeps a count in `calls` and registers four hooks: - - * **[`session.start`](</docs/en/plugins/mods/reference#session>)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code. - * **[`tool.call`](</docs/en/plugins/mods/reference#tools>)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again. - * **[`command.run`](</docs/en/plugins/mods/reference#commands-and-configuration>)** runs when you type `/tally`. It returns the text to print. - * **[`ui.render`](</docs/en/plugins/mods/reference#interface>)** runs each time Claude Code draws the spinner. It adds the count after the spinner’s word. - -How the example mod works explains the three arguments each hook takes and what each one returns. - -5 - -Load the mod - -Start Claude Code with the `--plugin-dir` flag, which loads a plugin directory for one session without installing it: - - claude --plugin-dir ./first-mod - -6 - -Try the mod - -Ask Claude to do something that takes a few tool calls, such as `list the files here and read the README`. While Claude works, the spinner’s word is followed by a count that rises, as in `Thinking · tool calls: 2…`. When Claude finishes, type `/tally` and press Enter. The transcript shows `first-mod: Claude has made 2 tool calls since this mod loaded`, with your own count. Claude Code puts the plugin’s name in front of the command’s text.To check the command without an interactive session, run it in non-interactive mode: - - claude -p "/tally" --plugin-dir ./first-mod - - first-mod: Claude has made 0 tool calls since this mod loaded - -If `/tally` isn’t in the command list, the module didn’t load. See [Find out why a mod does nothing](</docs/en/plugins/mods/troubleshoot#find-out-why-a-mod-does-nothing>). - -7 - -Change the code while the session runs - -Leave the session open. In `register.js`, change `' · tool calls: '` to `' · tools used: '` in the `ui.render` hook and save. The highlighted line is the one that changes: - -first-mod/hooks/register.js - - // Runs each time Claude Code draws the spinner - on('ui.render', { component: 'Spinner' }, async ($, e, next) => { - // Keep Claude Code's spinner, with the count added after its word - return next({ ...e, props: { ...e.props, suffix: ' · tools used: ' + calls + '…' } }) - }) - -A line in the transcript says `first-mod` reloaded and lists its hooks, and the next spinner uses the new text, as in `Thinking · tools used: 1…`. - -### - -​ - -How the example mod works - -Each function you pass to `on` is a hook, which is an event handler. Claude Code passes every hook the same three arguments: - - * **The mods API** , named `$`: every method a mod can call to reach outside itself, in [namespaces](</docs/en/plugins/mods/reference#mods-api-methods>) such as `$.ui` and `$.command` - * **The event** , named `e`: the [event’s input](</docs/en/plugins/mods/reference#events>) as plain data, such as a tool call’s name and arguments - * **The next handler** , named [`next`](</docs/en/plugins/mods/events#how-a-hook-handles-an-event>): a function that passes the event on to the other mods and then to Claude Code’s own behavior, and returns the result - -The hooks in `first-mod` handle their events in these ways: - - * **Observe** : the `session.start` hook registers the command, and the `tool.call` hook counts the call and asks for a redraw. Both return `next(e)`, so the session starts and the tool runs as usual. - * **Answer** : the `command.run` hook returns its own result and never calls `next`. The second argument to `on`, `{ command: 'tally' }`, is a filter, called a [matcher](</docs/en/plugins/mods/events#filter-which-events-a-hook-handles>), so the hook runs only for `/tally`. - * **Rewrite** : the `ui.render` hook calls `next` with a copy of `e` whose `suffix` holds the count, so Claude Code draws its usual spinner with your text after the word - -Claude Code watches a directory loaded with `--plugin-dir` and hot-reloads the hooks module when a file in it changes. Each reload runs `register` again, so `calls` resets to `0` and `/tally` starts counting again. To keep a value across reloads, see [Keep state](</docs/en/plugins/mods/interface#keep-state>). - -## - -​ - -Keep working on a mod - -Once a mod loads, you can have Claude change it, check your code against the type definitions for your version, list the events and calls Claude Code finds in it, and test it. - -### - -​ - -Change a mod with Claude - -To change a mod you already have, start the session with `--plugin-dir` pointed at the mod’s directory, so that what Claude writes loads in the same session: - - claude --plugin-dir ./first-mod - -Then ask for the change, for example `add a /tally-reset command to this mod that sets the tally back to zero`. Claude edits the hooks module, runs `claude plugin validate`, and fixes what it reports. A directory you load with `--plugin-dir` is a [protected path](</docs/en/permission-modes#protected-paths>), so in `default` and `acceptEdits` modes you’re asked to approve each of Claude’s edits to the mod. The protected paths table gives the result for the other permission modes. Files Claude saves during its turn reload when the turn ends, so you can try `/tally-reset` as soon as Claude finishes. - -### - -​ - -Get type definitions for your version - -Each time Claude Code loads or reloads a mod from a directory you pass to `--plugin-dir`, or a mod Claude wrote for you, it writes TypeScript declaration files, ending in `.d.ts`, into `.claude-plugin/types/` inside the mod’s directory. They describe the exact events, mods API methods, and elements in the Claude Code version you’re running, so your editor can autocomplete and type-check your hooks. To browse the declarations online, read [`mods/types/claude-code.d.ts`](<https://github.com/anthropics/claude-code/blob/main/mods/types/claude-code.d.ts>) in the Claude Code repository, whose first line names the version that wrote it. The directory holds these files: - -Path| What it declares ----|--- -`claude-code/index.d.ts`| Every event and its input and result, every mods API namespace and method, and the elements each surface can draw -`claude-code-tools/index.d.ts`| The built-in tools’ inputs and results, so that checking `e.tool === 'Bash'` narrows `e` -`claude-code-mcp/index.d.ts`| The inputs of the MCP tools that were connected the last time you saved a file in the mod -`index.d.ts` in a directory named for a plugin| What that plugin adds to the mods API. There’s one directory for each plugin your `plugin.json` lists under `dependencies`. -`tsconfig.json`| Compiler options that fit a hooks module - -If your mod has no `tsconfig.json` of its own, Claude Code adds one at the mod’s root that extends the generated one, so your editor and `tsc -p ./first-mod` type-check the mod without more setup. The events and methods can change between releases, so trust these files over any page, this one included, when they disagree. `claude-code/index.d.ts` is the fullest reference for your build, with a comment and an example for every mods API method. To look something up, search the file for its name, such as `'tool.call'`. - -### - -​ - -Check what Claude Code reads from your mod - -To see your mod the way Claude Code sees it, without running your code or starting a session, use `claude plugin validate`. It checks the manifest and runs the same static analysis on the hooks module’s source that Claude Code runs when it loads a mod. In your shell, run it on the mod’s directory: - - claude plugin validate ./first-mod - -For `first-mod`, the output includes these lines. - - ❯ ./register.js hooks: session.start, tool.call, command.run{command=tally}, ui.render{component=Spinner} - ❯ ./register.js calls: $.command.register, $.ui.invalidate - - ✔ Validation passed - -Check the `hooks:` line for the events your module hooks, each with its filter in braces, and `calls:` for every mods API method it calls. If your module reads or sets environment variables, look for `env reads:` and `env writes:` lines too, and `state reads:` and `state writes:` if it uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>). You also see one line for each hook that can refuse an action, such as `gating hook without .catch: tool.call`, which says whether that hook has a [`.catch` handler](</docs/en/plugins/mods/events#handle-a-hook-that-fails>). If an event you meant to handle is missing from the first line, Claude Code won’t call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`. Follow these rules so that static analysis can find every hook and call: - - * Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. You can pass `$` to a function declared at the top level of the same file, and for a function of yours named `loadNotes`, the `calls:` line then reads `$.store.get (via loadNotes)`. Passing `$` to a method, a function defined inside the hook, or a function you import from another of your files fails validation. The `read` and `update` functions that [`$.state`](</docs/en/plugins/mods/interface#keep-state>) uses are the imports that can take it. Don’t assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`. - * Write the event name in each `on` call as a string literal, such as `'tool.call'`. A variable, or a loop over a list of names, fails with `the event name passed to on() is not a string literal`. - * Inside `register`, don’t declare a second variable or parameter named `on`. Validation fails with `"on" is declared again (shadowed)`. - * Import only from files inside the plugin directory, by relative path. The one bare import allowed is `claude-code`, for types and a few helpers. - * Use `import` declarations at the top of the file, as in `import { name } from './file.js'`. A dynamic `import()` fails with `a dynamic import(); a hooks module imports its own files with an import declaration`. - * Write every file as an ES module, with `import` and not `require`. The [reference](</docs/en/plugins/mods/reference#files>) lists the file extensions Claude Code loads. - -### - -​ - -Test the mod - -You can write automated tests for a mod and run them from your shell with `claude plugin test`, with no session, sign-in, or network. A test fires the events your hooks handle and checks what the hooks did. This test fires two tool calls, runs `/tally`, and checks that the reply counts both. Save it as `first-mod/tests/first-mod.test.ts`: - -first-mod/tests/first-mod.test.ts - - import { expect, test } from 'claude-code/testing' - - test('/tally reports the tool calls the mod has seen', async ($, on) => { - // Answer each tool call in Claude Code's place, so no tool runs - on('tool.call', () => ({ result: 'ok' })) - - // Fire two tool calls, which the mod's tool.call hook counts - await $.tool.call({ tool: 'Bash', command: 'ls' }) - await $.tool.call({ tool: 'Read', file_path: 'README.md' }) - - // Run /tally and check the text its hook returns - const answer = await $.command.run({ command: 'tally', args: '' }) - expect(answer.text).toBe('Claude has made 2 tool calls since this mod loaded') - }) - -In your shell, run the tests from the `first-mod` directory: - - claude plugin test - -The output names each test and whether it passed, with timings that vary from run to run: - - tests/first-mod.test.ts: - (pass) /tally reports the tool calls the mod has seen [22.87ms] - - 1 pass - 0 fail - Ran 1 test across 1 file. [0.19s] - -[Test a mod](</docs/en/plugins/mods/test>) covers stubbing a model call or the store, and testing timers and drawings. - -## - -​ - -Share your mod - -A mod is a plugin, so you version it in the manifest and people install and update it with the `/plugin` commands. How you share it depends on who it’s for: - - * **A few people** : send them the plugin’s directory or a `.zip` of it. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>) - * **Your team** : list it in [your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>), such as a private repository with one directory for each plugin. To add that marketplace for everyone who works in a repository, [register it in the repository’s settings](</docs/en/plugins/host-marketplace#register-the-marketplace-for-everyone-in-a-repository>) - * **Your whole organization** : an administrator can [install your organization’s mods](</docs/en/plugins/mods/admin#install-your-organizations-mods>) through managed settings - * **Anyone** : make your marketplace’s repository public, or [submit the plugin to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>) - -Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don’t reach the installed copy until you increment the version and install again. +Test the migrated plugin + +Load the plugin for a session: + + claude --plugin-dir ./my-plugin + +Check each component under its new name: + + * **Skills** : run `/my-plugin:deploy` for a skill that was `/deploy`. + * **Subagents** : ask Claude to use the `my-plugin:reviewer` agent for an agent that was `reviewer`. + * **Hooks** : trigger the event each hook matches. + +If something is missing, work through Test and debug. + +While the originals are still under `.claude/`, they stay loaded alongside the plugin’s copies: + + * **Skills and agents** : the two sets don’t collide, because the plugin’s skills and agents carry the `my-plugin:` prefix. `/deploy` and `/my-plugin:deploy` both work, and Claude sees `reviewer` and `my-plugin:reviewer` as two subagents. + * **Hooks** : hooks have no prefix, so a hook that is in both your settings file and `hooks/hooks.json` runs twice each time its event fires. + +After you’ve confirmed the plugin works, delete the originals from `.claude/` and remove the `hooks` object from your settings file. ## @@ -366,9 +401,10 @@ Next steps - * [Draw in the interface](</docs/en/plugins/mods/interface>): open a pane, draw above the prompt, and add buttons and text fields - * [React to events](</docs/en/plugins/mods/events>): hook tool calls, prompts, and turns - * [Use the mods API](</docs/en/plugins/mods/api>): add commands and tools, call a model, and run work on a timer - * [Test a mod](</docs/en/plugins/mods/test>): stub what Claude Code would answer, and test timers and drawings - * [Troubleshoot a mod](</docs/en/plugins/mods/troubleshoot>): the reasons a mod does nothing, and the debug log - * [Read the source of built-in mods](</docs/en/plugins/mods/overview#read-the-source-of-built-in-mods>): complete plugins, each with its hooks module and tests + * [Plugin components](</docs/en/plugins/components>): add agents, hooks, MCP servers, LSP servers, and user configuration to your plugin + * [Test plugins with evals](</docs/en/plugin-evals>): write eval cases and run them with `claude plugin eval` to check how reliably the plugin guides Claude’s behavior + * [Publish a plugin](</docs/en/plugins/publish>): version it, put it in a marketplace, and submit it for review + * [Plugin structure and testing](<https://claude.com/docs/plugins/build>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only, and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) lists which load on each surface + * [Plugin manifest reference](</docs/en/plugins/manifest-reference>): every `plugin.json` field, path rule, and directory + * [Skills](</docs/en/skills>): write the skills your plugin provides + * [Anthropic’s plugins in the claude-code repository](<https://github.com/anthropics/claude-code/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review`
modified
--- a/create.md +++ b/create.md @@ -296,7 +296,7 @@ ✔ Validation passed -The `hooks:` line lists the events your module hooks, each with its filter in braces. The `calls:` line lists every mods API method it calls. A module that reads or sets environment variables also gets `env reads:` and `env writes:` lines, and one that uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>) gets `state reads:` and `state writes:`. If an event you meant to handle is missing from the first line, Claude Code won’t call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`. Follow these rules so that static analysis can find every hook and call: +Check the `hooks:` line for the events your module hooks, each with its filter in braces, and `calls:` for every mods API method it calls. If your module reads or sets environment variables, look for `env reads:` and `env writes:` lines too, and `state reads:` and `state writes:` if it uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>). You also see one line for each hook that can refuse an action, such as `gating hook without .catch: tool.call`, which says whether that hook has a [`.catch` handler](</docs/en/plugins/mods/events#handle-a-hook-that-fails>). If an event you meant to handle is missing from the first line, Claude Code won’t call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`. Follow these rules so that static analysis can find every hook and call: * Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. You can pass `$` to a function declared at the top level of the same file, and for a function of yours named `loadNotes`, the `calls:` line then reads `$.store.get (via loadNotes)`. Passing `$` to a method, a function defined inside the hook, or a function you import from another of your files fails validation. The `read` and `update` functions that [`$.state`](</docs/en/plugins/mods/interface#keep-state>) uses are the imports that can take it. Don’t assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`. * Write the event name in each `on` call as a string literal, such as `'tool.call'`. A variable, or a loop over a list of names, fails with `the event name passed to on() is not a string literal`.
modified
--- a/create.md +++ b/create.md @@ -5,7 +5,7 @@ If you haven’t decided whether a mod is the right tool, read the [comparison on the overview](</docs/en/plugins/mods/overview#compare-mods-settings-hooks-skills-and-mcp-servers>) first. -Mods require Claude Code v2.1.287 or later. In your shell, run `claude --version` to check. To see whether mods can load for you, see [Check whether mods can load](</docs/en/plugins/mods/troubleshoot#check-whether-mods-can-load>). +Use Claude Code v2.1.287 or later. In your shell, run `claude --version` to check. To see whether mods can load for you, see [Check whether mods can load](</docs/en/plugins/mods/troubleshoot#check-whether-mods-can-load>). ##
modified
--- a/create.md +++ b/create.md @@ -351,7 +351,14 @@ Share your mod -A mod is a plugin, so you version it in the manifest and people install and update it with the `/plugin` commands. To give it to other people, [add it to a marketplace](</docs/en/plugins/publish>). Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don’t reach the installed copy until you increment the version and install again. +A mod is a plugin, so you version it in the manifest and people install and update it with the `/plugin` commands. How you share it depends on who it’s for: + + * **A few people** : send them the plugin’s directory or a `.zip` of it. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>) + * **Your team** : list it in [your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>), such as a private repository with one directory for each plugin. To add that marketplace for everyone who works in a repository, [register it in the repository’s settings](</docs/en/plugins/host-marketplace#register-the-marketplace-for-everyone-in-a-repository>) + * **Your whole organization** : an administrator can [install your organization’s mods](</docs/en/plugins/mods/admin#install-your-organizations-mods>) through managed settings + * **Anyone** : make your marketplace’s repository public, or [submit the plugin to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>) + +Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don’t reach the installed copy until you increment the version and install again. ##
modified
Show diff (750 lines)
--- a/create.md +++ b/create.md @@ -1,399 +1,357 @@ -A plugin is a directory of skills, agents, hooks, and MCP servers, plus a `plugin.json` file, called the manifest, that names the plugin. Claude Code loads the directory as one unit, so you can share it with teammates, install it in several projects, or publish it to a marketplace. This page is for people writing their own plugins. - -These cases are covered on other pages: - - * **Installing someone else’s plugin** : see [Install plugins](</docs/en/plugins/install>) - * **Not sure you need a plugin** : see [Decide whether you need a plugin](</docs/en/plugins/overview#decide-whether-you-need-a-plugin>) on the overview - * **Your plugin’s users are on claude.ai or in Cowork** : the same folder installs there with a different subset of components. See [Plugin structure and testing](<https://claude.com/docs/plugins/build>) and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) - -Start from the section that matches what you already have: - - * **Nothing yet** : follow Create your first plugin, then Develop without a marketplace and Test and debug. - * **Files under`.claude/` already**: do the first-plugin walkthrough once to learn the layout, then follow Convert an existing `.claude/` setup. - -## - -​ - -Decide when to use a plugin - -Skills, agents, hooks, and MCP servers all work standalone in your project or home directory. Keep that standalone setup while it serves one project or only you. Make a plugin when you want to share the setup with teammates, install it in several projects, or publish versioned releases. When you move standalone skills, agents, hooks, and MCP config into a plugin, their location and names change: - - * **Where the files go** : under the plugin’s own directory, called the plugin root, as `skills/`, `agents/`, `hooks/hooks.json`, and `.mcp.json`. - * **How they’re named** : plugin skills and agents get the plugin name as a prefix, such as `/my-plugin:hello`, so two plugins can each provide a `hello` skill without colliding. - -To move an existing setup into a plugin, see Convert an existing `.claude/` setup. - -## - -​ - -Create your first plugin - -In this walkthrough, you create a plugin whose only component is one skill, a greeting, and run it with `--plugin-dir`, which loads a plugin for one session without installing it. A plugin can hold any mix of [components](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, and none is required; one skill is the smallest example that shows the layout. You need Claude Code [installed and signed in](</docs/en/quickstart#step-1-install-claude-code>). Open a terminal in the directory where you want to keep the plugin, such as `~/projects`, and run the commands in these steps from it. You can keep a plugin anywhere, because you pass its path to Claude Code when you start a session. +A mod is a Claude Code [plugin](</docs/en/plugins/overview>) with an entry file, called the hooks module: a JavaScript or TypeScript file whose functions Claude Code calls when events happen. To make one: + + * **Ask Claude to write it** : describe what you want in a Claude Code session + * **Write it yourself** : follow the tutorial to learn how a mod’s code works. You don’t need Node.js, a bundler, or a build step, because Claude Code loads `.js` and `.ts` files directly. + +If you haven’t decided whether a mod is the right tool, read the [comparison on the overview](</docs/en/plugins/mods/overview#compare-mods-settings-hooks-skills-and-mcp-servers>) first. + +Mods require Claude Code v2.1.287 or later. In your shell, run `claude --version` to check. To see whether mods can load for you, see [Check whether mods can load](</docs/en/plugins/mods/troubleshoot#check-whether-mods-can-load>). + +## + +​ + +Ask Claude for a mod + +Describe the mod you want in an interactive Claude Code session, and Claude writes it. Claude works from a built-in [skill](</docs/en/skills>) named `plugin-authoring`, which tells it where to write the mod, which events and methods your version has, and how the mod gets loaded. Claude can load the skill when you ask for a mod, or you can load it yourself by running `/plugin-authoring` at the Claude Code prompt. The mod runs once you approve it, except in sessions where a mod Claude writes can’t load. 1 +Describe the mod + +Ask for the mod in your own words, for example `make a mod that shows the current git branch above the prompt`. Claude writes the mod in a directory of its own in the session’s mods folder, which is `~/.claude/dev-mods/` followed by the session’s ID. A mod’s full path looks like `~/.claude/dev-mods/3f2a9c1e-5b7d-4e8a-9c21-6d0f4b8a7e13/git-branch/`. + +In the `default` and `acceptEdits` [permission modes](</docs/en/permission-modes#protected-paths>), Claude Code asks before Claude creates each of the mod’s files, because `~/.claude` is a protected path. Approve each file as it comes up. + +2 + +Approve the mod + +When Claude saves the first file, Claude Code asks whether to enable hot reloading for the session. Hot reloading runs the mods Claude writes in this session and picks up each later change.Choose one of these answers: + + * **Enable for this session** : the mods in the session’s mods folder load when the turn ends, and reload at the end of each turn that changes them. Your answer lasts for the session, including after you resume it. + * **Not now** : nothing loads for now. The files stay where Claude wrote them, and the mods load the next time that session starts. To keep a mod from ever loading, delete its directory. + +3 + +Check that the mod loaded + +Run `/plugin` at the Claude Code prompt and press Tab until the **Installed** tab is selected. It lists the mod, and you can turn it off there. + +4 + +Try the mod + +Use what you asked for. For the example prompt, the current branch name appears above the prompt box. If the mod doesn’t do what you wanted, tell Claude what to change. The mod reloads at the end of each turn that changes its files, so you can try the change as soon as Claude finishes. + +### + +​ + +Use the mod in other sessions + +A mod Claude wrote loads only in the session that made it, and Claude Code deletes that session’s mods folder once it’s older than [`cleanupPeriodDays`](</docs/en/settings-reference#cleanupperioddays>). To keep the mod, copy its directory out of the mods folder to a place of your own, such as `~/mods/git-branch`. Then choose how to load it: + + * **In a session you start** : in your shell, run `claude --plugin-dir ~/mods/git-branch` + * **For other people** : add it to a marketplace so they can install it + +### + +​ + +Sessions where a mod Claude writes can’t load + +A mod Claude writes loads only after you approve it, in a trusted workspace where mods are allowed to run. In these sessions it doesn’t load: + + * **Nobody is there to approve** : the session can’t show you a prompt, as in a `claude -p` run or [`dontAsk` mode](</docs/en/permission-modes>) + * **The workspace isn’t trusted** : you haven’t accepted the trust prompt for the directory + * **Mods are disabled** : you started with `--safe-mode` or `--bare`, you set `disableAllHooks`, or your organization’s [managed settings block it](</docs/en/plugins/mods/admin#choose-how-much-to-allow>) + +## + +​ + +Write a mod yourself + +In this tutorial you build a mod named `first-mod` that counts the tool calls Claude makes, shows the count beside the spinner while Claude works, and adds a `/tally` command that prints it. You then read the type declarations Claude Code writes beside your mod and run `claude plugin validate`. Together they show you the events and methods your version offers and what Claude Code reads from your code. This recording shows the finished mod. The spinner counts tool calls, `/tally` prints the count, and an edit to the code takes effect while the session runs: + +You write three files: + + first-mod/ + ├── .claude-plugin/ + │ └── plugin.json + └── hooks/ + ├── hooks.json + └── register.js + + * **`plugin.json`** : the plugin’s [manifest](</docs/en/plugins/manifest-reference>) + * **`hooks.json`** : [points to your code file](</docs/en/plugins/mods/reference#files>) + * **`register.js`** : your code, called the hooks module + +1 + Create the plugin directory -Create the plugin directory, with a `.claude-plugin/` folder inside it to hold the manifest: - - mkdir -p my-first-plugin/.claude-plugin +Create the two directories that hold the files: + + * Bash or Zsh + + * PowerShell + + mkdir -p first-mod/.claude-plugin first-mod/hooks + + New-Item -ItemType Directory -Force first-mod\.claude-plugin, first-mod\hooks 2 Write the manifest -The [manifest](</docs/en/plugins/manifest-reference>) is a JSON file named `plugin.json` that tells Claude Code the plugin’s name and describes it. Save this one as `my-first-plugin/.claude-plugin/plugin.json`: - -my-first-plugin/.claude-plugin/plugin.json +A mod is a plugin, and a mod needs a [manifest](</docs/en/plugins/manifest-reference>). This mod’s manifest has no special fields. Save this as `first-mod/.claude-plugin/plugin.json`: + +first-mod/.claude-plugin/plugin.json { - "name": "my-first-plugin", - "description": "A greeting plugin to learn the basics", - "version": "1.0.0", - "author": { - "name": "Your Name" - } + "name": "first-mod", + "version": "0.1.0", + "description": "Counts Claude's tool calls, shows the count beside the spinner, and adds a /tally command", + "author": { "name": "Your Name" } } -The four fields do this: - - * **`name`** : required. It identifies the plugin and becomes the prefix on every skill and agent the plugin provides. Don’t put spaces in it. - * **`description`** : the text users see for the plugin in `/plugin`. - * **`version`** : optional. Setting it keeps users on that version until you change it; [Release a new version](</docs/en/plugins/host-marketplace#release-a-new-version>) says when to set or omit it. - * **`author`** : who to credit. `name` is required inside it; `email` and `url` are optional. - -Every other field is on the [manifest reference](</docs/en/plugins/manifest-reference#fields>).Only `plugin.json` goes inside `.claude-plugin/`. The skill you add next goes directly under `my-first-plugin/`, next to that folder. - 3 -Add a skill - -This plugin’s one component is a skill. Each skill is a directory under `skills/` that contains a `SKILL.md` file. Create the skill’s directory: - - mkdir -p my-first-plugin/skills/hello - -Then create `my-first-plugin/skills/hello/SKILL.md` with this content: - -my-first-plugin/skills/hello/SKILL.md - - --- - name: hello - description: Greet the user with a friendly message - disable-model-invocation: true - --- - - Greet the user warmly and ask how you can help them today. - -The `disable-model-invocation: true` line means Claude doesn’t run the skill on its own, so only you trigger it. Remove that line from a skill you want Claude to run on its own. The skill’s command combines the plugin name and the skill’s name, so you run this one as `/my-first-plugin:hello`. For the other frontmatter fields, see the [skill frontmatter reference](</docs/en/skills#frontmatter-reference>). +Tell Claude Code where your code is + +When Claude Code loads a plugin, it reads the plugin’s `hooks/hooks.json`. The `modules` key in that file gives the path to your code, and having it is what makes the plugin a mod. List one path, relative to `hooks.json`. Here it points to `register.js`, which you write in the next step.Save this as `first-mod/hooks/hooks.json`: + +first-mod/hooks/hooks.json + + { + "description": "The first-mod hooks module", + "modules": ["./register.js"] + } 4 -Validate the plugin - -Check the manifest and the skill’s frontmatter before you run anything: - - claude plugin validate ./my-first-plugin - -The command prints the manifest path it checked and `✔ Validation passed`. If it prints `✘ Validation failed` instead, each line above that result line names the field to fix. Look up each message under [`claude plugin validate` reports errors](</docs/en/plugins/troubleshooting#claude-plugin-validate-reports-errors>). +Write the code + +This file is the mod’s code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](</docs/en/plugins/mods/reference#the-hook-function>). Each call to `on` registers an event handler, called a hook, for the event it names.Save this as `first-mod/hooks/register.js`: + +first-mod/hooks/register.js + + // The count, shared by the hooks below + let calls = 0 + + // Claude Code calls this once when the mod loads + export function register(on) { + // Runs when the session starts, before your first prompt + on('session.start', async ($, e, next) => { + // Add the /tally command + await $.command.register({ + name: 'tally', + description: 'Show how many tool calls Claude has made', + }) + // Let the session start as usual + return next(e) + }) + + // Runs each time Claude is about to use a tool + on('tool.call', async ($, e, next) => { + calls += 1 + // Ask Claude Code to draw the interface again, so the new count shows + $.ui.invalidate('ui.render') + // Let the tool run as usual + return next(e) + }) + + // Runs when you type /tally, and only then, because of the matcher + on('command.run', { command: 'tally' }, async () => { + // The text to print in the transcript + return { text: 'Claude has made ' + calls + ' tool calls since this mod loaded' } + }) + + // Runs each time Claude Code draws the spinner + on('ui.render', { component: 'Spinner' }, async ($, e, next) => { + // Keep Claude Code's spinner, with the count added after its word + return next({ ...e, props: { ...e.props, suffix: ' · tool calls: ' + calls + '…' } }) + }) + } + +The file keeps a count in `calls` and registers four hooks: + + * **[`session.start`](</docs/en/plugins/mods/reference#session>)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code. + * **[`tool.call`](</docs/en/plugins/mods/reference#tools>)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again. + * **[`command.run`](</docs/en/plugins/mods/reference#commands-and-configuration>)** runs when you type `/tally`. It returns the text to print. + * **[`ui.render`](</docs/en/plugins/mods/reference#interface>)** runs each time Claude Code draws the spinner. It adds the count after the spinner’s word. + +How the example mod works explains the three arguments each hook takes and what each one returns. 5 -Run Claude Code with the plugin - -Start a session with the plugin loaded: - - claude --plugin-dir ./my-first-plugin - -Once Claude Code starts, run the skill: - - /my-first-plugin:hello - -Claude replies with a greeting. - -The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. To have Claude scaffold and check a larger plugin with you, [install](</docs/en/plugins/install#install-a-plugin>) Anthropic’s `plugin-dev` plugin from the `claude-plugins-official` marketplace, which adds skills and agents for writing components such as skills, hooks, and MCP servers and for validating the finished plugin. Once it’s installed, run `/plugin-dev:create-plugin` followed by a description of the plugin you want, and Claude walks you through designing, creating, and validating it. - -### - -​ - -Share your plugin - -A plugin you built with Create your first plugin exists only on your machine. When it’s ready for other people, there are three ways to get it to them: - - * **Send it to a few people directly** : give them the plugin’s directory or a `.zip` of it, and nothing needs to be published. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>). - * **List it in your own marketplace** : teammates add your marketplace once and install the plugin by name, and they receive your updates. See [Publish through your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>). - * **Submit it to Anthropic’s directory** : after it passes review, people can add it on claude.ai and in Cowork, and it reaches Claude Code through their account. See [Submit to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>). - -### - -​ - -Plugin layout - -Each kind of [component](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, goes in a fixed directory under the plugin root, which is the directory you pass to `--plugin-dir`. Add only the directories you use. To click through a complete plugin directory and read what each file does, open the [plugin explorer](</docs/en/plugins/components#explore-the-plugin-directory>). The table lists the directories most plugins start with, and the [full layout](</docs/en/plugins/manifest-reference#standard-layout>) lists the rest. - -Location| Contents +Load the mod + +Start Claude Code with the `--plugin-dir` flag, which loads a plugin directory for one session without installing it: + + claude --plugin-dir ./first-mod + +6 + +Try the mod + +Ask Claude to do something that takes a few tool calls, such as `list the files here and read the README`. While Claude works, the spinner’s word is followed by a count that rises, as in `Thinking · tool calls: 2…`. When Claude finishes, type `/tally` and press Enter. The transcript shows `first-mod: Claude has made 2 tool calls since this mod loaded`, with your own count. Claude Code puts the plugin’s name in front of the command’s text.To check the command without an interactive session, run it in non-interactive mode: + + claude -p "/tally" --plugin-dir ./first-mod + + first-mod: Claude has made 0 tool calls since this mod loaded + +If `/tally` isn’t in the command list, the module didn’t load. See [Find out why a mod does nothing](</docs/en/plugins/mods/troubleshoot#find-out-why-a-mod-does-nothing>). + +7 + +Change the code while the session runs + +Leave the session open. In `register.js`, change `' · tool calls: '` to `' · tools used: '` in the `ui.render` hook and save. The highlighted line is the one that changes: + +first-mod/hooks/register.js + + // Runs each time Claude Code draws the spinner + on('ui.render', { component: 'Spinner' }, async ($, e, next) => { + // Keep Claude Code's spinner, with the count added after its word + return next({ ...e, props: { ...e.props, suffix: ' · tools used: ' + calls + '…' } }) + }) + +A line in the transcript says `first-mod` reloaded and lists its hooks, and the next spinner uses the new text, as in `Thinking · tools used: 1…`. + +### + +​ + +How the example mod works + +Each function you pass to `on` is a hook, which is an event handler. Claude Code passes every hook the same three arguments: + + * **The mods API** , named `$`: every method a mod can call to reach outside itself, in [namespaces](</docs/en/plugins/mods/reference#mods-api-methods>) such as `$.ui` and `$.command` + * **The event** , named `e`: the [event’s input](</docs/en/plugins/mods/reference#events>) as plain data, such as a tool call’s name and arguments + * **The next handler** , named [`next`](</docs/en/plugins/mods/events#how-a-hook-handles-an-event>): a function that passes the event on to the other mods and then to Claude Code’s own behavior, and returns the result + +The hooks in `first-mod` handle their events in these ways: + + * **Observe** : the `session.start` hook registers the command, and the `tool.call` hook counts the call and asks for a redraw. Both return `next(e)`, so the session starts and the tool runs as usual. + * **Answer** : the `command.run` hook returns its own result and never calls `next`. The second argument to `on`, `{ command: 'tally' }`, is a filter, called a [matcher](</docs/en/plugins/mods/events#filter-which-events-a-hook-handles>), so the hook runs only for `/tally`. + * **Rewrite** : the `ui.render` hook calls `next` with a copy of `e` whose `suffix` holds the count, so Claude Code draws its usual spinner with your text after the word + +Claude Code watches a directory loaded with `--plugin-dir` and hot-reloads the hooks module when a file in it changes. Each reload runs `register` again, so `calls` resets to `0` and `/tally` starts counting again. To keep a value across reloads, see [Keep state](</docs/en/plugins/mods/interface#keep-state>). + +## + +​ + +Keep working on a mod + +Once a mod loads, you can have Claude change it, check your code against the type definitions for your version, list the events and calls Claude Code finds in it, and test it. + +### + +​ + +Change a mod with Claude + +To change a mod you already have, start the session with `--plugin-dir` pointed at the mod’s directory, so that what Claude writes loads in the same session: + + claude --plugin-dir ./first-mod + +Then ask for the change, for example `add a /tally-reset command to this mod that sets the tally back to zero`. Claude edits the hooks module, runs `claude plugin validate`, and fixes what it reports. A directory you load with `--plugin-dir` is a [protected path](</docs/en/permission-modes#protected-paths>), so in `default` and `acceptEdits` modes you’re asked to approve each of Claude’s edits to the mod. The protected paths table gives the result for the other permission modes. Files Claude saves during its turn reload when the turn ends, so you can try `/tally-reset` as soon as Claude finishes. + +### + +​ + +Get type definitions for your version + +Each time Claude Code loads or reloads a mod from a directory you pass to `--plugin-dir`, or a mod Claude wrote for you, it writes TypeScript declaration files, ending in `.d.ts`, into `.claude-plugin/types/` inside the mod’s directory. They describe the exact events, mods API methods, and elements in the Claude Code version you’re running, so your editor can autocomplete and type-check your hooks. To browse the declarations online, read [`mods/types/claude-code.d.ts`](<https://github.com/anthropics/claude-code/blob/main/mods/types/claude-code.d.ts>) in the Claude Code repository, whose first line names the version that wrote it. The directory holds these files: + +Path| What it declares ---|--- -`.claude-plugin/plugin.json`| The manifest. When you load a plugin with `--plugin-dir` and it has no manifest, Claude Code names the plugin after its directory -`skills/`| One `<name>/SKILL.md` directory per skill -`commands/`| Flat Markdown files, the older form of skills. Use `skills/` for new plugins -`agents/`| One Markdown file per subagent -`hooks/hooks.json`| Hook configuration: a top-level `"hooks"` key whose value has the same shape as `hooks` in a settings file -`.mcp.json`| MCP server definitions - -Only `plugin.json` goes inside `.claude-plugin/`. Components saved there don’t load.The plugin root is the plugin’s own directory, not `~/.claude/` itself. A `.mcp.json` saved at `~/.claude/.mcp.json` doesn’t load. - -## - -​ - -Develop without a marketplace - -You don’t need a [marketplace](</docs/en/plugins/overview#get-plugins-from-a-marketplace>) to run a plugin you’re writing. Load it directly from disk or a URL instead: - - * `--plugin-dir`: loads a directory or `.zip` archive for one session. - * `--plugin-url`: fetches a `.zip` archive from a URL for one session. - * `claude plugin init`: scaffolds a plugin under `~/.claude/skills/` that loads every session. - -If two plugins loaded in different ways share a name, see [Name conflicts](</docs/en/plugins/loading#name-conflicts>) for which one Claude Code keeps. - -### - -​ - -Load a plugin for one session - -You can load a plugin for a single session in three ways: from a directory or `.zip` archive on disk with `--plugin-dir`, from a URL with `--plugin-url`, or from an environment variable when you can’t add a flag. Each plugin loads for that session only, and nothing is written to your settings for it. When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. - -#### - -​ - -From a directory or `.zip` - -When you start `claude` from your shell, pass `--plugin-dir` with the plugin’s root directory or a `.zip` archive of it. Repeat the flag to load several plugins: - - claude --plugin-dir ./my-first-plugin --plugin-dir ./other-plugin.zip - -#### - -​ - -From a folder of plugins - -To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. You can also pass a folder that keeps a `.claude-plugin/marketplace.json` beside its plugin folders. As long as that `.claude-plugin/` directory holds no `plugin.json`, the plugin folders still load. Nothing is installed or enabled from the marketplace file, because Claude Code doesn’t read it. Loading plugins from such a folder requires Claude Code v2.1.281 or later. In an interactive session, you can also add and remove plugins in the folder after startup: - - * A subfolder you add loads as a new plugin once its manifest exists. - * When you remove a subfolder, its plugin unloads. - -A message appears in the session for each of these changes. If loading or unloading a plugin mid-conversation would [invalidate the prompt cache](</docs/en/prompt-caching#enabling-or-disabling-a-plugin>), the change is held instead, and the message tells you to run `/reload-plugins` to apply it. - -#### - -​ - -From a URL - -When you start `claude` from your shell, pass `--plugin-url` with the address of a `.zip` archive, such as a build artifact your CI publishes: - - claude --plugin-url https://example.com/my-first-plugin.zip - -Claude Code downloads the archive at startup. To load several, repeat the flag or pass the URLs space-separated in one quoted argument. Point the flag only at archives you control or trust. If Claude Code can’t fetch the archive, or the archive is invalid, it starts without the plugin and records a plugin load error that you can review in the `/plugin` manager’s **Errors** tab. - -#### - -​ - -From an environment variable - -To load plugins in a session where you can’t add the `--plugin-dir` flag, list their absolute paths in the [`CLAUDE_CODE_PLUGIN_DIRS`](</docs/en/env-vars#variables>) environment variable instead. Claude Code loads each path as it loads a `--plugin-dir` path. These plugins load in addition to any you pass with `--plugin-dir`. [Project and local settings can’t set this variable](</docs/en/settings-reference#variables-claude-code-ignores-in-env>). `CLAUDE_CODE_PLUGIN_DIRS` requires Claude Code v2.1.280 or later. Managed settings can turn off `--plugin-dir` and `CLAUDE_CODE_PLUGIN_DIRS`. See [Flags that load a plugin for one session](</docs/en/plugins/cli-reference#flags-that-load-a-plugin-for-one-session>). To test a plugin together with a plugin it depends on, see [Test a plugin and its dependency locally](</docs/en/plugins/dependencies#test-a-plugin-and-its-dependency-locally>). - -### - -​ - -Make a plugin load in every session - -Your personal skills directory is `~/.claude/skills/`. Claude Code loads any folder there that contains a `.claude-plugin/plugin.json` as a plugin in every session, with no flag and no install step. `claude plugin init` scaffolds one of these plugins for you. - -#### - -​ - -Scaffold the plugin with `claude plugin init` - -`claude plugin init` writes a starter plugin under `~/.claude/skills/`. Requires Claude Code v2.1.157 or later. Scaffold one from your shell: - - claude plugin init my-tool - -The command creates `~/.claude/skills/my-tool/` with a `.claude-plugin/plugin.json` and a root `SKILL.md`. It prints `✔ Created plugin "my-tool" at ~/.claude/skills/my-tool` followed by `It will auto-load next session as my-tool@skills-dir. Run /reload-plugins to load it now.` Pass `--with skills` to have `claude plugin init` scaffold a skill under `skills/` for you. The other `--with` values are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-init>). - -#### - -​ - -Name the plugin’s skills - -The root skill at `~/.claude/skills/my-tool/SKILL.md` is also a personal skill, so you invoke it as `/my-tool`, not `/my-tool:my-tool`. Skills you add under `skills/` inside the plugin get the plugin-name prefix, such as `/my-tool:example`. - -#### - -​ - -Stop loading the plugin - -To stop loading a scaffolded plugin, delete its directory, or run `claude plugin disable my-tool@skills-dir` in your shell with the `my-tool@skills-dir` name that `claude plugin init` printed. In the ID `my-tool@skills-dir`, `skills-dir` stands where a marketplace name would, because the plugin loads from your skills directory rather than from a marketplace. - -#### - -​ - -Share the plugin through a repository - -`claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, so it loads for you in every project. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. - -## - -​ - -Test and debug - -When a change to your plugin doesn’t show up, work through these checks in order. Each one tells you what Claude Code did with the plugin: - - 1. In your shell, run `claude plugin validate <path>`. It checks the manifest and the frontmatter of every skill, agent, and command file, and exits `0` on `Validation passed`. Add `--strict` to fail on warnings too. Exit codes and directory handling are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-validate>). - 2. In the running session, run `/reload-plugins` to apply edits you made on disk. It prints one `Reloaded:` line with counts. Then confirm a skill loaded by typing its `/plugin-name:skill` command, or by finding the plugin in the `/plugin` **Installed** tab. - 3. In the same session, run `/plugin`. The **Installed** tab lists your plugin and, in the plugin’s details, the components Claude Code found. The **Errors** tab lists what failed to load and why, such as a path in your manifest that doesn’t exist. - 4. Back in your shell, run `claude plugin list`. It prints session-only and skills-directory plugins in their own sections with `Status: ✔ loaded` or the load error. To include the plugin you’re developing, pass `--plugin-dir` with its path before `plugin list`. - -To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the [debug log](</docs/en/hooks#debug-hooks>), which shows which hooks matched, their exit codes, and their output. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. - -### - -​ - -A component path isn’t found - -The **Errors** tab of `/plugin` shows `<component> path not found: <path>`, for example `commands path not found`. A component path in your manifest, such as `commands`, `skills`, `agents`, or `hooks`, points at nothing. Fix the path or create the directory, then run `/reload-plugins` in the session. See [`commands path not found`](</docs/en/plugins/troubleshooting#commands-path-not-found>). - -### - -​ - -`--plugin-dir` at a marketplace root doesn’t load the plugins under `plugins/` - -`--plugin-dir` takes the plugin’s root directory, the one that contains `.claude-plugin/plugin.json` and the component directories such as `skills/`. If you point it at a marketplace root instead, Claude Code doesn’t read `marketplace.json`, so a plugin under `plugins/` doesn’t load, and you see no error. Point the flag at one plugin’s folder, or add the marketplace. See [the troubleshooting entry](</docs/en/plugins/troubleshooting#plugin-dir-loads-a-plugin-with-no-components>). - -### - -​ - -The plugin loads but its skills are missing - -The `skills/` directory is inside `.claude-plugin/`, or a `skills` entry in the manifest points at a file. Move `skills/` to the plugin root, point each `skills` entry at a directory that contains `SKILL.md`, and run `/reload-plugins` in the session. See [Plugin loads but its skills are missing](</docs/en/plugins/troubleshooting#plugin-loads-but-its-skills-are-missing>). - -### - -​ - -The `userConfig` dialog never appears - -The dialog for your plugin’s [`userConfig`](</docs/en/plugins/components#user-configuration>) options is part of installing through `/plugin` in a session. Loading with `--plugin-dir` doesn’t show it, and neither does `claude plugin install` in the shell. With the plugin loaded, run `/plugin configure <plugin-name>` in the session to open it. See [The `userConfig` dialog never appears](</docs/en/plugins/troubleshooting#the-userconfig-dialog-never-appears>). - -### - -​ - -Check that the plugin changes Claude’s behavior - -A plugin that loads without errors can still fail to steer Claude the way you intend. `claude plugin eval`, which you run in your shell, runs your test cases with and without the plugin and scores the difference. See [Test plugins with evals](</docs/en/plugin-evals>), starting with [Create your first eval suite](</docs/en/plugin-evals#create-your-first-eval-suite>). - -## - -​ - -Convert an existing `.claude/` setup - -If you already have skills, agents, or hooks under a project’s `.claude/` directory, you can move them into a plugin without rewriting them. Run the commands in these steps from the project root, which is the directory that contains `.claude/`, because the `cp` paths are relative to it. - -1 - -Create the plugin structure - -Create the plugin directory and its `.claude-plugin/` folder alongside `.claude/`. You can move the plugin anywhere afterwards. - - mkdir -p my-plugin/.claude-plugin - -Create `my-plugin/.claude-plugin/plugin.json`: - -my-plugin/.claude-plugin/plugin.json - - { - "name": "my-plugin", - "description": "Migrated from standalone configuration", - "version": "1.0.0" - } - -2 - -Copy your existing files - -Copy each configuration directory you have to the plugin root, and skip the command for any directory you don’t have. - - cp -r .claude/commands my-plugin/ - - cp -r .claude/agents my-plugin/ - - cp -r .claude/skills my-plugin/ - -Run `ls -a my-plugin` to confirm that each directory you copied appears next to `.claude-plugin`. - -3 - -Move your hooks - -If you have hooks in `.claude/settings.json` or `.claude/settings.local.json`, create a hooks directory: - - mkdir -p my-plugin/hooks - -Create `my-plugin/hooks/hooks.json` and copy the `hooks` object from your settings file into it. The format is the same.This example shows the shape with one hook that runs a linter on each file Claude writes or edits. Replace the example with your own `hooks` object. - -my-plugin/hooks/hooks.json - - { - "hooks": { - "PostToolUse": [ - { - "matcher": "Write|Edit", - "hooks": [{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npm run lint:fix" }] - } - ] - } - } - -4 - -Test the migrated plugin - -Load the plugin for a session: - - claude --plugin-dir ./my-plugin - -Check each component under its new name: - - * **Skills** : run `/my-plugin:deploy` for a skill that was `/deploy`. - * **Subagents** : ask Claude to use the `my-plugin:reviewer` agent for an agent that was `reviewer`. - * **Hooks** : trigger the event each hook matches. - -If something is missing, work through Test and debug. - -While the originals are still under `.claude/`, they stay loaded alongside the plugin’s copies: - - * **Skills and agents** : the two sets don’t collide, because the plugin’s skills and agents carry the `my-plugin:` prefix. `/deploy` and `/my-plugin:deploy` both work, and Claude sees `reviewer` and `my-plugin:reviewer` as two subagents. - * **Hooks** : hooks have no prefix, so a hook that is in both your settings file and `hooks/hooks.json` runs twice each time its event fires. - -After you’ve confirmed the plugin works, delete the originals from `.claude/` and remove the `hooks` object from your settings file. +`claude-code/index.d.ts`| Every event and its input and result, every mods API namespace and method, and the elements each surface can draw +`claude-code-tools/index.d.ts`| The built-in tools’ inputs and results, so that checking `e.tool === 'Bash'` narrows `e` +`claude-code-mcp/index.d.ts`| The inputs of the MCP tools that were connected the last time you saved a file in the mod +`index.d.ts` in a directory named for a plugin| What that plugin adds to the mods API. There’s one directory for each plugin your `plugin.json` lists under `dependencies`. +`tsconfig.json`| Compiler options that fit a hooks module + +If your mod has no `tsconfig.json` of its own, Claude Code adds one at the mod’s root that extends the generated one, so your editor and `tsc -p ./first-mod` type-check the mod without more setup. The events and methods can change between releases, so trust these files over any page, this one included, when they disagree. `claude-code/index.d.ts` is the fullest reference for your build, with a comment and an example for every mods API method. To look something up, search the file for its name, such as `'tool.call'`. + +### + +​ + +Check what Claude Code reads from your mod + +To see your mod the way Claude Code sees it, without running your code or starting a session, use `claude plugin validate`. It checks the manifest and runs the same static analysis on the hooks module’s source that Claude Code runs when it loads a mod. In your shell, run it on the mod’s directory: + + claude plugin validate ./first-mod + +For `first-mod`, the output includes these lines. + + ❯ ./register.js hooks: session.start, tool.call, command.run{command=tally}, ui.render{component=Spinner} + ❯ ./register.js calls: $.command.register, $.ui.invalidate + + ✔ Validation passed + +The `hooks:` line lists the events your module hooks, each with its filter in braces. The `calls:` line lists every mods API method it calls. A module that reads or sets environment variables also gets `env reads:` and `env writes:` lines, and one that uses [`$.state`](</docs/en/plugins/mods/interface#keep-state>) gets `state reads:` and `state writes:`. If an event you meant to handle is missing from the first line, Claude Code won’t call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`. Follow these rules so that static analysis can find every hook and call: + + * Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. You can pass `$` to a function declared at the top level of the same file, and for a function of yours named `loadNotes`, the `calls:` line then reads `$.store.get (via loadNotes)`. Passing `$` to a method, a function defined inside the hook, or a function you import from another of your files fails validation. The `read` and `update` functions that [`$.state`](</docs/en/plugins/mods/interface#keep-state>) uses are the imports that can take it. Don’t assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`. + * Write the event name in each `on` call as a string literal, such as `'tool.call'`. A variable, or a loop over a list of names, fails with `the event name passed to on() is not a string literal`. + * Inside `register`, don’t declare a second variable or parameter named `on`. Validation fails with `"on" is declared again (shadowed)`. + * Import only from files inside the plugin directory, by relative path. The one bare import allowed is `claude-code`, for types and a few helpers. + * Use `import` declarations at the top of the file, as in `import { name } from './file.js'`. A dynamic `import()` fails with `a dynamic import(); a hooks module imports its own files with an import declaration`. + * Write every file as an ES module, with `import` and not `require`. The [reference](</docs/en/plugins/mods/reference#files>) lists the file extensions Claude Code loads. + +### + +​ + +Test the mod + +You can write automated tests for a mod and run them from your shell with `claude plugin test`, with no session, sign-in, or network. A test fires the events your hooks handle and checks what the hooks did. This test fires two tool calls, runs `/tally`, and checks that the reply counts both. Save it as `first-mod/tests/first-mod.test.ts`: + +first-mod/tests/first-mod.test.ts + + import { expect, test } from 'claude-code/testing' + + test('/tally reports the tool calls the mod has seen', async ($, on) => { + // Answer each tool call in Claude Code's place, so no tool runs + on('tool.call', () => ({ result: 'ok' })) + + // Fire two tool calls, which the mod's tool.call hook counts + await $.tool.call({ tool: 'Bash', command: 'ls' }) + await $.tool.call({ tool: 'Read', file_path: 'README.md' }) + + // Run /tally and check the text its hook returns + const answer = await $.command.run({ command: 'tally', args: '' }) + expect(answer.text).toBe('Claude has made 2 tool calls since this mod loaded') + }) + +In your shell, run the tests from the `first-mod` directory: + + claude plugin test + +The output names each test and whether it passed, with timings that vary from run to run: + + tests/first-mod.test.ts: + (pass) /tally reports the tool calls the mod has seen [22.87ms] + + 1 pass + 0 fail + Ran 1 test across 1 file. [0.19s] + +[Test a mod](</docs/en/plugins/mods/test>) covers stubbing a model call or the store, and testing timers and drawings. + +## + +​ + +Share your mod + +A mod is a plugin, so you version it in the manifest and people install and update it with the `/plugin` commands. To give it to other people, [add it to a marketplace](</docs/en/plugins/publish>). Before you do, check the plugin’s `name`: `claude plugin validate` fails a name that [looks like one of Anthropic’s own](</docs/en/plugins/manifest-reference#name>), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with. Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don’t reach the installed copy until you increment the version and install again. ## @@ -401,10 +359,9 @@ Next steps - * [Plugin components](</docs/en/plugins/components>): add agents, hooks, MCP servers, LSP servers, and user configuration to your plugin - * [Test plugins with evals](</docs/en/plugin-evals>): write eval cases and run them with `claude plugin eval` to check how reliably the plugin guides Claude’s behavior - * [Publish a plugin](</docs/en/plugins/publish>): version it, put it in a marketplace, and submit it for review - * [Plugin structure and testing](<https://claude.com/docs/plugins/build>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only, and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) lists which load on each surface - * [Plugin manifest reference](</docs/en/plugins/manifest-reference>): every `plugin.json` field, path rule, and directory - * [Skills](</docs/en/skills>): write the skills your plugin provides - * [Anthropic’s plugins in the claude-code repository](<https://github.com/anthropics/claude-code/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review` + * [Draw in the interface](</docs/en/plugins/mods/interface>): open a pane, draw above the prompt, and add buttons and text fields + * [React to events](</docs/en/plugins/mods/events>): hook tool calls, prompts, and turns + * [Use the mods API](</docs/en/plugins/mods/api>): add commands and tools, call a model, and run work on a timer + * [Test a mod](</docs/en/plugins/mods/test>): stub what Claude Code would answer, and test timers and drawings + * [Troubleshoot a mod](</docs/en/plugins/mods/troubleshoot>): the reasons a mod does nothing, and the debug log + * [Read the source of built-in mods](</docs/en/plugins/mods/overview#read-the-source-of-built-in-mods>): complete plugins, each with its hooks module and tests
modified
--- a/create.md +++ b/create.md @@ -183,7 +183,7 @@ From a folder of plugins -To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. In an interactive session, you can also add and remove plugins in the folder after startup: +To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. You can also pass a folder that keeps a `.claude-plugin/marketplace.json` beside its plugin folders. As long as that `.claude-plugin/` directory holds no `plugin.json`, the plugin folders still load. Nothing is installed or enabled from the marketplace file, because Claude Code doesn’t read it. Loading plugins from such a folder requires Claude Code v2.1.281 or later. In an interactive session, you can also add and remove plugins in the folder after startup: * A subfolder you add loads as a new plugin once its manifest exists. * When you remove a subfolder, its plugin unloads.
modified
--- a/create.md +++ b/create.md @@ -4,7 +4,7 @@ * **Installing someone else’s plugin** : see [Install plugins](</docs/en/plugins/install>) * **Not sure you need a plugin** : see [Decide whether you need a plugin](</docs/en/plugins/overview#decide-whether-you-need-a-plugin>) on the overview - * **Your plugin’s users are on claude.ai or in Cowork** : the same folder installs there with a different subset of components. See [Plugins on claude.ai and in Cowork](<https://claude.com/docs/plugins/overview>) + * **Your plugin’s users are on claude.ai or in Cowork** : the same folder installs there with a different subset of components. See [Plugin structure and testing](<https://claude.com/docs/plugins/build>) and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) Start from the section that matches what you already have: @@ -112,7 +112,7 @@ Claude replies with a greeting. -The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. +The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. To have Claude scaffold and check a larger plugin with you, [install](</docs/en/plugins/install#install-a-plugin>) Anthropic’s `plugin-dev` plugin from the `claude-plugins-official` marketplace, which adds skills and agents for writing components such as skills, hooks, and MCP servers and for validating the finished plugin. Once it’s installed, run `/plugin-dev:create-plugin` followed by a description of the plugin you want, and Claude walks you through designing, creating, and validating it. ### @@ -124,7 +124,7 @@ * **Send it to a few people directly** : give them the plugin’s directory or a `.zip` of it, and nothing needs to be published. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>). * **List it in your own marketplace** : teammates add your marketplace once and install the plugin by name, and they receive your updates. See [Publish through your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>). - * **Submit it to Anthropic’s community marketplace** : once it’s listed, anyone who adds that marketplace can install it. See [Submit to the community marketplace](</docs/en/plugins/publish#submit-to-the-community-marketplace>). + * **Submit it to Anthropic’s directory** : after it passes review, people can add it on claude.ai and in Cowork, and it reaches Claude Code through their account. See [Submit to Anthropic’s directory](</docs/en/plugins/publish#submit-to-anthropics-directory>). ### @@ -403,8 +403,8 @@ * [Plugin components](</docs/en/plugins/components>): add agents, hooks, MCP servers, LSP servers, and user configuration to your plugin * [Test plugins with evals](</docs/en/plugin-evals>): write eval cases and run them with `claude plugin eval` to check how reliably the plugin guides Claude’s behavior - * [Publish a plugin](</docs/en/plugins/publish>): version it, put it in a marketplace, and submit it to the community marketplace - * [Plugins on claude.ai and in Cowork](<https://claude.com/docs/plugins/overview>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only + * [Publish a plugin](</docs/en/plugins/publish>): version it, put it in a marketplace, and submit it for review + * [Plugin structure and testing](<https://claude.com/docs/plugins/build>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only, and the [component support table](<https://claude.com/docs/plugins/platform-support#compare-component-support-by-app>) lists which load on each surface * [Plugin manifest reference](</docs/en/plugins/manifest-reference>): every `plugin.json` field, path rule, and directory * [Skills](</docs/en/skills>): write the skills your plugin provides * [Anthropic’s plugins in the claude-code repository](<https://github.com/anthropics/claude-code/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review`
added
Show diff (413 lines)
--- a/create.md +++ b/create.md @@ -0,0 +1,410 @@ +A plugin is a directory of skills, agents, hooks, and MCP servers, plus a `plugin.json` file, called the manifest, that names the plugin. Claude Code loads the directory as one unit, so you can share it with teammates, install it in several projects, or publish it to a marketplace. This page is for people writing their own plugins. + +These cases are covered on other pages: + + * **Installing someone else’s plugin** : see [Install plugins](</docs/en/plugins/install>) + * **Not sure you need a plugin** : see [Decide whether you need a plugin](</docs/en/plugins/overview#decide-whether-you-need-a-plugin>) on the overview + * **Your plugin’s users are on claude.ai or in Cowork** : the same folder installs there with a different subset of components. See [Plugins on claude.ai and in Cowork](<https://claude.com/docs/plugins/overview>) + +Start from the section that matches what you already have: + + * **Nothing yet** : follow Create your first plugin, then Develop without a marketplace and Test and debug. + * **Files under`.claude/` already**: do the first-plugin walkthrough once to learn the layout, then follow Convert an existing `.claude/` setup. + +## + +​ + +Decide when to use a plugin + +Skills, agents, hooks, and MCP servers all work standalone in your project or home directory. Keep that standalone setup while it serves one project or only you. Make a plugin when you want to share the setup with teammates, install it in several projects, or publish versioned releases. When you move standalone skills, agents, hooks, and MCP config into a plugin, their location and names change: + + * **Where the files go** : under the plugin’s own directory, called the plugin root, as `skills/`, `agents/`, `hooks/hooks.json`, and `.mcp.json`. + * **How they’re named** : plugin skills and agents get the plugin name as a prefix, such as `/my-plugin:hello`, so two plugins can each provide a `hello` skill without colliding. + +To move an existing setup into a plugin, see Convert an existing `.claude/` setup. + +## + +​ + +Create your first plugin + +In this walkthrough, you create a plugin whose only component is one skill, a greeting, and run it with `--plugin-dir`, which loads a plugin for one session without installing it. A plugin can hold any mix of [components](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, and none is required; one skill is the smallest example that shows the layout. You need Claude Code [installed and signed in](</docs/en/quickstart#step-1-install-claude-code>). Open a terminal in the directory where you want to keep the plugin, such as `~/projects`, and run the commands in these steps from it. You can keep a plugin anywhere, because you pass its path to Claude Code when you start a session. + +1 + +Create the plugin directory + +Create the plugin directory, with a `.claude-plugin/` folder inside it to hold the manifest: + + mkdir -p my-first-plugin/.claude-plugin + +2 + +Write the manifest + +The [manifest](</docs/en/plugins/manifest-reference>) is a JSON file named `plugin.json` that tells Claude Code the plugin’s name and describes it. Save this one as `my-first-plugin/.claude-plugin/plugin.json`: + +my-first-plugin/.claude-plugin/plugin.json + + { + "name": "my-first-plugin", + "description": "A greeting plugin to learn the basics", + "version": "1.0.0", + "author": { + "name": "Your Name" + } + } + +The four fields do this: + + * **`name`** : required. It identifies the plugin and becomes the prefix on every skill and agent the plugin provides. Don’t put spaces in it. + * **`description`** : the text users see for the plugin in `/plugin`. + * **`version`** : optional. Setting it keeps users on that version until you change it; [Release a new version](</docs/en/plugins/host-marketplace#release-a-new-version>) says when to set or omit it. + * **`author`** : who to credit. `name` is required inside it; `email` and `url` are optional. + +Every other field is on the [manifest reference](</docs/en/plugins/manifest-reference#fields>).Only `plugin.json` goes inside `.claude-plugin/`. The skill you add next goes directly under `my-first-plugin/`, next to that folder. + +3 + +Add a skill + +This plugin’s one component is a skill. Each skill is a directory under `skills/` that contains a `SKILL.md` file. Create the skill’s directory: + + mkdir -p my-first-plugin/skills/hello + +Then create `my-first-plugin/skills/hello/SKILL.md` with this content: + +my-first-plugin/skills/hello/SKILL.md + + --- + name: hello + description: Greet the user with a friendly message + disable-model-invocation: true + --- + + Greet the user warmly and ask how you can help them today. + +The `disable-model-invocation: true` line means Claude doesn’t run the skill on its own, so only you trigger it. Remove that line from a skill you want Claude to run on its own. The skill’s command combines the plugin name and the skill’s name, so you run this one as `/my-first-plugin:hello`. For the other frontmatter fields, see the [skill frontmatter reference](</docs/en/skills#frontmatter-reference>). + +4 + +Validate the plugin + +Check the manifest and the skill’s frontmatter before you run anything: + + claude plugin validate ./my-first-plugin + +The command prints the manifest path it checked and `✔ Validation passed`. If it prints `✘ Validation failed` instead, each line above that result line names the field to fix. Look up each message under [`claude plugin validate` reports errors](</docs/en/plugins/troubleshooting#claude-plugin-validate-reports-errors>). + +5 + +Run Claude Code with the plugin + +Start a session with the plugin loaded: + + claude --plugin-dir ./my-first-plugin + +Once Claude Code starts, run the skill: + + /my-first-plugin:hello + +Claude replies with a greeting. + +The plugin loads only in sessions you start with `--plugin-dir`. To keep working on it without the flag, or to test a `.zip` build, see Develop without a marketplace. + +### + +​ + +Share your plugin + +A plugin you built with Create your first plugin exists only on your machine. When it’s ready for other people, there are three ways to get it to them: + + * **Send it to a few people directly** : give them the plugin’s directory or a `.zip` of it, and nothing needs to be published. See [Share a plugin without a marketplace](</docs/en/plugins/publish#share-a-plugin-without-a-marketplace>). + * **List it in your own marketplace** : teammates add your marketplace once and install the plugin by name, and they receive your updates. See [Publish through your own marketplace](</docs/en/plugins/publish#publish-through-your-own-marketplace>). + * **Submit it to Anthropic’s community marketplace** : once it’s listed, anyone who adds that marketplace can install it. See [Submit to the community marketplace](</docs/en/plugins/publish#submit-to-the-community-marketplace>). + +### + +​ + +Plugin layout + +Each kind of [component](</docs/en/plugins/components>), such as skills, agents, hooks, and MCP servers, goes in a fixed directory under the plugin root, which is the directory you pass to `--plugin-dir`. Add only the directories you use. To click through a complete plugin directory and read what each file does, open the [plugin explorer](</docs/en/plugins/components#explore-the-plugin-directory>). The table lists the directories most plugins start with, and the [full layout](</docs/en/plugins/manifest-reference#standard-layout>) lists the rest. + +Location| Contents +---|--- +`.claude-plugin/plugin.json`| The manifest. When you load a plugin with `--plugin-dir` and it has no manifest, Claude Code names the plugin after its directory +`skills/`| One `<name>/SKILL.md` directory per skill +`commands/`| Flat Markdown files, the older form of skills. Use `skills/` for new plugins +`agents/`| One Markdown file per subagent +`hooks/hooks.json`| Hook configuration: a top-level `"hooks"` key whose value has the same shape as `hooks` in a settings file +`.mcp.json`| MCP server definitions + +Only `plugin.json` goes inside `.claude-plugin/`. Components saved there don’t load.The plugin root is the plugin’s own directory, not `~/.claude/` itself. A `.mcp.json` saved at `~/.claude/.mcp.json` doesn’t load. + +## + +​ + +Develop without a marketplace + +You don’t need a [marketplace](</docs/en/plugins/overview#get-plugins-from-a-marketplace>) to run a plugin you’re writing. Load it directly from disk or a URL instead: + + * `--plugin-dir`: loads a directory or `.zip` archive for one session. + * `--plugin-url`: fetches a `.zip` archive from a URL for one session. + * `claude plugin init`: scaffolds a plugin under `~/.claude/skills/` that loads every session. + +If two plugins loaded in different ways share a name, see [Name conflicts](</docs/en/plugins/loading#name-conflicts>) for which one Claude Code keeps. + +### + +​ + +Load a plugin for one session + +You can load a plugin for a single session in three ways: from a directory or `.zip` archive on disk with `--plugin-dir`, from a URL with `--plugin-url`, or from an environment variable when you can’t add a flag. Each plugin loads for that session only, and nothing is written to your settings for it. When you edit the plugin’s files during the session, run `/reload-plugins` to load the changes. + +#### + +​ + +From a directory or `.zip` + +When you start `claude` from your shell, pass `--plugin-dir` with the plugin’s root directory or a `.zip` archive of it. Repeat the flag to load several plugins: + + claude --plugin-dir ./my-first-plugin --plugin-dir ./other-plugin.zip + +#### + +​ + +From a folder of plugins + +To load several plugins from one place, pass a folder that holds them, such as `--plugin-dir ./plugins`. Loading a folder of plugins requires Claude Code v2.1.265 or later. If the folder has no `.claude-plugin/` directory and no plugin components at its top level, Claude Code treats it as a folder of plugins. Each immediate subfolder that has a `.claude-plugin/plugin.json` manifest then loads as a separate plugin. Everything else in the folder is skipped without an error, including a subfolder that has no manifest. If a plugin in the folder doesn’t load, check that its subfolder has a `.claude-plugin/plugin.json`. In an interactive session, you can also add and remove plugins in the folder after startup: + + * A subfolder you add loads as a new plugin once its manifest exists. + * When you remove a subfolder, its plugin unloads. + +A message appears in the session for each of these changes. If loading or unloading a plugin mid-conversation would [invalidate the prompt cache](</docs/en/prompt-caching#enabling-or-disabling-a-plugin>), the change is held instead, and the message tells you to run `/reload-plugins` to apply it. + +#### + +​ + +From a URL + +When you start `claude` from your shell, pass `--plugin-url` with the address of a `.zip` archive, such as a build artifact your CI publishes: + + claude --plugin-url https://example.com/my-first-plugin.zip + +Claude Code downloads the archive at startup. To load several, repeat the flag or pass the URLs space-separated in one quoted argument. Point the flag only at archives you control or trust. If Claude Code can’t fetch the archive, or the archive is invalid, it starts without the plugin and records a plugin load error that you can review in the `/plugin` manager’s **Errors** tab. + +#### + +​ + +From an environment variable + +To load plugins in a session where you can’t add the `--plugin-dir` flag, list their absolute paths in the [`CLAUDE_CODE_PLUGIN_DIRS`](</docs/en/env-vars#variables>) environment variable instead. Claude Code loads each path as it loads a `--plugin-dir` path. These plugins load in addition to any you pass with `--plugin-dir`. [Project and local settings can’t set this variable](</docs/en/settings-reference#variables-claude-code-ignores-in-env>). `CLAUDE_CODE_PLUGIN_DIRS` requires Claude Code v2.1.280 or later. Managed settings can turn off `--plugin-dir` and `CLAUDE_CODE_PLUGIN_DIRS`. See [Flags that load a plugin for one session](</docs/en/plugins/cli-reference#flags-that-load-a-plugin-for-one-session>). To test a plugin together with a plugin it depends on, see [Test a plugin and its dependency locally](</docs/en/plugins/dependencies#test-a-plugin-and-its-dependency-locally>). + +### + +​ + +Make a plugin load in every session + +Your personal skills directory is `~/.claude/skills/`. Claude Code loads any folder there that contains a `.claude-plugin/plugin.json` as a plugin in every session, with no flag and no install step. `claude plugin init` scaffolds one of these plugins for you. + +#### + +​ + +Scaffold the plugin with `claude plugin init` + +`claude plugin init` writes a starter plugin under `~/.claude/skills/`. Requires Claude Code v2.1.157 or later. Scaffold one from your shell: + + claude plugin init my-tool + +The command creates `~/.claude/skills/my-tool/` with a `.claude-plugin/plugin.json` and a root `SKILL.md`. It prints `✔ Created plugin "my-tool" at ~/.claude/skills/my-tool` followed by `It will auto-load next session as my-tool@skills-dir. Run /reload-plugins to load it now.` Pass `--with skills` to have `claude plugin init` scaffold a skill under `skills/` for you. The other `--with` values are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-init>). + +#### + +​ + +Name the plugin’s skills + +The root skill at `~/.claude/skills/my-tool/SKILL.md` is also a personal skill, so you invoke it as `/my-tool`, not `/my-tool:my-tool`. Skills you add under `skills/` inside the plugin get the plugin-name prefix, such as `/my-tool:example`. + +#### + +​ + +Stop loading the plugin + +To stop loading a scaffolded plugin, delete its directory, or run `claude plugin disable my-tool@skills-dir` in your shell with the `my-tool@skills-dir` name that `claude plugin init` printed. In the ID `my-tool@skills-dir`, `skills-dir` stands where a marketplace name would, because the plugin loads from your skills directory rather than from a marketplace. + +#### + +​ + +Share the plugin through a repository + +`claude plugin init` writes the plugin to your personal skills directory at `~/.claude/skills/`, so it loads for you in every project. To make a plugin load for everyone in one repository, create the same layout yourself at `<project>/.claude/skills/<name>/`, including its `.claude-plugin/plugin.json`. See [Plugins shared through a repository](</docs/en/plugins/loading#plugins-shared-through-a-repository>) for the conditions under which Claude Code loads it. + +## + +​ + +Test and debug + +When a change to your plugin doesn’t show up, work through these checks in order. Each one tells you what Claude Code did with the plugin: + + 1. In your shell, run `claude plugin validate <path>`. It checks the manifest and the frontmatter of every skill, agent, and command file, and exits `0` on `Validation passed`. Add `--strict` to fail on warnings too. Exit codes and directory handling are on the [plugin commands reference](</docs/en/plugins/cli-reference#plugin-validate>). + 2. In the running session, run `/reload-plugins` to apply edits you made on disk. It prints one `Reloaded:` line with counts. Then confirm a skill loaded by typing its `/plugin-name:skill` command, or by finding the plugin in the `/plugin` **Installed** tab. + 3. In the same session, run `/plugin`. The **Installed** tab lists your plugin and, in the plugin’s details, the components Claude Code found. The **Errors** tab lists what failed to load and why, such as a path in your manifest that doesn’t exist. + 4. Back in your shell, run `claude plugin list`. It prints session-only and skills-directory plugins in their own sections with `Status: ✔ loaded` or the load error. To include the plugin you’re developing, pass `--plugin-dir` with its path before `plugin list`. + +To check an MCP server, run `/mcp` in the session to see the server’s status. When the server is healthy, `/mcp` lists it as connected. If it isn’t, see [MCP servers that don’t start](</docs/en/plugins/troubleshooting#invalid-mcp-server-config-for-and-mcp-servers-that-dont-start>). To check a hook, trigger the event it matches. For example, ask Claude to edit a file to trigger a `PostToolUse` hook. Then read the [debug log](</docs/en/hooks#debug-hooks>), which shows which hooks matched, their exit codes, and their output. The next sections cover the failures you’re most likely to hit while developing, and the [troubleshooting page](</docs/en/plugins/troubleshooting#build-a-plugin>) has the full entry for each. + +### + +​ + +A component path isn’t found + +The **Errors** tab of `/plugin` shows `<component> path not found: <path>`, for example `commands path not found`. A component path in your manifest, such as `commands`, `skills`, `agents`, or `hooks`, points at nothing. Fix the path or create the directory, then run `/reload-plugins` in the session. See [`commands path not found`](</docs/en/plugins/troubleshooting#commands-path-not-found>). + +### + +​ + +`--plugin-dir` at a marketplace root doesn’t load the plugins under `plugins/` + +`--plugin-dir` takes the plugin’s root directory, the one that contains `.claude-plugin/plugin.json` and the component directories such as `skills/`. If you point it at a marketplace root instead, Claude Code doesn’t read `marketplace.json`, so a plugin under `plugins/` doesn’t load, and you see no error. Point the flag at one plugin’s folder, or add the marketplace. See [the troubleshooting entry](</docs/en/plugins/troubleshooting#plugin-dir-loads-a-plugin-with-no-components>). + +### + +​ + +The plugin loads but its skills are missing + +The `skills/` directory is inside `.claude-plugin/`, or a `skills` entry in the manifest points at a file. Move `skills/` to the plugin root, point each `skills` entry at a directory that contains `SKILL.md`, and run `/reload-plugins` in the session. See [Plugin loads but its skills are missing](</docs/en/plugins/troubleshooting#plugin-loads-but-its-skills-are-missing>). + +### + +​ + +The `userConfig` dialog never appears + +The dialog for your plugin’s [`userConfig`](</docs/en/plugins/components#user-configuration>) options is part of installing through `/plugin` in a session. Loading with `--plugin-dir` doesn’t show it, and neither does `claude plugin install` in the shell. With the plugin loaded, run `/plugin configure <plugin-name>` in the session to open it. See [The `userConfig` dialog never appears](</docs/en/plugins/troubleshooting#the-userconfig-dialog-never-appears>). + +### + +​ + +Check that the plugin changes Claude’s behavior + +A plugin that loads without errors can still fail to steer Claude the way you intend. `claude plugin eval`, which you run in your shell, runs your test cases with and without the plugin and scores the difference. See [Test plugins with evals](</docs/en/plugin-evals>), starting with [Create your first eval suite](</docs/en/plugin-evals#create-your-first-eval-suite>). + +## + +​ + +Convert an existing `.claude/` setup + +If you already have skills, agents, or hooks under a project’s `.claude/` directory, you can move them into a plugin without rewriting them. Run the commands in these steps from the project root, which is the directory that contains `.claude/`, because the `cp` paths are relative to it. + +1 + +Create the plugin structure + +Create the plugin directory and its `.claude-plugin/` folder alongside `.claude/`. You can move the plugin anywhere afterwards. + + mkdir -p my-plugin/.claude-plugin + +Create `my-plugin/.claude-plugin/plugin.json`: + +my-plugin/.claude-plugin/plugin.json + + { + "name": "my-plugin", + "description": "Migrated from standalone configuration", + "version": "1.0.0" + } + +2 + +Copy your existing files + +Copy each configuration directory you have to the plugin root, and skip the command for any directory you don’t have. + + cp -r .claude/commands my-plugin/ + + cp -r .claude/agents my-plugin/ + + cp -r .claude/skills my-plugin/ + +Run `ls -a my-plugin` to confirm that each directory you copied appears next to `.claude-plugin`. + +3 + +Move your hooks + +If you have hooks in `.claude/settings.json` or `.claude/settings.local.json`, create a hooks directory: + + mkdir -p my-plugin/hooks + +Create `my-plugin/hooks/hooks.json` and copy the `hooks` object from your settings file into it. The format is the same.This example shows the shape with one hook that runs a linter on each file Claude writes or edits. Replace the example with your own `hooks` object. + +my-plugin/hooks/hooks.json + + { + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit", + "hooks": [{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npm run lint:fix" }] + } + ] + } + } + +4 + +Test the migrated plugin + +Load the plugin for a session: + + claude --plugin-dir ./my-plugin + +Check each component under its new name: + + * **Skills** : run `/my-plugin:deploy` for a skill that was `/deploy`. + * **Subagents** : ask Claude to use the `my-plugin:reviewer` agent for an agent that was `reviewer`. + * **Hooks** : trigger the event each hook matches. + +If something is missing, work through Test and debug. + +While the originals are still under `.claude/`, they stay loaded alongside the plugin’s copies: + + * **Skills and agents** : the two sets don’t collide, because the plugin’s skills and agents carry the `my-plugin:` prefix. `/deploy` and `/my-plugin:deploy` both work, and Claude sees `reviewer` and `my-plugin:reviewer` as two subagents. + * **Hooks** : hooks have no prefix, so a hook that is in both your settings file and `hooks/hooks.json` runs twice each time its event fires. + +After you’ve confirmed the plugin works, delete the originals from `.claude/` and remove the `hooks` object from your settings file. + +## + +​ + +Next steps + + * [Plugin components](</docs/en/plugins/components>): add agents, hooks, MCP servers, LSP servers, and user configuration to your plugin + * [Test plugins with evals](</docs/en/plugin-evals>): write eval cases and run them with `claude plugin eval` to check how reliably the plugin guides Claude’s behavior + * [Publish a plugin](</docs/en/plugins/publish>): version it, put it in a marketplace, and submit it to the community marketplace + * [Plugins on claude.ai and in Cowork](<https://claude.com/docs/plugins/overview>): the same plugin folder installs on claude.ai and in Cowork. Some components are Claude Code-only + * [Plugin manifest reference](</docs/en/plugins/manifest-reference>): every `plugin.json` field, path rule, and directory + * [Skills](</docs/en/skills>): write the skills your plugin provides + * [Anthropic’s plugins in the claude-code repository](<https://github.com/anthropics/claude-code/tree/main/plugins>): complete worked examples of the layout on this page, such as `feature-dev` and `code-review`