> ## Documentation Index
> Fetch the complete documentation index at: https://langwatch.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Explore your usage with your own agent

> Point Claude Code or any coding agent at your own LangWatch usage. One device login, one pasted prompt, and the agent answers where your tokens went.

Once your sessions land on LangWatch (see [Track your Claude Code usage](/docs/ai-governance/track-your-claude-code-usage)), the same CLI that captured them can read them back. That means your own coding agent can answer questions about your usage: no API key to paste, no dashboard clicking, just the `langwatch` CLI it already has.

## One-time setup

```bash theme={null}
npm install -g langwatch
langwatch login
```

`langwatch login` opens a browser sign-in. Approve it once and the CLI works with your personal account from then on: when no API key is set (no `--api-key` flag, no `LANGWATCH_API_KEY` in the environment or `.env`), every command falls back to your device login and resolves your personal project by itself. `langwatch whoami` shows who you are logged in as.

## The prompt

Paste this into Claude Code (or Cursor, Codex, or any coding agent with shell access):

```text theme={null}
Explore my LangWatch usage and tell me where my tokens and money went.

The `langwatch` CLI works with my device login: no API key and no env vars needed. If a command says I am not logged in, have me run `langwatch login` once, then continue. `langwatch whoami` prints who I am logged in as.

Read my usage with these commands (add `-o json` for machine-readable output):
- `langwatch trace search --limit 50` lists my recent sessions with cost and token totals (`-q <text>`, `--start-date` / `--end-date` to narrow)
- `langwatch trace get <traceId>` shows one session's full tree: models, per-span tokens, cache reads vs writes, tool calls
- `langwatch analytics query -m total-cost --group-by metadata.model` aggregates spend over time (other presets: trace-count, user-count; raw metric paths with `-a sum|avg|p95`)
- `langwatch trace export -f jsonl` dumps a whole window of traces when you want to crunch numbers yourself

Start with the last 7 days: total spend, the most expensive sessions and what made them expensive (context size, cache misses, subagents, retries), and which models consumed the most. Then answer my follow-up questions about my own usage from the same data.
```

The same prompt is one click away in the app: on `/me`, once your account has traces, **Connect your agent** offers **Explore via your coding agent**, which copies it to your clipboard.

## Questions your agent can answer

Once the prompt is in, ask in plain language. Some that pay for themselves:

* Where did my tokens go this week?
* Which sessions were the most expensive?
* What share of my usage ran above 150k context, and what should I do about it? (The usual fixes: `/compact` mid-task, `/clear` between tasks.)
* How much usage came from sessions active 8+ hours, or from 4+ sessions running in parallel?
* Which subagents consumed the most, and would a cheaper model fit the simple ones?
* Which skills did I use the most?
* How much of my usage came from MCP tool results staying in context?

The agent reads the same traces you see on `/me` and `/traces`, so every answer can cite the sessions behind it.
