# SessionEnd Hook

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** SessionEnd, CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS

## Think of it like

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

## 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

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.

## Example code

```json
{
  "hooks": {
    "SessionEnd": [
      { "hooks": [{ "type": "command", "command": "./save-log.sh", "timeout": 10 }] }
    ]
  }
}
```

Give the cleanup ten seconds.

## Why it matters

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

## Common mistake

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

## Three principles

- **When a session ends.** Five reasons.
- **Cannot stop it.** Cleanup only.
- **1.5 seconds.** Unless raised.

## Related terms

- [SessionStart Hook](https://learn.benibix.com/term/ai/sessionstart-hook)
- [Hook Timeout](https://learn.benibix.com/term/ai/hook-timeout)

---

Source: https://learn.benibix.com/term/ai/sessionend-hook
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
