Skip to content
BENIBIX Learn

SessionEnd Hook

AI⌨️ Claude CodeConfiguration

Also known as SessionEnd, CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS

The event when a session ends. It is used to clean up or save logs.

Think of it like

It is like you turn off the lights. You do it as you leave the room.

Example

Emma's SessionEnd hook copies the day's log to a shared folder. She sets a ten second timeout so it has time to finish.

Why it matters

It is the last chance to tidy up or record what a session did.

Definition

SessionEnd is the hook event that fires when a Claude Code session ends. The matcher can pick the reason: clear, resume, logout, prompt_input_exit or other. It cannot stop the end. By default it gets only 1.5 seconds, so a slow clean-up needs its own timeout.

Example code

json
{
  "hooks": {
    "SessionEnd": [
      { "hooks": [{ "type": "command", "command": "./save-log.sh", "timeout": 10 }] }
    ]
  }
}
Give the cleanup ten seconds.

Common mistake

Leaving the default timeout on a slow script. It is cut off after 1.5 seconds.

Key takeaways

  1. 1
    When a session ends. Five reasons.
  2. 2
    Cannot stop it. Cleanup only.
  3. 3
    1.5 seconds. Unless raised.