Transcript
0:00 We just added mods to Claude Code and with a mod, you can directly change how Claude Code itself works. You can change what it renders, what goes into a prompt, what tool calls it makes, and you can even add your own UI, skills and commands. And you can get really creative with these. So I always wanted more visibility into my context, so I made one that renders a live breakdown of it right above my prompt. I also wanted to see every agent in my project and not just the running one.
0:24 So here's a mod that lists all of them in a side pane where I can start one with just a single click. And when I'm recording, I would rather not have any email addresses on screen. So I also created a mod that hides them until I hover. And a mod is just a plugin, so the same plugin.json, same hook.json, but the only difference is that hook.json gets one extra key, modules. And this points at a TypeScript file, and that file is the actual mod.
0:48 Inside this file, you write functions that run inside of Claude Code itself. Claude Code has a few dozen internal events, so a tool call, permission check, running a message, emitting a prompt, and you register a function on one of those. It runs every time that event fires, right before Claude Code does its own thing. If you've ever used Express, that's pretty much just middleware built into Claude Code. And that function always gets the same three values.
1:13 So the first one is this dollar sign object, which is how you talk back to Claude Code. So rendering UI, calling the model, reading the files, all of that lives on here. And the second one is the event itself. So the actual data for whatever is happening right then. And you can change that data right here in the function body if you want, before you pass it on back to Claude Code. And passing it on is exactly what this third one is for next.
1:33 And this is the middleware part, so whatever you pass to next is what Claude Code actually goes and does. So if you change the command, that changed command is what runs. You don't have to call next though. If you don't call next and just return something yourself, then you're the one handling the event. And Claude Code just takes your answer instead of doing its own thing. So all three together, the dollar sign object is your connection to Claude Code itself, the event tells you what's happening, and next decides what Claude Code ends up doing with it.
2:02 To load it, you can start Claude Code with the plugin dir flag on that folder. Now the desktop app doesn't take flags, so you can just add the folder to your global settings file instead. The folder is watched, so whenever I save the file, the session I'm in picks up the change right away. Okay, so let's build a mod, so let's take that email one from the start and actually build it. What I want is that whenever Claude replies with an email address, it's hidden on screen unless I hover over it.
2:26 Rendering a reply is one of Claude Code's internal events, the render event, so that's the one I register my function on. The event data here is the text of the reply, right before it goes on screen. And then for every email address, I build a little block through that $send object that only shows its text on hover. And instead of calling next, I return that, so Claude Code renders my version. Then now when I ask Claude for Sam's email, the email address only shows when I hover over it.
2:53 And when I then ask Claude to write a message, it still uses the real email address because a model render only changes what shows up on screen. So the model never saw my version. A mod only sees the events that Claude Code exposes, and it runs in its own sandbox, so everything goes through this $send object. And a mod is just a plugin, so you can also share it as one. So you can put it in the marketplace repo, and people can install it just like any other plugin.