SessionEnd hook should receive session cost/token data

Resolved 💬 3 comments Opened Mar 25, 2026 by adunstan Closed Mar 29, 2026

Feature Request

The SessionEnd hook fires when a session terminates, but it receives no session metadata — specifically, no cost or token usage data.

This makes it impossible to automate session cost logging via hooks. The cost data exists (available via /cost), but it's only accessible interactively. A SessionEnd hook that received this data in its stdin JSON could enable automated cost tracking.

Proposed stdin payload for SessionEnd

{
  "session_id": "abc123",
  "total_cost_usd": 3.05,
  "duration_api_seconds": 303,
  "duration_wall_seconds": 980,
  "usage_by_model": {
    "claude-opus-4-6": {
      "input_tokens": 97,
      "output_tokens": 7900,
      "cache_read_tokens": 1500000,
      "cache_write_tokens": 331300
    }
  },
  "working_directory": "/home/user/project"
}

Use case

Appending a line to a cost log file at the end of every session, for tracking spend across projects. Currently this requires the user to manually run /cost and the assistant to remember to log it — which is unreliable.

Current workaround

None that is fully automatic. A Stop hook can remind the assistant, but the assistant still cannot invoke /cost itself, so the user must manually provide the data every time.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