Skip to content

docs(claude-code): add token usage tracking to Langfuse hook#2623

Open
iamjjanga-ouo wants to merge 1 commit intolangfuse:mainfrom
iamjjanga-ouo:main
Open

docs(claude-code): add token usage tracking to Langfuse hook#2623
iamjjanga-ouo wants to merge 1 commit intolangfuse:mainfrom
iamjjanga-ouo:main

Conversation

@iamjjanga-ouo
Copy link

Summary

  • Add get_usage helper to extract token usage from assistant messages in the Claude Code transcript
  • Add aggregate_usage helper to sum token usage across multiple assistant messages in a turn
  • Pass usage_details (input, output, cache_creation_input_tokens, cache_read_input_tokens) to the Langfuse generation span in emit_turn

This enables token-level cost tracking in Langfuse when using the Claude Code hook integration.

Adds get_usage/aggregate_usage helpers and passes usage_details to
Langfuse generation spans, enabling input/output/cache token tracking.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 7, 2026

@iamjjanga-ouo is attempting to deploy a commit to the langfuse Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Mar 7, 2026

CLA assistant check
All committers have signed the CLA.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. documentation Improvements or additions to documentation labels Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants