Skip to content
AI Primer
release

Claude Code adds TypeScript mods for custom agent behavior

Claude Code mods let users change agent behavior and interfaces through TypeScript plugins. Examples include context displays, command previews and forked agents, and Claude can generate mods from prompts.

4 min read
Claude Code adds TypeScript mods for custom agent behavior
Claude Code adds TypeScript mods for custom agent behavior

TL;DR

Token Weather takes about 80 lines in the starter guide. Anthropic already uses mods for /diff and AGENTS.md support, and Claude can write new ones from a description, a pleasingly recursive trick celebrated in one launch-day reaction.

Event hooks

Mods make extensibility a first-class feature in Claude Code: modules receive events for prompts, tool calls, permission requests and UI drawing. Settings hooks run a shell command for each event; mods stay loaded and retain session state, according to the getting-started guide.

Each hook can take one of three paths:

  1. Observe: let the event run, then record an edit or read context usage.
  2. Rewrite: change what the next hook receives, such as replacing a shell command with a safer version.
  3. Answer: return directly without continuing the chain, such as refusing a tool call or implementing a command.

Token Weather

The sample reads context usage after each main-agent turn and retains the last 12 readings. Ordinary usage reads are free; requesting a breakdown triggers a token-count request, according to the guide.

Blast Radius

The sample pauses risky Bash calls for a Proceed-or-Cancel decision. Cancel returns a refusal to Claude; Proceed runs the original command unchanged, as the tutorial explains.

Replay Theater

/replay opens a docked, step-through review of the file edits Claude made during a turn.

Prompt-built mods

Claude can generate a mod from a description and iterate on it inside the running session, a workflow trq212 highlighted.

The getting-started workflow spells out the development mechanics:

  • Version: Claude Code 2.1.287 or later has mods enabled by default.
  • Hot reload: Claude asks for approval to enable it; subsequent changes reload in place without restarting the session.
  • State: values stored in $.state survive hot reloads. Module-level variables reset.
  • API contract: each load writes version-specific declarations into .claude-plugin/types/. The API can change between releases.
  • Validation and tests: claude plugin validate ./token-weather checks the plugin; claude plugin test ./token-weather runs its tests against the real Claude Code runtime.
  • Persistence: prompt-generated mod folders are session-only and cleaned up later. Keeping one requires copying it out and installing it as a normal plugin.

Anthropic is also adding ready-made samples to its Playground repository.

The next-steps mod suggests skills and other commands. trq212 published this installation sequence:

Forked agents and memory

Mods can spin off agents for additional work, including a custom classifier that runs every turn and selectively writes memories. In the launch thread, trq212 said converting plan mode into a mod was still in progress.

Machine access and managed permissions

Mods have Claude Code’s access to the machine, and Anthropic’s announcement says they are not sandboxed. Mods can stay private or be submitted to the Claude directory.

The announcement also specifies administrative controls:

  • Existing plugin controls apply, including allowing or blocking marketplaces.
  • On Team and Enterprise plans, and machines with managed settings, sec-default loads first. It prevents user-installed mods from overriding permission deny rules.
  • Admins can put their own mods first and include sec-default to preserve its restrictions.
  • Mods execute in load order: the first loaded sees the event first and the result last. A first-loaded audit mod can record every call other mods make.

Further reading

Discussion across the web

Where this story is being discussed, in original context.

On X· 3 threads
TL;DR2 posts
Event hooks1 post
Prompt-built mods2 posts
Share on X