October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

Claude Code Hook JSON: What Arrives on Stdin and Which Fields Vary

Claude Code command hooks receive JSON on stdin; HTTP hooks receive it as a POST body. Learn which fields are shared, which depend on the event, and how to parse optional inputs safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Claude Code sends command hooks a JSON object on standard input; HTTP hooks receive the same JSON as the POST request body. The payload combines context fields with fields for the event that fired, so branch on hook_event_name and check optional fields rather than treating every hook as one fixed schema. Anthropic’s Hooks reference is the authority for the exact, version-sensitive event inputs.

How Claude Code delivers hook input

The transport depends on the handler: command hooks read JSON from stdin, while HTTP hooks receive JSON in the request body. The event name, hook_event_name, tells your handler which event-specific fields to expect. Not every event contains every common field, and newer fields can require a minimum Claude Code version.

As an Amazon Associate I earn from qualifying purchases.

Model the input as a shared context layer plus an event-specific layer, not as one universal payload. Your parser should first identify the event, then check for each field it needs.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common fields and their caveats

Anthropic documents these fields as common inputs, while noting that particular events may omit some of them:

#1 Best Overall
Lenovo 305 Wired USB-C Keyboard with Numeric Keypad, Full Size Keyboard, Slim Design, Black, USB-C Connectivity, Dedicated Function & AI Keys, for Gaming PC, Laptop, Desktop, Tablet, Home Office
  • Full-Size Layout: This Lenovo 305 USB-C keyboard offers a complete, full-size layout with a numeric keypad, making it ideal for data entry, calculations, and spreadsheets
  • Slim and Stylish: Ultra-thin design with low-profile keys delivers a modern, sleek look without compromising on typing comfort. Perfect for minimalist workspaces
  • USB-C Connectivity: Features a USB-C connection for fast, reliable data transmission, offering plug-and-play convenience with modern devices including laptops, PCs, and tablets
  • Durable and Responsive: Built to last, the Lenovo 305 keyboard is made with high-quality materials and features robust keys, offering excellent tactile feedback for long-lasting use
  • Versatile Functionality: Includes dedicated function keys, Windows keys, and multimedia controls, enhancing your productivity with every keystroke
Field What it contains Important caveat
session_id The current session identifier. Check for presence rather than assuming it is included in every event.
prompt_id The UUID for the user prompt being processed; useful for correlating hook output with OpenTelemetry prompt events. Absent until the first user input.
transcript_path Path to the conversation JSON file. The file is written asynchronously and may not yet contain the latest messages when the hook fires.
cwd The working directory when the hook runs. It describes the invocation context; do not assume it is a permanent project path.
scratchpad_dir The session scratchpad directory, when available. May be absent if there is no scratchpad or the temporary directory is unavailable; requires Claude Code v2.1.257 or later.
permission_mode The current mode: default, plan, acceptEdits, auto, dontAsk, or bypassPermissions. Not present on every event. Manual mode is represented as default, not manual.
effort An object with a level, such as low, medium, high, xhigh, or max. Appears in relevant tool-use contexts when the active model supports the effort parameter.
hook_event_name The name of the event that fired. Use it to select event-specific handling.
agent_id Identifies the subagent when a hook runs inside a subagent call. Distinguishes subagent hook calls from main-thread calls.
agent_type The agent name when running with --agent or inside a subagent. For a subagent, its type takes precedence over the session’s --agent value.

model is a special case: only SessionStart hooks can receive it, and it is not guaranteed to be present. PreModelSwitch and PostModelSwitch instead receive from_model and to_model.

What changes by event

The event catalog covers session setup, prompts, tool calls and permissions, subagents and tasks, stopping, workspace and configuration changes, compaction, model switches, MCP elicitation, and session termination. The following examples show why handling by event matters; they are not a complete substitute for the live schema.

Rank #2
Perixx PERIBOARD-422 Wired USB-C Mini Keyboard, USB Type C Connector, Black, US English Layout
  • USB-C Wired Connection: Wired keyboard with USB-C connectivity for tablets, laptops, and other USB-C devices. Connects directly without adapters for a stable, reliable plug-and-play experience.
  • Compact Mini Keyboard Design: PERIBOARD-422 features a space-saving layout (11.46 × 5.43 × 0.77 in; 0.68 lb). Lightweight and portable—ideal for home, office, travel, or limited desk spaces.
  • 12 Multimedia Function Keys: Integrated multimedia hotkeys offer quick access to audio and media controls. Use Fn + F1–F12 for efficient operation during work or entertainment (see manual for details).
  • Ideal for Educational Use: Wired design ensures stable performance, avoids wireless interference, and reduces security risks. No batteries or pairing required—perfect for classrooms and group learning environments.
  • Low-Profile Typing with Red Accents: Durable ABS build with quiet membrane switches and 3 mm key travel for comfortable, laptop-style typing. Slim profile with red bottom accents adds a modern touch.
