Hooks reference changedhooks
Recorded here
Lines+17added
Lines−2removed
From line
1,096
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits113to this page, all time
The whole hunk
from line 1096, old and new numbered
/
This page is larger than the 256 KiB this site keeps, so one side of the diff below stops where the stored text does.
from line 1096
10961096| `agent_type` | The agent name, present when you start Claude Code with `claude --agent <name>` |
10971097| `session_title` | The current session title if one is already set, for example via `--name` or `/rename`. A hook that emits `sessionTitle` can check `session_title` first to avoid overwriting a title the user set explicitly |
10981098
1099When `source` is `"resume"` or `"fork"` and the transcript contains at least one response from Claude, SessionStart hooks also receive the four fields below. Your hook can use them to report what resuming a stale conversation costs before the first request, for example in a [`systemMessage`](#json-output). These fields require Claude Code v2.1.251 or later.
1100
1101| Field | Description |
1102| :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1103| `seconds_since_last_response` | Wall-clock seconds since the last response in the resumed transcript |
1104| `context_tokens` | Tokens the first request of the resumed session re-sends as its prompt |
1105| `prompt_cache_likely_expired` | `true` when the last response is older than the session's [prompt cache lifetime](/docs/en/prompt-caching#cache-lifetime) or a later compaction replaced the cached conversation |
1106| `estimated_cache_write_usd` | Estimated cost in US dollars of writing `context_tokens` to the prompt cache on the session's model, excluding the response |
1107
1108This example shows the input for a session resumed 90 minutes after its last response:
1109
10991110```json theme={null}
11001111{
11011112 "session_id": "abc123",
from line 1113
11021113 "transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
11031114 "cwd": "/Users/...",
11041115 "hook_event_name": "SessionStart",
1105 "source": "startup",
1106 "model": "claude-sonnet-5"
1116 "source": "resume",
1117 "model": "claude-opus-5",
1118 "seconds_since_last_response": 5400,
1119 "context_tokens": 182340,
1120 "prompt_cache_likely_expired": true,
1121 "estimated_cache_write_usd": 1.1396
11071122}
11081123```
11091124
from line 2873
28582873
28592874#### WorktreeCreate input
28602875
2861In addition to the [common input fields](#common-input-fields), WorktreeCreate hooks receive the `name` field. This is a slug identifier for the new worktree, either specified by the user or auto-generated, for example `bold-oak-a3f2`.
2862
2863```json theme={null}
2864{
2865 "session_id": "abc123",
2866 "transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
2867 "cwd": "/Users/...",
2868 "hook_event_name": "WorktreeCreate",
2869 "name": "feature-auth"
2870}
2871```
2872
2873#### WorktreeCreate output
2874
2875WorktreeCreate hooks don't use the standard allow/block decision model. Instead, the hook's success or failure determines the outcome. The hook must return the path to the created worktree directory:
2876
2877* **Command hooks** (`type: "command"`): print the path as the last non-empty line of stdout. Claude Code strips ANSI escape codes before reading that line, so shell startup banners printed before your `echo` are ignored. Redirect any other hook output to stderr.
2878* **HTTP hooks** (`type: "http"`): return `{ "hookSpecificOutput": { "hookEventName": "WorktreeCreate", "worktreePath": "/absolute/path" } }` in the response body.
2879
2880If the hook fails or produces no path, worktree creation fails with an error.
2881
2882Claude Code resolves a relative path against the directory the hook ran in, collapsing any `.` or `..` segments in it. If the resulting path isn't a directory Claude Code can enter, the session prints an error naming the path and exits with code 1.
2883
2884Claude Code refuses an absolute path that contains `.` or `..` segments, and any path that passes through a symlink below the repository root, because a symlink committed to the repository could redirect the worktree outside it. The error names the rejected component. Return a normalized path that doesn't pass through a symlink inside the repository. Before v2.1.216, worktree creation followed the hook's path without this screening.
2885
2886### WorktreeRemove
2887
2888R
2876In addition to the [common input fields](#common-input-fields), WorktreeCreate h
No line in this hunk matches that.