Dev.to
7/23/2026

The original title is: "Log Every Agent Invocation: Building Usage Analytics with Claude Code's Stop Hook and transcript_path"
Original: Log Every Agent Invocation: Building Usage Analytics with Claude Code's Stop Hook and transcript_path
Short summary
A detailed guide to building usage analytics for Claude Code agents by leveraging the Stop hook's transcript_path payload. A bash wrapper fans out to multiple hooks; inline Python parses JSONL transcripts, filters for Agent tool calls with subagent_type, and deduplicates by session_id and tool_use_id. The result is a persistent log of every agent invocation for observability and cleanup.
- •Stop hook payload includes transcript_path for full session logs
- •Python parses transcripts filtering for Agent tool calls with subagent_type
- •Deduplication via session_id + tool_use_id prevents duplicate entries on re-fires
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



