Learning resourcesReviewed · Anthropic

Claude Code mods API guide

This is a Claude Code documentation page that teaches developers who already have a first mod how to use the mods API, and its main catch is that it depends on other pages for the full method list and on specific Claude Code versions for several features. It shows how a mod registers slash commands and tools for Claude, calls a model with optional prompt caching, runs timers and background jobs, submits prompts and notifications, messages other sessions, and reads files, runs processes, makes HTTP requests and reads settings. The examples are JavaScript hook functions that receive the API as their first argument, $. The page gives no price, licence or stability statement for mods.

Researched 15 Nov 2026

In short.

This is a Claude Code documentation page for developers who have built a first mod and want to use the mods API, and its main catch is that it is one page in a larger set: the complete method list, limits, setup and several linked topics are on other pages, and many features need specific Claude Code versions. The mods API is the set of methods, grouped in namespaces such as $.ui, $.fs, $.model and $.session, that every hook receives as its first argument. The page covers adding commands and tools, calling a model with prompt caching, timers and background work, what happens after the user interrupts a turn or a run hits its limits, messaging between sessions, and access to files, processes, HTTP and settings. It gives no price, licence or stability statement. Nothing in the page was executed, so the code is described as documented, not as tested.

Researched and written by an AI model and checked by a second AI model. How it works

