Skip to content

[Bug][Plugin/ClaudeCode] Claude Code plugin fails for Claude Console organizations - wrong Analytics API endpoint #8977

Description

@salim8898

Search before asking

  • I had searched in the issues and found no similar issues.

What happened

When using a Claude Console Admin API key (sk-ant-admin01-...), the connection test passes but data collection fails with:
permission_error: Missing required scopes. Got: ['api:admin'] Needed: ['read:analytics']

The plugin calls these Claude Enterprise endpoints which require read:analytics scope on an sk-ant-api01-... key (only available to Claude Enterprise / claude.ai customers):

  • v1/organizations/analytics/users
  • v1/organizations/analytics/summaries
  • v1/organizations/analytics/connectors

Claude Console organizations (platform.claude.com) use a different API entirely:

  • v1/organizations/usage_report/claude_code (query param: starting_at instead of date)

Claude Console Admin keys (sk-ant-admin01-...) have full access to the Console endpoint but the plugin never calls it, so Console orgs have no way to collect analytics data.

API differences:

Enterprise API Console API
Endpoint v1/organizations/analytics/users v1/organizations/usage_report/claude_code
Date param date starting_at
User field user.id / user.email_address actor.type + actor.email_address
Sessions claude_code_metrics.core_metrics.distinct_session_count core_metrics.num_sessions
Commits claude_code_metrics.core_metrics.commit_count core_metrics.commits_by_claude_code
Lines added claude_code_metrics.core_metrics.lines_of_code.added_count core_metrics.lines_of_code.added
Tool accepted tool_actions.edit_tool.accepted_count tool_actions.edit_tool.accepted
Chat metrics Yes No
Model cost breakdown No Yes

Pagination envelope (data, has_more, next_page) is identical across both APIs.

References:

What do you expect to happen

Organizations using Claude Console (platform.claude.com) with sk-ant-admin01-... Admin API keys should be able to collect Claude Code analytics data via v1/organizations/usage_report/claude_code.

Suggested fix: detect API type from key prefix (sk-ant-admin01- = Console, sk-ant-api01- = Enterprise) or add an explicit ApiType field to the connection model. For Console orgs, the analytics/summaries and analytics/connectors collectors should be skipped gracefully since those endpoints have no Console equivalent. All core Claude Code metrics (sessions, commits, PRs, lines of code, tool actions) are available in the Console API and can map to the existing ClaudeCodeUserActivity model.

How to reproduce

  1. Create a Claude Console Admin API key at platform.claude.com/settings/admin-keys (key starts with sk-ant-admin01-)
  2. In DevLake, go to Connections → Claude Code → create a new connection
  3. Paste the sk-ant-admin01-... key and fill in the Organization ID
  4. Click Test Connection — it succeeds
  5. Add a scope and trigger a data sync
  6. Sync fails with:
    permission_error: Missing required scopes. Got: ['api:admin'] Needed: ['read:analytics']

Environment:

  • DevLake version: v1.0.3-beta13
  • Anthropic account type: Claude Console (platform.claude.com)
  • Admin key prefix: sk-ant-admin01-...

Anything else

No response

Version

v1.0.3-beta13

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugThis issue is a bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions