Long sessions in Claude Code make it easy to lose track of how much conversation context has accumulated, or what a file-deletion command is about to wipe out before it runs. Mods let you attach small custom programs to Claude Code to surface that state or step in before an action executes. Using a weather-style context indicator as the main example, this post walks through how mods run, how to build one, and what to watch out for when sharing them.

At a Glance

  • A mod is a small JavaScript or TypeScript file that runs alongside your Claude Code session. It can inspect session state, modify an action right before execution, or render custom status information in the terminal UI.
  • You can ask Claude in plain language to generate a mod for you, or write one yourself starting from an empty plugin folder.
  • Mods live inside plugins, which package extensions for installation, and connect to session activity through hooks that fire when specific events occur.
  • The post walks through three examples: Token Weather for live context usage, Blast Radius for previewing destructive commands, and Replay Theater for stepping through file edits.

About the Original Post

Addy Osmani published this tutorial on October 1, 2026. Following the examples requires Claude Code 2.1.287 or later. Because you can start by describing what you want in plain English without memorizing the API upfront, the guide fits regular Claude Code users who want to adapt the terminal workflow to their own habits. Source: Getting started with Claude Code mods .

How Mods Work Under the Hood

Whenever Claude Code calls a tool or finishes a response, it emits an event. An event signals that an action is happening, and a hook is the custom handler function you attach to run at that moment—for instance, logging changed files right after an edit completes.

Mod files sit inside a plugin directory, where hooks.json points to the code module to load. Inside that module’s register function, on(event, hook) binds specific events to your handler code.

Multiple hooks run in sequence like middleware. Calling next(e) hands the event to the next handler in the chain; once the chain finishes, Claude Code performs the underlying action. That structure gives each hook three distinct ways to act:

  • Observe: Let the original action run and record the outcome, such as tracking which files were edited during a turn.
  • Rewrite: Modify the event payload before passing it forward, such as swapping a command for a safer variant.
  • Respond: Return a result directly without calling next, stopping a tool call before it reaches execution.

Everything hinges on whether your handler calls next. Calling next lets the event pass through any remaining hooks to the original action and returns the result back up the chain. Returning early without next ends the action inside your hook.

Beyond tool calls, events cover prompt submission, turn start and end, custom slash commands, and ui.render for drawing terminal UI elements.

Modules execute inside a restricted sandbox rather than a browser DOM or a full Node runtime. Instead of standard system APIs, your code interacts with the session and terminal screen through the $ object provided by Claude Code.

Traditional configuration hooks spawn a fresh shell command each time they fire, whereas a mod stays alive for the entire session. Because it persists in memory, a mod can retain state across turns, update status lines, open interactive panels, and register new slash commands or model-callable tools.

First Example: Token Weather

The context window is the total span of conversation history and file content the model can hold at once. At the end of each turn, Token Weather reads how full that window is and renders a single status line above the prompt, pairing token counts with a weather label that shifts as usage climbs.

Context usageLabelWhat it signals
Under 25%ClearPlenty of headroom left
25–49%CloudyContext is steadily filling up
50–74%ShowersMore than half the window is used
75–89%StormRunning low on remaining context
90% and aboveCompact soonTime to consider compacting the conversation

Alongside total tokens used, the bar shows a 12-turn sparkline of recent history and the token delta from the latest turn, making both current capacity and recent growth rate visible at a glance.

The session screenshots from the original post show a 200k context window crossing 18%, 67%, and 81%.

Token Weather one-line status display showing a weather icon, token count, and recent turn sparkline

Figure 1. The single-line Token Weather indicator from the original post. Labels progress from Clear through Showers to Storm as the 200k window fills, while the mini bars on the right track per-turn growth. Source: Original post .

Each threshold crossing updates both the weather label and its color: 18% sits in Clear, 67% in Showers, and 81% in Storm.

The fastest way to build it is to launch claude and describe the indicator you want. With hot reload enabled—so Claude Code re-reads modified plugin files without a restart—the new status bar appears as soon as the turn finishes. Follow-up tweaks like lowering the Storm threshold to 70% can also be requested in plain English.

Writing the mod by hand takes roughly 80 lines of code:

  • Launch claude --plugin-dir to load the plugin under development, reloading automatically whenever you save a file.
  • Read current window consumption via $.session.usage() and store per-turn history in $.state. Plain module-level variables reset on hot reload, whereas $.state survives reloads for the life of the session.
  • Check plugin structure with claude plugin validate and verify behavior with claude plugin test.

