Claude Code Analytics API
Programmatically access your organization’s Claude Code usage analytics and productivity metrics with the Claude Code Analytics Admin API.
The Admin API is unavailable for individual accounts. To collaborate with teammates and add members, set up your organization in Console → Settings → Organization.
The Claude Code Analytics Admin API provides programmatic access to daily aggregated usage metrics for Claude Code users, enabling organizations to analyze developer productivity and build custom dashboards. This API bridges the gap between our basic Analytics dashboard and the complex OpenTelemetry integration.
This API enables you to better monitor, analyze, and optimize your Claude Code adoption:
- Developer Productivity Analysis: Track sessions, lines of code added/removed, commits, and pull requests created using Claude Code
- Tool Usage Metrics: Monitor acceptance and rejection rates for different Claude Code tools (Edit, MultiEdit, Write, NotebookEdit)
- Cost Analysis: View estimated costs and token usage broken down by Claude model
- Custom Reporting: Export data to build executive dashboards and reports for management teams
- Usage Justification: Provide metrics to justify and expand Claude Code adoption internally
Admin API key required
This API is part of the Admin API. These endpoints require an Admin API key (starting with sk-ant-admin...
) that differs from standard API keys. Only organization members with the admin role can provision Admin API keys through the Anthropic Console.
Quick start
Get your organization’s Claude Code analytics for a specific day:
Set a User-Agent header for integrations
If you’re building an integration, set your User-Agent header to help us understand usage patterns:
Claude Code Analytics API
Track Claude Code usage, productivity metrics, and developer activity across your organization with the /v1/organizations/usage_report/claude_code
endpoint.
Key concepts
- Daily aggregation: Returns metrics for a single day specified by the
starting_at
parameter - User-level data: Each record represents one user’s activity for the specified day
- Productivity metrics: Track sessions, lines of code, commits, pull requests, and tool usage
- Token and cost data: Monitor usage and estimated costs broken down by Claude model
- Cursor-based pagination: Handle large datasets with stable pagination using opaque cursors
- Data freshness: Metrics are available with up to 1-hour delay for consistency
For complete parameter details and response schemas, see the Claude Code Analytics API reference.
Basic examples
Get analytics for a specific day
Get analytics with pagination
Request parameters
Parameter | Type | Required | Description |
---|---|---|---|
starting_at | string | Yes | UTC date in YYYY-MM-DD format. Returns metrics for this single day only |
limit | integer | No | Number of records per page (default: 20, max: 1000) |
page | string | No | Opaque cursor token from previous response’s next_page field |
Available metrics
Each response record contains the following metrics for a single user on a single day:
Dimensions
- date: Date in RFC 3339 format (UTC timestamp)
- actor: The user or API key that performed the Claude Code actions (either
user_actor
withemail_address
orapi_actor
withapi_key_name
) - organization_id: Organization UUID
- customer_type: Type of customer account (
api
for API customers,subscription
for Pro/Team customers) - terminal_type: Type of terminal or environment where Claude Code was used (e.g.,
vscode
,iTerm.app
,tmux
)
Core metrics
- num_sessions: Number of distinct Claude Code sessions initiated by this actor
- lines_of_code.added: Total number of lines of code added across all files by Claude Code
- lines_of_code.removed: Total number of lines of code removed across all files by Claude Code
- commits_by_claude_code: Number of git commits created through Claude Code’s commit functionality
- pull_requests_by_claude_code: Number of pull requests created through Claude Code’s PR functionality
Tool action metrics
Breakdown of tool action acceptance and rejection rates by tool type:
- edit_tool.accepted/rejected: Number of Edit tool proposals that the user accepted/rejected
- multi_edit_tool.accepted/rejected: Number of MultiEdit tool proposals that the user accepted/rejected
- write_tool.accepted/rejected: Number of Write tool proposals that the user accepted/rejected
- notebook_edit_tool.accepted/rejected: Number of NotebookEdit tool proposals that the user accepted/rejected
Model breakdown
For each Claude model used:
- model: Claude model identifier (e.g.,
claude-3-5-sonnet-20241022
) - tokens.input/output: Input and output token counts for this model
- tokens.cache_read/cache_creation: Cache-related token usage for this model
- estimated_cost.amount: Estimated cost in cents USD for this model
- estimated_cost.currency: Currency code for the cost amount (currently always
USD
)
Response structure
The API returns data in the following format:
Pagination
The API supports cursor-based pagination for organizations with large numbers of users:
- Make your initial request with optional
limit
parameter - If
has_more
istrue
in the response, use thenext_page
value in your next request - Continue until
has_more
isfalse
The cursor encodes the position of the last record and ensures stable pagination even as new data arrives. Each pagination session maintains a consistent data boundary to ensure you don’t miss or duplicate records.
Common use cases
- Executive dashboards: Create high-level reports showing Claude Code impact on development velocity
- AI tool comparison: Export metrics to compare Claude Code with other AI coding tools like Copilot and Cursor
- Developer productivity analysis: Track individual and team productivity metrics over time
- Cost tracking and allocation: Monitor spending patterns and allocate costs by team or project
- Adoption monitoring: Identify which teams and users are getting the most value from Claude Code
- ROI justification: Provide concrete metrics to justify and expand Claude Code adoption internally
Frequently asked questions
How fresh is the analytics data?
Claude Code analytics data typically appears within 1 hour of user activity completion. To ensure consistent pagination results, only data older than 1 hour is included in responses.
Can I get real-time metrics?
No, this API provides daily aggregated metrics only. For real-time monitoring, consider using the OpenTelemetry integration.
How are users identified in the data?
Users are identified through the actor
field in two ways:
user_actor
: Containsemail_address
for users who authenticate via OAuth (most common)api_actor
: Containsapi_key_name
for users who authenticate via API key
The customer_type
field indicates whether the usage is from api
customers (API PAYG) or subscription
customers (Pro/Team plans).
What’s the data retention period?
Historical Claude Code analytics data is retained and accessible through the API. There is no specified deletion period for this data.
Which Claude Code deployments are supported?
This API only tracks Claude Code usage on the Anthropic API (1st party). Usage on Amazon Bedrock, Google Vertex AI, or other third-party platforms is not included.
What does it cost to use this API?
The Claude Code Analytics API is free to use for all organizations with access to the Admin API.
How do I calculate tool acceptance rates?
Tool acceptance rate = accepted / (accepted + rejected)
for each tool type. For example, if the edit tool shows 45 accepted and 5 rejected, the acceptance rate is 90%.
What time zone is used for the date parameter?
All dates are in UTC. The starting_at
parameter should be in YYYY-MM-DD format and represents UTC midnight for that day.
See also
The Claude Code Analytics API helps you understand and optimize your team’s development workflow. Learn more about related features:
- Admin API overview
- Admin API reference
- Claude Code Analytics dashboard
- Usage and Cost API - Track API usage across all Anthropic services
- Identity and access management
- Monitoring usage with OpenTelemetry for custom metrics and alerting