Record Session Resume Cost Estimate
A resumed session after a long gap can trigger an expensive cache-write that doesn't show up anywhere unless something logs it. This records the fields Claude Code already computes on resume — idle time and estimated cost — to a durable file for a periodic cost review.
1. Save this as the hook script
#!/usr/bin/env python3
"""SessionStart hook — logs resume cost/idle-gap fields.
Wire with matcher "resume"."""
import json, sys, datetime
from pathlib import Path
data = json.load(sys.stdin)
log_path = Path(data.get("cwd", ".")) / ".claude" / "resume_cost_log.jsonl"
log_path.parent.mkdir(parents=True, exist_ok=True)
entry = {
"ts": datetime.datetime.utcnow().isoformat() + "Z",
"seconds_since_last_response": data.get("seconds_since_last_response"),
"estimated_cache_write_usd": data.get("estimated_cache_write_usd"),
}
with open(log_path, "a") as f:
f.write(json.dumps(entry) + "\n")
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/record-session-resume-cost-estimate.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"SessionStart": [
{
"matcher": "resume",
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/record-session-resume-cost-estimate.py"}
]
}
]
}
}
Before you use this
A hook runs with your local shell's permissions — review the script above before adding it, the same way you'd review any script you didn't write yourself. See our guide on hook security risks for the specific CVEs this category of feature has already produced.
Related hooks