Repository Public
1---2title: Claude Code Analytics API3url: https://platform.claude.com/docs/en/manage-claude/claude-code-analytics-api4description: Programmatically access your organization's Claude Code usage analytics and productivity metrics with the Claude Code Analytics Admin API.5---67<Tip>8 **The Admin API is unavailable for individual accounts.** To collaborate with teammates and add members, set up your organization in **Console → Settings → Organization**.9</Tip>1011The 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 provides more detail than the basic [Analytics dashboard](https://platform.claude.com/claude-code) without the complexity of the OpenTelemetry integration.1213This API enables you to better monitor, analyze, and optimize your Claude Code adoption:1415* **Developer productivity analysis:** Track sessions, lines of code added/removed, commits, and pull requests created using Claude Code16* **Tool usage metrics:** Monitor acceptance and rejection rates for different Claude Code tools (Edit, MultiEdit, Write, NotebookEdit)17* **Cost analysis:** View estimated costs and token usage broken down by Claude model18* **Custom reporting:** Export data to build executive dashboards and reports for management teams19* **Usage justification:** Provide metrics to justify and expand Claude Code adoption internally2021<Check>22 **Admin API credentials required.** These endpoints are part of the Admin API. You can access them using an [Admin API key](https://platform.claude.com/docs/en/manage-claude/admin-api-keys), an OAuth token with the `org:admin` scope, or a personal or service account key that isn't scoped to a workspace; workspace API keys don't work. See [Authentication](https://platform.claude.com/docs/en/manage-claude/admin-api#authentication) for details.23</Check>2425<Note>26 **Claude Platform on AWS:** The Claude Code Analytics API is not currently available. View Claude Code usage on the **Usage** page in the Claude Console instead.27</Note>2829<Note>30 **Claude Enterprise organizations:** Claude Code activity for claude.ai users is reported by the Claude Enterprise Analytics API, which uses an Analytics API key instead of an Admin API key. See [Analytics APIs](https://platform.claude.com/docs/en/manage-claude/analytics-api) to find which API and key type your organization needs.31</Note>3233## Quick start3435Get your organization's Claude Code analytics for a specific day:3637```bash cURL38curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\39starting_at=2025-09-08&\40limit=20" \41 -H "anthropic-version: 2023-06-01" \42 -H "x-api-key: $ANTHROPIC_ADMIN_KEY"43```4445<Tip>46 **Set a User-Agent header for integrations**4748 If you're building an integration, set your User-Agent header to help Anthropic understand usage patterns:4950 ```text wrap51 User-Agent: YourApp/1.0.0 (https://yourapp.com)52 ```53</Tip>5455## Claude Code Analytics API5657Track Claude Code usage, productivity metrics, and developer activity across your organization with the `/v1/organizations/usage_report/claude_code` endpoint.5859### Key concepts6061* **Daily aggregation:** Returns metrics for a single day specified by the `starting_at` parameter62* **User-level data:** Each record represents one user's activity for the specified day63* **Productivity metrics:** Track sessions, lines of code, commits, pull requests, and tool usage64* **Token and cost data:** Monitor usage and estimated costs broken down by Claude model65* **Cursor-based pagination:** Handle large datasets with stable pagination using opaque cursors66* **Data freshness:** Metrics are available with up to 1-hour delay for consistency6768For complete parameter details and response schemas, see the [Claude Code Analytics API reference](https://platform.claude.com/docs/en/api/admin/usage_report/retrieve_claude_code).6970### Basic examples7172#### Get analytics for a specific day7374```bash cURL75curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\76starting_at=2025-09-08" \77 -H "anthropic-version: 2023-06-01" \78 -H "x-api-key: $ANTHROPIC_ADMIN_KEY"79```8081#### Get analytics with pagination8283```bash cURL84# First request85curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\86starting_at=2025-09-08&\87limit=20" \88 -H "anthropic-version: 2023-06-01" \89 -H "x-api-key: $ANTHROPIC_ADMIN_KEY"9091# Subsequent request using cursor from response92curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\93starting_at=2025-09-08&\94page=page_MjAyNS0wNS0xNFQwMDowMDowMFo=" \95 -H "anthropic-version: 2023-06-01" \96 -H "x-api-key: $ANTHROPIC_ADMIN_KEY"97```9899### Request parameters100101| Parameter | Type | Required | Description |102| ------------- | ------- | -------- | ----------------------------------------------------------------------- |103| `starting_at` | string | Yes | UTC date in YYYY-MM-DD format; returns metrics for this single day only |104| `limit` | integer | No | Number of records per page (default: 20, max: 1000) |105| `page` | string | No | Opaque cursor token from previous response's `next_page` field |106107### Available metrics108109Each response record contains the following metrics for a single user on a single day:110111#### Dimensions112113* **date:** Date in RFC 3339 format (UTC timestamp)114* **actor:** The user or API key that performed the Claude Code actions (either `user_actor` with `email_address` or `api_actor` with `api_key_name`)115* **organization\_id:** Organization UUID116* **customer\_type:** Type of customer account (`api` for API customers, `subscription` for Pro/Team customers)117* **terminal\_type:** Type of terminal or environment where Claude Code was used (for example, `vscode`, `iTerm.app`, `tmux`)118119#### Core metrics120121* **num\_sessions:** Number of distinct Claude Code sessions initiated by this actor122* **lines\_of\_code.added:** Total number of lines of code added across all files by Claude Code123* **lines\_of\_code.removed:** Total number of lines of code removed across all files by Claude Code124* **commits\_by\_claude\_code:** Number of git commits created through Claude Code's commit functionality125* **pull\_requests\_by\_claude\_code:** Number of pull requests created through Claude Code's PR functionality126127#### Tool action metrics128129Breakdown of tool action acceptance and rejection rates by tool type:130131* **edit\_tool.accepted/rejected:** Number of Edit tool proposals that the user accepted/rejected132* **multi\_edit\_tool.accepted/rejected:** Number of MultiEdit tool proposals that the user accepted/rejected133* **write\_tool.accepted/rejected:** Number of Write tool proposals that the user accepted/rejected134* **notebook\_edit\_tool.accepted/rejected:** Number of NotebookEdit tool proposals that the user accepted/rejected135136#### Model breakdown137138For each Claude model used:139140* **model:** Claude model identifier (for example, `claude-opus-5`)141* **tokens.input/output:** Input and output token counts for this model142* **tokens.cache\_read/cache\_creation:** Cache-related token usage for this model143* **estimated\_cost.amount:** Estimated cost in cents USD for this model144* **estimated\_cost.currency:** Currency code for the cost amount (currently always `USD`)145146### Response structure147148The API returns data in the following format:149150```json151{152 "data": [153 {154 "date": "2025-09-08T00:00:00Z",155 "actor": {156 "type": "user_actor",157 "email_address": "developer@company.com"158 },159 "organization_id": "dc9f6c26-b22c-4831-8d01-0446bada88f1",160 "customer_type": "api",161 "terminal_type": "vscode",162 "core_metrics": {163 "num_sessions": 5,164 "lines_of_code": {165 "added": 1543,166 "removed": 892167 },168 "commits_by_claude_code": 12,169 "pull_requests_by_claude_code": 2170 },171 "tool_actions": {172 "edit_tool": {173 "accepted": 45,174 "rejected": 5175 },176 "multi_edit_tool": {177 "accepted": 12,178 "rejected": 2179 },180 "write_tool": {181 "accepted": 8,182 "rejected": 1183 },184 "notebook_edit_tool": {185 "accepted": 3,186 "rejected": 0187 }188 },189 "model_breakdown": [190 {191 "model": "claude-opus-5",192 "tokens": {193 "input": 100000,194 "output": 35000,195 "cache_read": 10000,196 "cache_creation": 5000197 },198 "estimated_cost": {199 "currency": "USD",200 "amount": 141201 }202 }203 ]204 }205 ],206 "has_more": false,207 "next_page": null208}209```210211## Pagination212213The API supports cursor-based pagination for organizations with large numbers of users:2142151. Make your initial request with optional `limit` parameter.2162. If `has_more` is `true` in the response, use the `next_page` value in your next request.2173. Continue until `has_more` is `false`.218219The 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.220221## Common use cases222223* **Executive dashboards:** Create high-level reports showing Claude Code impact on development velocity224* **AI tool comparison:** Export metrics to compare Claude Code with other AI coding tools such as Copilot and Cursor225* **Developer productivity analysis:** Track individual and team productivity metrics over time226* **Cost tracking and allocation:** Monitor spending patterns and allocate costs by team or project227* **Adoption monitoring:** Identify which teams and users are getting the most value from Claude Code228* **ROI justification:** Provide concrete metrics to justify and expand Claude Code adoption internally229230## Frequently asked questions231232### How fresh is the analytics data?233234Claude 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.235236### Can I get real-time metrics?237238No, this API provides daily aggregated metrics only. For real-time monitoring, consider using the [OpenTelemetry integration](https://code.claude.com/docs/en/monitoring-usage).239240### How are users identified in the data?241242Users are identified through the `actor` field in two ways:243244* **`user_actor`:** Contains `email_address` for users who authenticate through OAuth (most common)245* **`api_actor`:** Contains `api_key_name` for users who authenticate with an API key246247The `customer_type` field indicates whether the usage is from `api` customers (pay-as-you-go API) or `subscription` customers (Pro/Team plans).248249### What's the data retention period?250251Historical Claude Code analytics data is retained and accessible through the API. There is no specified deletion period for this data.252253### Which Claude Code deployments are supported?254255This API only tracks Claude Code usage on the Claude API. Usage through [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), [Claude in Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry), [Claude on Google Cloud](https://platform.claude.com/docs/en/build-with-claude/claude-on-vertex-ai), or [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws) is not included.256257### What does it cost to use this API?258259The Claude Code Analytics API is free to use for all organizations with access to the Admin API.260261### How do I calculate tool acceptance rates?262263Tool 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%.264265### What time zone is used for the date parameter?266267All dates are in UTC. The `starting_at` parameter should be in YYYY-MM-DD format and represents UTC midnight for that day.268269## See also270271The Claude Code Analytics API helps you understand and optimize your team's development workflow. Learn more about related features:272273* [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api)274* [Admin API reference](https://platform.claude.com/docs/en/api/admin)275* [Claude Code Analytics dashboard](https://platform.claude.com/claude-code)276* [Usage and Cost API](https://platform.claude.com/docs/en/manage-claude/usage-cost-api) - Track API usage across all Anthropic services277* [Compliance API](https://platform.claude.com/docs/en/manage-claude/compliance-api) - Retrieve audit and activity data278* [Identity and access management](https://code.claude.com/docs/en/iam)279* [Monitoring usage with OpenTelemetry](https://code.claude.com/docs/en/monitoring-usage) for custom metrics and alerting280