What it does
When a Claude Code session ends, this hook reads its transcript and sends one note to your own inbox with a form named Session ledger: the project folder, the model, the start time, the minutes, the number of model replies and the input, output and cache tokens. A session with no model replies sends nothing. Every non-interactive run, such as claude -p, sends a note too. The note does not include your prompt. To add the first 140 characters of the opening request, which can hold anything you typed, set HOMING_LEDGER_PROMPT=1.
What you need
A Homing account, and curl, jq and perl.
- 1 Create a key named Session ledger under API keys in the app. In a terminal, run the command below, paste the key, press Return, then Control-D. Revoke this key to stop the ledger.
mkdir -p ~/.config/homing && (umask 077; cat > ~/.config/homing/ledger-key)
- Get a note when Claude Code finishes or waits: A different job: a short note when a session finishes or needs you, to read or get a ping on your phone.
Make the form
- 1 In Settings, under Forms, choose New form, then Blank form.
- 2 Name it Session ledger. Its slug becomes session-ledger, which the script sends.
- 3 Add Project, Model and Started as Short text. Add Minutes, Messages, Input tokens, Output tokens and Cache tokens as Short text with the Format set to Number. Add First prompt as Long text, not required.
- 4 Choose Save form.
Save the script
- 1 In a terminal, run: mkdir -p ~/.claude/hooks && cat > ~/.claude/hooks/session-ledger.sh
- 2 Copy the script below, paste it into the terminal, press Return, then Control-D.
- 3 Run: chmod +x ~/.claude/hooks/session-ledger.sh
#!/usr/bin/env bash # SessionEnd hook: one note to self per Claude Code session, sent with the Session ledger form. # Needs curl, jq and perl. The key is read from ~/.config/homing/ledger-key. Exits 0 always. # The work runs detached, so leaving Claude Code is never delayed. To see Homing's reply, run: # printf '%s' '{"session_id":"…","transcript_path":"…","cwd":"…"}' | ~/.claude/hooks/session-ledger.sh work if [ "${1:-}" != work ]; then in=$(cat) { printf '%s' "$in" | perl -MPOSIX -e 'POSIX::setsid(); exec @ARGV' bash "$0" work; } >/dev/null 2>&1 & exit 0 fi key=$(cat "$HOME/.config/homing/ledger-key" 2>/dev/null) in=$(cat) get() { printf '%s' "$in" | jq -r "$1 // empty"; } sid=$(get .session_id); tp=$(get .transcript_path); cwd=$(get .cwd) { [ -n "$key" ] && [ -n "$sid" ] && [ -r "$tp" ]; } || exit 0 out=$(jq -sc --arg project "$(basename -- "${CLAUDE_PROJECT_DIR:-$cwd}")" --arg prompt "${HOMING_LEDGER_PROMPT:-0}" ' def secs: sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601; [.[] | .timestamp? // empty] as $t | ([.[] | select(.type == "assistant" and .message.usage and .message.model != "<synthetic>")] | unique_by(.message.id)) as $a | if ($a | length) == 0 then empty else ([.[] | select(.type == "user" and (.isSidechain | not) and (.isMeta | not)) | (.message.content // "") | if type == "string" then . else ([.[]? | select(.type? == "text").text] | first // "") end | select(length > 0 and (startswith("<") | not))] | first // "") as $p | ($t | max), {jsonrpc: "2.0", id: 1, method: "tools/call", params: {name: "send_message", arguments: { form: "session-ledger", subject: "Session: \($project)", message: "Claude Code session in \($project).", fields: ({ project: $project, model: ($a[0].message.model // ""), started: ($t | min), minutes: ((($t | max | secs) - ($t | min | secs)) / 60 | round), messages: ($a | length), input_tokens: ([$a[].message.usage.input_tokens // 0] | add), output_tokens: ([$a[].message.usage.output_tokens // 0] | add), cache_tokens: ([$a[].message.usage | (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0)] | add) } + (if $prompt == "1" then {first_prompt: $p[:140]} else {} end))}}} end' "$tp") || exit 0 last=$(printf '%s\n' "$out" | sed -n 1p | tr -d '"'); call=$(printf '%s\n' "$out" | sed -n 2p) [ -n "$call" ] || exit 0 if command -v sha1sum >/dev/null; then sha=sha1sum; else sha=shasum; fi h=$(printf 'session-ledger:%s:%s' "$sid" "$last" | $sha | cut -c1-32) id="${h:0:8}-${h:8:4}-5${h:13:3}-8${h:17:3}-${h:20:12}" printf '%s' "$call" | jq -c --arg id "$id" '.params.arguments.message_id = $id' | curl -sS -K <(printf 'header = "Authorization: Bearer %s"\n' "$key") --connect-timeout 3 --max-time 10 \ -w '\n%{http_code}\n' -H 'content-type: application/json' -H 'accept: application/json, text/event-stream' \ --data-binary @- https://api.tryhoming.com/mcp || true exit 0
When it cannot send
The hook returns at once and finishes on its own: with no key, no transcript or no network, nothing is sent and nothing is retried.
Add the hook
Add this under hooks in ~/.claude/settings.json, keeping any hooks already there. Start a new session afterwards: Claude Code reads its hooks when a session starts.
{ "hooks": { "SessionEnd": [ { "hooks": [ { "type": "command", "command": "~/.claude/hooks/session-ledger.sh" } ] } ] } }
Test it
Run this in a project folder. It sends one real note for your most recent session and prints Homing's reply. A good reply holds "status":"delivered" and ends in 200. A 200 with "isError":true is a refusal, and the receipt says why. A 401 means the key file is wrong or the key was revoked.
f=$(ls -t ~/.claude/projects/*/*.jsonl | head -1); printf '{"session_id":"%s","transcript_path":"%s","cwd":"%s"}' "$(basename "$f" .jsonl)" "$f" "$PWD" | ~/.claude/hooks/session-ledger.sh work
What the numbers mean
Minutes is the time from the first message to the last, idle time included. Messages counts the model's replies, tool rounds included. Claude Code writes its transcript a little behind the session, so the last turn can be missing. Subagents keep their own transcripts, so their tokens are not in the total. Each note covers the whole session so far: a session you resume and end again sends a second note with the larger totals. Firing the hook again for the same transcript is a replay: Homing answers with the first receipt and adds no note.
Send the notes on
- 1 Under Settings, Integrations, add one integration. On its Payload tab, set Which messages to By form and tick Session ledger.
- 2 For a Google Sheet, use Zapier, Make or n8n: choose Start from a template, then Form submission, and add the Google Sheets step in that tool. The fields arrive in an object named answers, the counts as numbers.
- 3 For Notion, choose a database, then map the fields to its columns on the Payload tab.
Keep it to your own notes
Choose By form, not Notes to self: Notes to self would send every note you write yourself to the sheet. A contact's agent can see this form and send it to you, and By form passes that on too. In Zapier, Make or n8n, keep only requests whose submitter.handle is yours. As of November 2026, the free plan allows three integrations on at a time.