Follow Discord
Sweep 03 Dec 2026 · 19:13Z Build v2.1.336 553 read Stable v2.1.332 Latest v2.1.336 Next v2.1.336 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · claude-code

React to events with a mod changedplugins/mods/events

Nearest release: v2.1.332, published 2 hours before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Upstream edited this page at 25 Nov 2026 01:03 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 25 Nov 2026 01:07 UTC.

Upstream edited
Recorded here
Lines+11added
Lines−8removed
From line 42 where the diff opens
First seen 1 Oct 2026 this site's first read of the page
Recorded edits34to this page, all time

The whole hunk

from line 42, old and new numbered
/
lines
from line 42
4242 
4343### Rewrite an event
4444 
45To change what Claude Code acts on, such as the text of a prompt, call `next` with a modified copy of the event. The event itself is immutable: it's deeply frozen, and assigning to a field throws. This hook trims each prompt before it's sent:
45To change what Claude Code acts on, call `next` with a modified copy of the event.
4646 
47This hook trims a prompt before it's sent:
48 
4749```javascript theme={null}
4850on('prompt.submit', async ($, e, next) => {
4951 // Pass on a copy of the event with its text changed
from line 53
5153})
5254```
5355 
54Later handlers and Claude Code receive the trimmed prompt and never see the original. You can also change the result: `await next(e)`, then return a copy of the result with a field replaced.
56For a prompt typed as plain text, later handlers and Claude receive the trimmed prompt.
5557 
5658### Answer an event
5759 
from line 258
256258 
257259### Rewrite or add to a prompt
258260 
259A `prompt.submit` hook sees each prompt before the turn starts, so it can rewrite the text or add to it. `e.text` is what was typed.
261To rewrite a prompt or add to it, handle `prompt.submit`, read the prompt from `e.text`, and return a value from this table:
260262 
261263| To do this | Return this |
262264| :- | :- |
263| Rewrite the prompt. The transcript and your [prompt history](https://code.claude.com/docs/en/interactive-mode.md#command-history) show the new text. | `next({ ...e, text: newText })` |
265| Rewrite a prompt typed as plain text. The transcript and your [prompt history](https://code.claude.com/docs/en/interactive-mode.md#command-history) show the new text. | `next({ ...e, text: newText })` |
264266| Add text only Claude reads, after the prompt | `next({ ...e, context: [...(e.context ?? []), extraText] })` |
265267| Stop the prompt from being sent | `{ drop: 'the reason' }` |
266268 
267This hook adds the current branch name for Claude whenever a prompt mentions a pull request:
269This hook adds the current branch name for Claude when a prompt mentions a pull request:
268270 
269271```javascript theme={null}
270272on('prompt.submit', async ($, e, next) => {
from line 282
280282 
281283When you send a prompt such as `open a PR for this change`, your message looks the same in the transcript, and Claude also reads a line such as `Current branch: feature/auth` after it. A prompt that doesn't mention a pull request goes through unchanged, and `git` doesn't run.
282284 
283To stop a prompt, return `{ drop: 'the reason' }` without calling `next`. The text goes back into the user's prompt input, and they see `Prompt dropped by a hook:` followed by your reason, so address the reason to them. The prompt still goes through in these cases:
285To stop a prompt, return `{ drop: 'the reason' }` without calling `next`. The text goes back into the user's prompt input, and they see `Prompt dropped by a hook:` followed by your reason, so address the reason to them. Don't rely on `drop` to stop every prompt. For example, a prompt goes through in these cases:
284286 
285287* **Your hook returns a `drop` after its `next(e)` call let the prompt through**: the turn still runs, and the hook [fails](#handle-a-hook-that-fails) with a message that includes `a drop after its next() was answered`
286288* **Your hook throws or times out**: Claude Code skips it and sends the prompt. [Add a `.catch` handler](#handle-a-hook-that-fails) so that a failure doesn't send a prompt the hook would have stopped.
289* **The prompt is the `/command` for a [skill with `context: fork`](https://code.claude.com/docs/en/skills#run-skills-in-a-subagent)**: your hook doesn't run. To stop the command, return `{ text: 'the reason' }` from a [`command.run`](https://code.claude.com/docs/en/plugins/mods/api#add-a-command) hook without calling `next`.
287290 
288291[Other events](https://code.claude.com/docs/en/plugins/mods/reference.md#prompts-and-what-claude-reads) cover the rest of what Claude reads: `prompt.section` for each section of the system prompt, `prompt.context` for the context sent with the first message, and `skill.prompt` for a skill's text. To change a section after a conversation has started, see [Send a changed system prompt section or tool description](https://code.claude.com/docs/en/plugins/mods/reference.md#break-prompt-cache). In a `skill.prompt` hook, you can also read [which plugin or file the skill came from](https://code.claude.com/docs/en/plugins/mods/reference.md#skill-prompt-fields).
289292 
from line 296
293296 
294297| Event | When it fires | What a hook can do |
295298| :- | :- | :- |
296| `turn.start` | A turn begins | Observe. `e.turnId` identifies the turn in the other two events. |
299| `turn.start` | A turn begins. A subagent's turn fires it with `e.agentId` set, which requires Claude Code v2.1.299 or later. | Observe. `e.turnId` identifies the turn in the other two events. |
297300| `turn.step` | Claude Code is about to send one request to the model. A turn with tool calls has several. `e.agentId` is set for a subagent's request. | Read each request's token usage, send it to a different model with `next({ ...e, model })`, or answer without calling the model |
298| `turn.complete` | The turn ended, including a turn the user interrupted, where `e.isAborted` is `true`. `e.answer` is Claude's final text, `e.durationMs` how long it took, and `e.usage` the turn's token totals. A subagent's turn fires it with `e.agentId` set. | Observe, or return an object with a `text` field, such as `{ text: 'Done in 12 seconds' }`, to show a line under the answer |
301| `turn.complete` | The turn ended, including a turn the user interrupted, where `e.isAborted` is `true`. `e.answer` is Claude's final text, `e.durationMs` how long it took, and `e.usage` the turn's token totals. A subagent's turn fires it with `e.agentId` set. | Observe. In the main conversation, return an object with a `text` field, such as `{ text: 'Done in 12 seconds' }`, to show a line under the answer. |
299302 
300303Write a `turn.step` hook as an async generator, because the event streams. `yield* next(e)` forwards the response as it streams and evaluates to the finished result. This hook logs how much of each request the Claude API served from the [prompt cache](https://code.claude.com/docs/en/prompt-caching.md):
301304 
Feedback