This analysis covers the complete Use the mods API documentation page at [https://code.claude.com/docs/en/plugins/mods/api.md], as captured on 2026-11-15. The pages it links to are excluded, including the first-mod guide, the events page, the mods reference and limits, the interface, test and troubleshoot pages, and the MCP, hooks, prompt caching, Agent SDK and settings documentation. The captured page contains no licence or terms text, so rights and reuse are reported as unknown. Nothing was executed: no mod was built or run, no API call was made, and the described behaviour, version thresholds and code samples are the page's statements, not observed results.

The overview

What this resource is

This resource is a single documentation page titled Use the mods API, at [https://code.claude.com/docs/en/plugins/mods/api.md] on the Claude Code documentation site. The page describes the mods API as the set of methods a Claude Code mod calls to act: add commands and tools, call a model, run work between events, and reach the file system, processes and network. Every hook receives the API as its first argument, named $, with methods grouped in namespaces such as $.ui and $.fs. The page says events decide when a hook runs and the mods API is what the hook calls once it does.

The page treats a mod as something that ships inside a Claude Code plugin: a tool registered by a plugin named my-mod is shown to Claude as mcp__my-mod__ticket. It is a how-to guide with code samples, not the exhaustive reference. It sends readers to a separate reference page for every method and to a separate page for events.

Overall assessment

As a learning resource the page is specific and task-oriented. Each section starts from something a mod author wants to do, such as adding a /standup command, giving Claude a ticket lookup tool, labelling text with a small model, polling pull request checks every minute, or pinging another session. Each has a short code sample and a description of what the user sees. It also records behaviour that would otherwise cause confusion: a throwing hook is skipped, a taken command name throws, API failures do not reject a model call, and refused calls after an interruption return particular strings.

The main weakness is dependence on other pages. The complete method list, the types for a build, the limits page (including the default maxTokens and hook time limit values) and the event details are linked but not included. Several features are version-gated, and the page does not say how mature or stable the mods feature is. I did not run any code, so correctness rests on the page's own statements.

Who it is for

The audience is developers who write Claude Code mods. The page tells them to build a first mod before starting here, so it is not an introduction for people who only use Claude Code, and it is not a beginner's course in JavaScript. A reader needs to be comfortable with async functions and the hook shape shown in the samples: on(eventName, optional matcher, async ($, e, next) => ...).

It is also useful to plugin authors who want Claude to call their own tools or to react in the background. Organization administrators may find the notes on how an earlier mod in the chain can observe, rewrite or refuse another mod's calls relevant. People who install third-party mods can use it to understand how much access a mod has.

What the API can do, according to the page

Commands and tools: $.command.register adds a user-run slash command with a name, description and optional argumentHint, handled by a command.run hook. Returning { text } prints it in the transcript and Claude reads it, while returning {} prints nothing. An immediate: true option lets the command run while Claude is working. $.tool.register adds a tool for Claude with a description and a JSON Schema input, handled by a tool.call hook filtered to the full mcp__ name. An isDeferred: false option loads the tool upfront instead of leaving it to MCP tool search.

Models: $.model.complete sends a standalone prompt to a model you name, with optional system text and options such as maxTokens, timeoutMs and effort. $.model.fork sends the current conversation plus your prompt, using the session's model, system prompt and project context, with Claude's tools present but not callable by the model. The result of complete has isAnswered, text, reason and a usage object. Prompt caching is supported by passing prompt (or system) as an array of { text } blocks with cache: true on the last static block.

Background work and display: $.clock.every, after, now and sleep replace timers. $.ui.status, toast, log and notify show text without starting a turn, and $.ui.notify reports whether a terminal notification was sent. $.prompt.submit starts a turn from a background job, optionally as the user's own words with asUser: true. next.signal is an AbortSignal for long-running work.

Messaging and access: $.session.send delivers plain text to another session, a subagent or a teammate in an agent team. The session.receive and session.send events both let a mod observe messages, and session.receive also lets a mod keep an inbound message from Claude by returning { consumed: reason }. The page documents no such return behaviour for session.send. $.fs, $.process, $.http, $.store, $.env, $.settings, $.session and $.mcp cover files, processes, HTTP, a plugin-private JSON key-value store, environment variables, merged or per-source settings, session data such as the transcript, and calls to connected MCP servers.

Using it

What you need

The page states one prerequisite: build a first mod using the create guide before reading this page. It also assumes a working Claude Code installation and a mod that registers hooks. It does not list an operating system, runtime, account type or package manager.

Several features name minimum Claude Code versions: isDeferred: false needs v2.1.293 or later, arrays of blocks in prompt or system need v2.1.292 or later, the $.settings.read key argument needs v2.1.304 or later, and the post-interruption handling of refused calls needs v2.1.304 or later (except for $.prompt.submit and $.command.run). Mod prompts are refused at a --max-turns limit from v2.1.299, and subagent turns count toward that limit from v2.1.304. Model calls use the session's credentials, so a working Claude plan, API key or cloud provider setup is needed for $.model calls.

The hooks module has no Node.js APIs, no timer globals such as setTimeout, and no direct network or file access. Standard JavaScript and web APIs such as URL, TextEncoder, AbortController and crypto.subtle are available.

How it works

A mod is a set of hooks. Each hook is registered with on(event, optional matcher, handler) and receives $ (the mods API), e (the event) and next. A hook can pass the event along with return next(e), or answer it itself by returning a value, such as { text } for command.run or { result } for tool.call. A matcher such as { command: 'standup' } or { tool: 'mcp__my-mod__ticket' } narrows which events reach the hook. Commands and tools are registered in a session.start hook, and Claude Code waits for that hook before the first prompt.

Every API call is also an event named for its namespace and method without the $, for example fs.read for $.fs.read. A mod earlier in the chain can observe, rewrite or refuse a later mod's call, and the page says this is how an organization restricts what mods can reach. Hooks have a time limit on their own execution that does not count time waiting on next or on API calls, except $.clock.sleep.

Model requests: $.model.complete sends prompt as the user message; its system prompt contains a short attribution block followed by the optional system text. No CLAUDE.md or other project context is included. fork repeats the conversation's last request, so the Claude API can serve most of it from the prompt cache while it is still cached. Cache entries last five minutes after last use, taken from the user's settings, with an hour available through the subagentPromptCacheTtl setting. Up to four breakpoints are accepted per request. The page advises putting static shared content at the start of prompt, not system, for providers other than the Claude API directly and for mods that other people run, because the attribution block's fingerprint comes from the start of the user message.

Setup

The page has no install or packaging steps. For those it points to the first-mod guide and to a section on getting the types for your build. Both are on other pages that this analysis did not read.

What the page does cover is placement and registration. Register commands and tools inside a session.start hook, and register commands last or wrap the call in try and catch, because a taken name throws and a throwing hook is skipped along with the rest of its body. Choose a command name that no built-in command uses, which you can check by typing / in a session. A helper function that uses $ must be declared above register, because the page says validation refuses $ passed to a function declared inside register. Timers should be started from session.start. A claude -p run that loads a mod which submits a prompt at the end of every turn can end on its own if it is started with --max-turns or --max-budget-usd, or if the mod stops submitting prompts once its work is done. Otherwise it continues until someone stops it manually.

Worked example from the page

The page's tool example, from a plugin named my-mod, registers a tool called ticket in session.start with the description Look up a ticket by its id and return its title and status, and an input schema with one required string, id. A second hook, filtered to mcp__my-mod__ticket, calls $.http.fetch on [https://tickets.example.com/api/] followed by the URL-encoded id. It returns the response text when the response is ok, and otherwise the text Lookup failed with status followed by the status number. Per the page, Claude can then call the tool when asked about a ticket and reads that returned text as the result.

The page's command example registers /standup with an optional days argument and answers it with text built from e.args. A model example shows only the command.run hook for a /triage command. It does not register /triage; the page assumes the command has been registered separately with $.command.register in a session.start hook, as in the command example, so readers must add that registration themselves. The hook calls $.model.complete with model haiku, a system instruction requesting a one-word response (bug, feature, or question), maxTokens 20 and a 15-second timeout, then prints Label: followed by the answer or unknown. The example ticket address, the summarize function and the RULES string are placeholders, so the samples need adapting. They were not run for this report.

Assessment & evidence

Limitations and caveats

Scope: this is a guide, not a reference. The full reference and additional limits are linked elsewhere, but this page includes several numeric limits: a 30-second default timeout for $.process.run, a maximum of five redirects for $.http.fetch, up to four cache breakpoints per request and a five-minute default cache lifetime. The page itself does not say whether the mods feature is stable, experimental or limited to certain plans or platforms, so that is unknown.

Behaviour the page documents that can surprise authors: $.process.run rejects if the program cannot start or is still running at its timeout (30 seconds by default). $.http.fetch follows up to five redirects and drops headers such as Authorization on a cross-origin redirect. A mod can refuse a $.process.spawn call after the command has run, and nothing the command did is undone. After the user interrupts a turn, calls that start new work are refused until the user's next input, and queued prompts or commands are dropped, so authors must implement retries themselves. In claude -p and Agent SDK runs, calls can be refused at turn or budget limits or when input has ended. $.ui.notify's isSent: true means the notification was sent, not that the user saw it, and the terminal_bell channel shows no text. Prompt caching can silently fail when the prefix is too short, caching is disabled, a gateway strips cache_control, or another mod rewrites the start of the text.

Evidence limits: only this one page was read, no code was executed, and none of the described behaviour was observed.

Reasoning behind the assessment

The assessment rests on what the page states directly. It names specific methods, argument shapes, return values, failure results and version thresholds, and it connects them to concrete user-visible outcomes. That level of detail makes it useful for deciding whether the mods API can do a particular job, such as giving Claude a custom tool, labelling text with a small model, or polling in the background.

The caveats come from what the page leaves out. It does not say how mature the feature is, what it costs beyond the billing route for model calls, or under what licence the documentation is offered. It also sends readers elsewhere for setup, types and limits. Some promises, such as how a notification appears in each renderer, can only be confirmed by running Claude Code. I did not do that, so those statements remain the documentation's claims.

Related approaches mentioned on the page

The page does not compare the mods API with alternatives, so no ranking can be drawn from it. It does point to neighbouring mechanisms. Tools registered by a mod appear to Claude with an mcp__ name and fall under MCP tool search deferral, and $.mcp calls tools on connected MCP servers, so MCP servers are the related route for tools. It mentions user Notification hooks, which run with the type plugin_notification when a mod calls $.ui.notify. It mentions agent teams and cross-session messaging, which $.session.send builds on. It also mentions the Agent SDK and claude -p, where the page notes that mods run but some calls can be refused. Their trade-offs against the mods API are not given here and would need the linked pages.

Evidence base

The analysis rests on the full text of the Use the mods API page on the Claude Code documentation site, [https://code.claude.com/docs/en/plugins/mods/api.md], as captured on 2026-11-15. The whole page was available, and every claim above is taken from it. The code samples were read but not run, and none of the described behaviour was observed. Anything the page defers to a linked page, such as the full method list, the types for a build, the limits page and the event details, is reported as unknown.

Access & freshness

Costs

The page states no price for the mods API, for mods, or for Claude Code. Those costs are unknown from this evidence.

It does say who pays for model calls: both $.model.complete and $.model.fork use the session's credentials, so they bill to the user's plan, API key or cloud provider. No per-call amount, token price or model price appears on the page. Prompt caching is presented as a way to avoid paying the full input price for repeated static prefixes, but the page gives no figures, and it does not state the price of the one-hour cache option. The default maxTokens is on the limits page, which was not read.

The page also warns of an uncontrolled-cost pattern: a mod that submits a prompt at the end of every turn can make a claude -p run continue until stopped unless --max-turns or --max-budget-usd is set.

Rights, permissions and licence

The captured page contains no licence, copyright notice or terms of use. Whether the text or code samples may be copied or redistributed is therefore unknown from this evidence, and the report offers no file for distribution.

On runtime permissions, the page says a mod reaches the file system, processes and network with the same permissions as the user running Claude Code. So an installed mod can read and write files, run commands (the page says $.process.run takes an argument list and uses no shell, but does not state the same for $.process.spawn), fetch URLs, read merged settings including the managed policy source, and send messages to other sessions. The page also says an earlier mod in the chain can observe, rewrite or refuse these calls. For messages, a session set to refuse inbound messages refuses them before session.receive fires, and the sender's name on a received message is whatever the sender wrote, so decisions should not rest on it.

Freshness

The captured text shows no publication date, last-updated date or page version. The only time reference is the capture on 2026-11-15. The page does refer to Claude Code versions v2.1.292, v2.1.293, v2.1.299 and v2.1.304, so it reflects a release at least as new as v2.1.304. The current Claude Code release and whether the page has changed since capture are unknown. Because the API has version-gated behaviour and the page says that earlier versions reject or ignore some options, readers should check their installed version against the thresholds above and compare with the live page before relying on a detail.

What to do next

If you are new to mods, build the first mod from the create guide before using this page. Run claude --version and compare it with the version thresholds listed above if you want prompt-cache blocks, isDeferred: false, settings key reads or the post-interruption behaviour.

When writing a mod, register commands last in session.start or wrap the call in try and catch. Always check r.isAnswered and r.reason on model calls, and put shared static text first in prompt if other people will run the mod. Add --max-turns or --max-budget-usd to claude -p runs that load a mod which submits prompts. Keep retry logic in a turn.complete hook if background prompts must survive an interruption.

When deciding whether to install someone else's mod, remember that it acts with your user permissions and can read files and settings, run commands and make HTTP requests. Review what its hooks call. For limits, the full method list and the types, read the linked reference and create pages, which are outside this analysis.

Evidence for this report

selected-page.txtselected · checked 2026-11-15