# Monitor Claude Code Usage and Costs with Sentry

> Track Claude Code token usage, API costs, and tool activity with Sentry AI Observability. Set up OpenTelemetry-based observability for your Claude Code sessions in minutes.

**URL:** https://sentry.io/cookbook/monitor-claude-code-with-sentry/

---

Add the claude-code-sentry-monitor plugin to track token usage, session costs, and tool activity across every Claude Code session, without touching your project code.

**Time:** 10 minutes | **Difficulty:** Beginner

## What You'll Learn

- Installed the claude-code-sentry-monitor plugin into Claude Code

- Connected Claude Code sessions to Sentry AI Observability

- Tracked token usage and estimated API costs per Claude Code session

- Tracked tool calls per session as structured spans

- Explored per-session traces in the Sentry AI Agents dashboard

- Explored per-conversation-turn spans showing input/output tokens and which tools Claude used to answer each message

**Topics:** Tracing, AI Observability, Agent Tracing

## Before you start

**SDKs & packages**

- [Claude Code](https://claude.com/download) installed and configured

- Node.js 18+ installed

**Accounts & access**

- [Sentry account](https://sentry.io/signup/) with a Node.js project created

**Knowledge**

- Basic familiarity with Claude Code slash commands

## Steps

### 1. Create a Sentry project

In Sentry, create a new project for your Claude Code monitoring data. Go to [Settings → Projects](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/) and click **Create Project**. Select **Node.js** as the platform, give it a name like `claude-code`, and copy the DSN from the project settings. You'll need it in step 4.

[Creating a Sentry project](https://docs.sentry.io/product/sentry-basics/getting-started-tutorial/create-new-project/)

### 2. Add the plugin marketplace

Claude Code supports third-party plugin marketplaces. Add the marketplace that hosts the Sentry monitor plugin by running this slash command inside Claude Code.

```bash
/plugin marketplace add sergical/claude-code-sentry-monitor
```

### 3. Install the plugin and reload

With the marketplace added, install the plugin and reload to activate it. The reload step is required, as hooks won't fire until Claude Code picks up the new plugin.

```bash
/plugin install claude-code-sentry-monitor
/reload-plugins
```

### 4. Run the setup wizard

Tell Claude to set up Sentry monitoring. It will run the plugin's setup skill, prompt you for the DSN you copied in step 1, and write the config to `~/.config/claude-code/sentry-monitor.json` automatically.

```bash
set up Sentry monitoring
```

### 5. Explore traces in Sentry

Head to [AI Agents Insights](https://sentry.io/orgredirect/organizations/:orgslug/insights/ai-agents/) in Sentry. Each Claude Code session appears as an `invoke_agent` root span. Expand a session to see each conversation turn as a `gen_ai.request` child span, including input and output token counts for that turn, which map directly to your API costs. Tool calls (`read`, `bash`, `grep`, and others) are nested inside each turn as `execute_tool` spans with durations and metadata. To check total token usage and cost across sessions, use the Trace Explorer and filter by `service.name:claude-code`.

[AI Observability documentation](https://docs.sentry.io/product/agents/)

## Summary

**Token usage, costs, and tool calls. All in one place.**

See exactly how many tokens each Claude Code session consumed, what it cost, and which tools it used, so you can understand your usage, control spend, and tune your workflow.

## Pro Tips

- Adjust `tracesSampleRate` in `~/.config/claude-code/sentry-monitor.json` to reduce volume during heavy sessions.

- Add a `tags` field with `"developer": "yourname"` to filter traces and costs by team member in the Sentry dashboard.

- The config lives at `~/.config/claude-code/sentry-monitor.json` and can be edited at any time without reinstalling the plugin.

- To monitor token usage and costs across your whole team, have each developer install the plugin and set a shared Sentry project DSN. All sessions roll up into one dashboard.

## Common Pitfalls

- Forgetting `/reload-plugins` after install. Hooks won't fire until Claude Code reloads the plugin.

- Using a browser or Python Sentry DSN instead of a Node.js project. The plugin uses `@sentry/node` and requires a server-side DSN.

- The plugin is user-level, not project-level. One install covers all your Claude Code projects automatically.

## FAQ

**Can I set alerts when Claude Code usage spikes?**

Yes. Use Sentry's alert rules to trigger a notification when token volume or session count exceeds a threshold, useful for keeping an eye on heavy usage periods.

**Does this work with all Claude models?**

Yes. The plugin instruments Claude Code's tool execution layer, so it captures data regardless of which Claude model you have configured.

**Will this slow down my coding sessions?**

No. Sentry uses asynchronous, non-blocking transport. Spans are batched and sent in the background with negligible performance impact.

**How much does Sentry monitoring cost?**

Traces are billed based on volume. Sentry's free tier includes 10,000 spans/month — more than enough for a single developer to get started.

**Can I use this across multiple projects?**

Yes. Because the plugin is installed at the user level, it automatically monitors all your Claude Code sessions across every project with a single install.

## Next Steps

- [Set up alerts on unusual activity](https://sentry.io/orgredirect/organizations/:orgslug/monitors/alerts/): Create a Sentry alert to notify you when tool call volume or session duration spikes unexpectedly.

- [Explore full trace details](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/): Use the Trace Explorer to drill into individual Claude Code sessions and see every tool invocation.

- [AI Observability docs](https://docs.sentry.io/product/agents/): Learn more about how Sentry tracks tool calls and agent behavior for AI applications.

---

*Source: [sentry.io/cookbook/monitor-claude-code-with-sentry/](https://sentry.io/cookbook/monitor-claude-code-with-sentry/)*
