Claude logo
10 min setup

Connect Claude to StackSpend

Send Claude Code, Cowork, and Office agents OpenTelemetry directly to StackSpend for estimated usage and cost visibility. This does not require the Anthropic API.

What This Tracks

Claude Code, Cowork, and Office agents can send OpenTelemetry to StackSpend while they run. StackSpend stores the raw telemetry and turns cost-bearing metrics or events into estimated cost line items. You do not need to create an Anthropic API key for this setup.

  • Estimated USD cost from claude_code.cost.usage metrics and api_request cost_usd log events.
  • Token usage from claude_code.token.usage and api_request token attributes, including input, output, cache read, and cache creation token types when present.
  • Useful dimensions such as model, user email, user account UUID, organization ID, session ID, query source, skill, plugin, and agent names when Claude Code emits them.
  • Raw OTLP JSON metric and log batches for validation while we learn what real accounts send.
  • This Claude provider is for OpenTelemetry usage estimates. Anthropic API billing remains a separate Anthropic provider connection.

Before You Start

You will need a few things:

  • Access to StackSpend with permission to create a provider and API key.
  • For Claude Code business rollout: access to Claude Code managed settings, MDM, or a system managed-settings.json deployment path.
  • For an individual Claude Code install: a Terminal window on the machine you want to measure.
  • For Cowork or Office agents: access to the Claude admin monitoring settings.

Important Estimate Note

Claude telemetry is usage telemetry, not an official invoice. StackSpend treats the cost as estimated and uses it for trend, attribution, and early warning workflows. Your final Anthropic bill, Claude subscription bundle, enterprise credit pool, or overage terms may differ.

Step 1

Create the StackSpend Provider

  1. In StackSpend, go to Dashboard - Providers.
  2. Click the add provider card.
  3. Choose Claude.
  4. Name it something clear, such as Claude Team.
  5. Click Create Provider.
  6. Open the provider page and copy the connection ID from the URL. It is the final path segment after/dashboard/providers/.
  7. Example: if the URL ends with abc123-provider-id, then your connection ID is abc123-provider-id.
Step 2

Create a Usage Ingest API Key

The easiest path is to generate the key from the Claude provider page. StackSpend creates a scoped usage:write key, injects it into copy-ready setup snippets, and still lists it under Settings - API Keys for future rotation or revocation.

  1. Open the Claude provider page you created in Step 1.
  2. Click Generate ingest key.
  3. Copy the key immediately. StackSpend only shows it once.
  4. If you prefer to create it manually, go to Settings - API Keys, create a key named Claude OTEL, and make sure it includesusage:write.
  5. The key usually starts withss_live_.
Step 3

Claude Code for a Business Account: Use Managed Settings

For a company rollout, use Claude Code managed settings. This is the recommended path because IT or an admin can deploy one policy across the organization instead of asking every user to edit shell files. Paste a single JSON object like this into server-managed settings, MDM policy, or a system-level managed-settings.json.

Common file-based managed settings locations are/Library/Application Support/ClaudeCode/managed-settings.jsonon macOS,/etc/claude-code/managed-settings.jsonon Linux or WSL, andC:\Program Files\ClaudeCode\managed-settings.jsonon Windows.

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://ingest.stackspend.app/api/v1/public/ingest/otel/claude/YOUR_CONNECTION_ID",
    "OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer YOUR_STACKSPEND_API_KEY"
  }
}

What to Replace

  • Replace YOUR_CONNECTION_ID with the provider connection ID from Step 1.
  • Replace YOUR_STACKSPEND_API_KEY with the API key from Step 2.
  • Your endpoint should look like https://ingest.stackspend.app/api/v1/public/ingest/otel/claude/abc123-provider-id.
  • Use the collector root endpoint. Do not add/v1/metricsor /v1/logs. Claude Code appends those paths automatically.

Secret Storage Warning

The static header above is acceptable for a first rollout test, but it stores the StackSpend API key in managed settings. For long-term use, deploy anotelHeadersHelper script that reads the key from your MDM secret store, Keychain, or another controlled location and returnsAuthorization=Bearer ....

After the policy lands, users should fully restart Claude Code and start a new session. Telemetry environment variables only apply to sessions started after the settings are loaded.

Step 4

Claude Code for an Individual User: Direct Install

If you are not on a business account or you want to test one machine first, use environment variables. Open a new Terminal window, paste the commands below, replace the placeholders, and then start Claude Code from that same Terminal window.

export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/json
export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.stackspend.app/api/v1/public/ingest/otel/claude/YOUR_CONNECTION_ID
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_STACKSPEND_API_KEY"
export OTEL_METRIC_EXPORT_INTERVAL=60000
export OTEL_LOGS_EXPORT_INTERVAL=5000
  1. Run claude in that same Terminal.
  2. Ask Claude Code to do a small task, then wait about 60 seconds for metrics and logs to export.
  3. Refresh the Claude Code provider page in StackSpend. Last synced should update after StackSpend receives the first telemetry payload.

To make this personal setup permanent, add the export commands to~/.zshrc or a safer local file such as ~/.zshrc.local, then restart Claude Code.

Step 5

Cowork and Office Agents: Use Claude Admin Monitoring

Cowork and Office agents are configured in the Claude admin UI, not with Claude Codesettings.json. Use the monitoring form for each product.

  1. In Claude admin, open Products - Cowork or Products - Office agents.
  2. In OTLP endpoint, pastehttps://ingest.stackspend.app/api/v1/public/ingest/otel/claude/YOUR_CONNECTION_IDafter replacing the connection ID.
  3. Set OTLP protocol to http/json.
  4. In OTLP headers, pasteAuthorization=Bearer YOUR_STACKSPEND_API_KEY.
  5. Add resource attributes such asdeployment.environment=prod,team=product,stackspend.source=claude_cowork. For Office agents, usestackspend.source=claude_office_agents.
  6. Save settings and start a new Cowork or Office agent session. Existing sessions may not pick up the new monitoring settings.

Setting Up a Team

Create one Claude provider connection for the team and reuse its endpoint across Claude Code, Cowork, and Office agents. You can share oneusage:write API key for the first rollout test. Later, per-product or per-team API keys make rotation and audit trails cleaner. StackSpend can show user-level attribution when Claude includes user attributes such as email or account UUID.

Troubleshooting

401 Unauthorized

Confirm the API key is active and the header is exactly likeAuthorization=Bearer ss_live_.... There must be a space between Bearer and the key.

403 Invalid Scope

Create or rotate the key so it includes the usage:write scope.

No Cost Line Items

Confirm the request returns 202 and the payload includes either claude_code.cost.usage metrics orapi_request log events withcost_usd.

404 on /v1/logs or /v1/metrics

Make sure the endpoint is the collector root, not a signal-specific path. Pastehttps://ingest.stackspend.app/api/v1/public/ingest/otel/claude/abc123-provider-id, not the same URL with /v1/metrics or/v1/logs appended.

I Added It to ~/.zshrc but Nothing Changed

Open a new Terminal window or run source ~/.zshrc. Then quit and restart Claude Code from that Terminal. A Claude Code session that is already running will not see newly added environment variables.

Official Claude Code Reference

Ready to track Claude usage?

Connect Claude with OpenTelemetry and give your team cost visibility across Claude Code, Cowork, and Office agents without adding Anthropic API credentials.