← Back to Cookbook

Monitor Claude Code usage and costs 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.

Features
Category Monitoring
Time
10 minutes
Difficulty
Beginner
Steps
5 steps

Before you start

SDKs & packages
  • Claude Code installed and configured
  • Node.js 18+ installed
Accounts & access
Knowledge
  • Basic familiarity with Claude Code slash commands

1
Create a Sentry project

In Sentry, create a new project for your Claude Code monitoring data. Go to 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

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.

/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.

/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.

set up Sentry monitoring

5
Explore traces in Sentry

Head to AI Agents Insights 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 Monitoring documentation
Sentry AI Agents dashboard showing Claude Code sessions with invoke_agent root spans, chat and Bash tool execute_tool child spans, and gen_ai.request span details including input, output, and attributes

That's it.

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.

  • 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

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.

Frequently asked questions

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.
Yes. The plugin instruments Claude Code's tool execution layer, so it captures data regardless of which Claude model you have configured.
No. Sentry uses asynchronous, non-blocking transport. Spans are batched and sent in the background with negligible performance impact.
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.
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.

Fix it, don't observe it.

Get started with the only application monitoring platform that empowers developers to fix application problems without compromising on velocity.