Saving edits to tweak the UI reloads the module cleanly while keeping the turn history accumulated in $.state.

Sharing Mods and Two Larger Examples

To distribute a mod, you publish a marketplace manifest in a GitHub repository listing the available plugins. Other users register that repository with /plugin marketplace add, install the mod via /plugin install, and pick up changes with /reload-plugins.

A mod runs on your machine with the same OS permissions as Claude Code itself, and community-published mods are not official Anthropic code. The module sandbox limits which JavaScript APIs a mod can call directly, not whether installed code is safe to trust. Treat third-party mods like any software package: read the repository first and install only from authors you trust.

The post closes with two larger examples built on the same hook model:

  • Blast Radius: Intercepts destructive commands such as rm -rf, git reset --hard (which discards uncommitted work), and force-pushes before they run, computes their impact, and opens a confirmation panel with Proceed and Cancel options. In the original example, rm -rf build previews 9 files (1.1 MB) slated for deletion. Because the mod parses only the raw command string, it can miss command substitutions like $(…), shell aliases, or scripts that invoke rm internally. The author frames it as a helpful guardrail rather than a hard security boundary—use permission rules when you need guaranteed blocking.
  • Replay Theater: Observes Edit and Write tool calls during a turn without altering file writes, then lets you press r or run /replay to step through before-and-after diffs one change at a time.

Blast Radius panel in a narrow terminal previewing two uncommitted files that git reset –hard would discard

Figure 2. Blast Radius lists two uncommitted files that git reset --hard would wipe out, pausing execution until the user picks Proceed or Cancel. Source: Original post .

Replay Theater panel in a narrow terminal stepping through diffs on greet.js

Figure 3. Replay Theater walks through file edits one step at a time with Prev, Next, and Close controls. Source: Original post .

Non-destructive commands pass straight through without interruption; only flagged patterns pause for human confirmation.

Takeaways

The notes below are this blog’s own interpretation and hands-on testing, not part of the original post.

  1. Designing a mod gets much simpler once you decide upfront whether it observes, rewrites, or responds early. File-edit history belongs in a passive observer, whereas destructive commands warrant pausing execution to preview impact. The Blast Radius pattern translates directly to database tooling as well: before an agent runs a query, a hook can preview affected tables or row counts and wait for explicit approval.

  2. Keeping context fill level and recent per-turn growth visible removes the guesswork around when to compact a session. Pairing cumulative totals with recent deltas works well for other operational agent metrics too, such as tool-call latency or retry counts.

  3. Because installed mods inherit Claude Code’s local permissions, a flawed or malicious community mod can affect your workspace directly. Teams sharing internal mods should review authorship, file access, and shell execution paths before installation, just as they would for internal CLI packages.

  4. Rebuilding all three examples directly in Claude Code 2.1.289 surfaced a few practical constraints worth knowing before combining multiple mods:

    • Only one mod can own the single status line above the prompt at a time. When Token Weather occupies that slot, Replay Theater cannot place its r shortcut prompt in the same spot, so we exposed edit counts in the status bar and opened the viewer via /replay instead.
    • Because Blast Radius inspects only the literal command string, paths containing ~ or $HOME are not expanded and appear only as "not expanded". Remote commit counts for force-push warnings also reflect the last local git fetch rather than live remote state.
    • A single risky command can trigger both the mod’s confirmation panel and Claude Code’s built-in permission prompt back to back. In non-interactive runs such as claude -p, where nobody can answer a prompt, risky commands are always rejected.

    Running several mods together means sharing scarce UI slots and coordinating pre-execution hooks with built-in permission rules. Check where each mod renders and where it intercepts the hook chain before stacking them in one workspace.

What to Try First

  • Run claude --version in your terminal and confirm you are on 2.1.287 or later before testing the mod APIs from this guide.
  • Pick one metric you want visible throughout a session—for example, ask Claude to build a one-line mod showing current context percentage and the token jump from the previous turn—and watch how it behaves across a real task.
  • Read every file in a mod repository before installing or sharing it with teammates, checking which files it reads or writes and whether it intercepts or executes commands.

Original post: Getting started with Claude Code mods