Event or group Documented event-specific fields How to use them
SessionStart source (for example startup, resume, clear, compact, or fork); may also include model, agent_type, and session_title. Qualifying resumed or forked sessions in newer versions can include elapsed-time, context-token, and prompt-cache estimates. Use source to distinguish how the session began. Check optional fields before reading them.
Setup and InstructionsLoaded Setup includes trigger (init or maintenance). InstructionsLoaded includes instruction-file details such as file_path, memory_type, and load_reason; optional fields can describe path globs or the file that triggered a lazy load. Expect different structures even among events associated with session initialization.
UserPromptSubmit and UserPromptExpansion UserPromptSubmit includes prompt and may include a custom session_title. UserPromptExpansion includes expansion_type, command_name, command_args, command_source, and the original prompt. Pasted content can arrive expanded in the submitted prompt.
MessageDisplay turn_id, message_id, batch index, final, and new text in delta. Interactive sessions can invoke it for successive message batches; non-interactive runs invoke it once per assistant message.
PreToolUse tool_name, tool_input, and tool_use_id; MCP calls can also include mcp_server. tool_input depends on the tool. The mcp_server field requires Claude Code v2.1.274 or later.
PostToolUse Tool input and result. Some Bash executions can include tool_response.bashEditDiff. The Bash edit diff is a best-effort public beta feature requiring v2.1.269 or later; it may be incomplete and is for review, not policy enforcement.
PostToolUseFailure and PostToolBatch PostToolUseFailure includes tool identity and input, top-level error, and optional is_interrupt and duration_ms. PostToolBatch includes a tool_calls array with resolved calls, including tool name, input, use ID, and response. Error string formats vary by tool. Parse batch entries as individual tool-call records.
PermissionRequest and PermissionDenied PermissionDenied includes tool details and a reason; output can indicate whether retry is allowed in applicable cases. Use the exact event’s schema when handling permission decisions; do not infer it from tool-use input alone.
Notification message, optional title, and notification_type. Check whether title is present.
SubagentStart and SubagentStop SubagentStart includes agent_id and agent_type. SubagentStop includes stop_hook_active, agent identifiers/type, agent_transcript_path, and last_assistant_message. The ordinary transcript_path still points to the main session transcript.
TaskCreated and TaskCompleted task_id, task_subject, and optional task description and team/teammate names. Do not assume optional descriptions or names are populated.
Stop and StopFailure Stop includes stop_hook_active, last_assistant_message, background-task information, and session cron information. StopFailure includes an error type, optional error details, and optional last assistant message. Check the current event page for exact shapes.
TeammateIdle teammate_name and team_name. These identify the idle teammate and team.
ConfigChange, CwdChanged, DirectoryAdded, and FileChanged ConfigChange: configuration source and optional file_path. CwdChanged: old_cwd and new_cwd. DirectoryAdded: added directory and how it was added. FileChanged: file_path and change event. These describe different workspace or configuration changes; dispatch separately if the reaction differs.
WorktreeCreate and WorktreeRemove WorktreeCreate includes name; WorktreeRemove includes worktree_path. Use the field appropriate to the lifecycle event.
PreCompact and PostCompact Both include the compaction trigger; PreCompact can include custom instructions, while PostCompact includes the compacted summary. Before and after compaction have distinct data and timing.
PreModelSwitch and PostModelSwitch Include the models involved; current versions can add context and cache estimates for pre-switch cost reporting. Use from_model and to_model, not the SessionStart model field.
Elicitation and ElicitationResult MCP server and request/response details such as message, action, and optional form content. Check whether optional form content is supplied.
SessionEnd A reason explaining why the session ended. Handle termination based on the reported reason.

Parse defensively and choose the right source of truth

  • Read and decode the JSON, then branch on hook_event_name.
  • Check for a field before using it. Optional fields, version-gated fields, and fields omitted on particular events are normal.
  • Do not assume tool_input has the same shape for all tools. For example, a Bash input includes a command, while a Write input includes file_path and content.
  • For Windows path matching, normalize backslashes before applying path checks.
  • Do not use the transcript file as a guaranteed up-to-the-moment record. Anthropic says it is written asynchronously and can lag behind the in-memory conversation. For final response text, use last_assistant_message on Stop or SubagentStop when that is the data you need.
  • Confirm minimum Claude Code versions before depending on recently added fields. The live reference is version-sensitive.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Example: branch on the event name

This illustrative shell snippet reads the command-hook payload once and extracts fields only for the events it handles. It is not a tested script:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#!/usr/bin/env bash
payload=$(cat)
event=$(jq -r '.hook_event_name // empty' <<<"$payload")

case "$event" in
  PreToolUse)
    tool=$(jq -r '.tool_name // empty' <<<"$payload")
    ;;
  UserPromptSubmit)
    prompt=$(jq -r '.prompt // empty' <<<"$payload")
    ;;
esac

Anthropic’s official example reads tool_input.command from stdin for a PreToolUse Bash hook. That path is tool-specific: do not apply it to a different tool without checking that tool’s input structure.

Best Value
Lenovo 305 USB-C Wired Keyboard & Mouse Combo, Black, Spill-Resistant, Narrow Border, Adjustable Tilt, Full-Size Keyboard & Mouse, Compatible with Laptop, PC, Tablet, USB-C Connectivity Gaming Office
  • USB-C Wired Connection: Enjoy a stable and fast connection with the USB-C wired interface. Ideal for laptops, desktops, and tablets, this combo ensures consistent performance without interference
  • Full-Size Keyboard with Number Pad: The Lenovo 305 wired combo features a full-size keyboard with a convenient number pad, providing a comfortable typing experience for everyday tasks, data entry, and more
  • Spill-Resistant Design: Designed for durability, this combo features a spill-resistant keyboard that can handle minor accidents, protecting your equipment from unexpected mishaps
  • Sleek, Space-Saving Design: The narrow border design and thin profile make this keyboard combo ideal for smaller workspaces. The adjustable tilt feature ensures ergonomic comfort during long typing sessions
  • Reliable Mouse: The included full-size mouse is designed for precision and comfort, making it easy to navigate your computer with ease. Its responsive tracking ensures accurate cursor control
Rank #4
Sale
Macally USB C Wired Keyboard for Mac (USB C + USB A) – Compatible Keyboard for MacBook Pro/Air, iMac & MacMini – Compact Mac Keyboard
  • Dual (USB A + USB C) Connection: Built-in USB C and USB A plug ensure direct compatibility with modern and legacy computers without adapters, making this a reliable apple wired keyboard across multiple systems.
  • Space Saving Design: Slim, space efficient design keeps all essential keys while reducing desk clutter. This mac compatible keyboard usb c is ideal for minimalist workspaces, small desks, or travel.
  • One Touch Shortcut Keys: 13 dedicated shortcut keys deliver quick access to Mission Control, brightness, media, and volume controls, giving you familiar functionality expected from a mac keyboard wired for daily productivity.
  • Responsive Scissor Switch Keys: Low profile scissor switch keys offer stable, responsive typing with reduced noise and shorter key travel, creating a comfortable typing experience similar to a macbook keyboard.
  • Plug and Play Reliability: No batteries, charging, or wireless dropouts to manage. The wired type c keyboard delivers consistent, uninterrupted typing you can rely on at home, in the office, or on the go.
Rank #3
GEODMAER 65% Gaming Keyboard, Wired Backlit Mini Keyboard, Ultra-Compact Anti-Ghosting No-Conflict 68 Keys Membrane Gaming Wired Keyboard for PC Laptop Windows Gamer
  • 【65% Compact Design】GEODMAER Wired gaming keyboard compact mini design, save space on the desktop, novel black & silver gray keycap color matching, separate arrow keys, No numpad, both gaming and office, easy to carry size can be easily put into the backpack
  • 【Wired Connection】Gaming Keybaord connects via a detachable Type-C cable to provide a stable, constant connection and ultra-low input latency, and the keyboard's 26 keys no-conflict, with FN+Win lockable win keys to prevent accidental touches
  • 【Strong Working Life】Wired gaming keyboard has more than 10,000,000+ keystrokes lifespan, each key over UV to prevent fading, has 11 media buttons, 65% small size but fully functional, free up desktop space and increase efficiency
  • 【LED Backlit Keyboard】GEODMAER Wired Gaming Keyboard using the new two-color injection molding key caps, characters transparent luminous, in the dark can also clearly see each key, through the light key can be OF/OFF Backlit, FN + light key can switch backlit mode, always bright / breathing mode, FN + ↑ / ↓ adjust the brightness increase / decrease, FN + ← / → adjust the breathing frequency slow / fast
  • 【Ergonomics & Mechanical Feel Keyboard】The ergonomically designed keycap height maintains the comfort for long time use, protects the wrist, and the mechanical feeling brought by the imitation mechanical technology when using it, an excellent mechanical feeling that can be enjoyed without the high price, and also a quiet membrane gaming keyboard

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.