---
title: Track and optimize coding agent usage
description: Govern coding agent spend centrally. See cost by team and developer, trace every session, and improve token efficiency with Langfuse — via a gateway or agent hooks.
---

# Track and optimize coding agent usage

Coding agents make engineers faster, but they also make AI spend unpredictable. Govern it centrally. See spend by team and by developer. Trace sessions to improve token efficiency.

Engineering spend by task, last 30 days: Implementation $486, Code review $379, Planning $321, Bug fix $178, Documentation $104, Other $72. Total spend $1,540 · 4,812 sessions · 28% budget left.

[Start free](/cloud) · [Talk to sales](/talk-to-us)

Pick the path that matches how your organization runs coding agents. Platform teams usually start with a **gateway**. Individual developers and team rollouts often start with **hooks**.

## Govern AI spend from a central place

Route coding agent traffic through an LLM gateway so every model call is authenticated, budgeted, and traced in one place — without changing each developer's local setup.

### Allocate budgets centrally

Give teams and departments a spend envelope on the gateway, then see what actually landed in Langfuse. A developer cannot disable a gateway the way they can a local hook.

![Organization budget of $40,000 per month allocated across four teams, with each team's spend shown against its budget](/images/coding-agents/gateway-budget-allocation.png)

[What is an LLM gateway?](/resources/engineering/llm-gateway)

### See spend by department and use case

Trace every coding-agent LLM call into Langfuse. Build dashboards for cost per team, repository, model, and use case, then set alerts before a spike becomes a surprise.

![Platform team spend of $14,600 with daily costs, an alert threshold, and a breakdown by debugging, feature implementation, code review, and planning](/images/coding-agents/gateway-spend-breakdown.png)

[Cost tracking](/docs/observability/features/token-and-cost-tracking)

### Improve token efficiency with shared skills

Use traces to find repeated context, failed tool loops, and prompts that should become org- or team-wide skills. Roll those skills out once and measure whether token spend actually drops.

![Repeated tasks consolidated into a shared skill, reducing tokens per run from 14.2k to 8.6k](/images/coding-agents/gateway-shared-skills.png)

[Evaluating AI agent skills](/blog/2026-02-26-evaluate-ai-agent-skills)

### A gateway as the routing layer

[![Coding agents send requests through an LLM gateway to model providers, while asynchronous OpenTelemetry traces go to Langfuse.](/images/coding-agents/gateway-architecture.png)](/images/coding-agents/gateway-architecture.png)

### Any gateway, one place for LLM calls

Route coding-agent traffic through LiteLLM or OpenRouter today. Langfuse Gateway is coming soon: virtual keys, access control, and tracing built in.

**LLM gateways:** [LiteLLM](/integrations/gateways/litellm), [OpenRouter](/integrations/gateways/openrouter), [Langfuse Gateway (coming soon)](/docs/roadmap#langfuse-gateway)

## Dive deep into session details

Trace the full execution of your preferred coding agent. Log tool calls, token spend, and skill usage to identify bottlenecks. Optimize your coding setup, test skills, and inspect agent context for maximum efficiency.

Hooks are per-machine and user-serviceable. Treat them as telemetry, not enforcement. If you need guaranteed capture or budgets, use a gateway.

### Trace the full coding-agent session

Log tool calls, retries, skill usage, and model turns. Reconstruct what the agent did so you can debug loops, bloated context, and skills that need a rewrite.

![Coding-agent session trace showing model turns, tool calls, approval waits, token usage, and cost](/images/coding-agents/hooks-session-trace.png)

[Tracing coding agents](/resources/engineering/coding-agent-tracing)

### Attribute spend to developers and projects

Hook integrations attach a user identifier, so dashboards can break down cost per person or per repo. Find who is burning tokens and which workflows are worth optimizing.

![Tokens per user dashboard showing total token consumption grouped by individual users](/images/coding-agents/hooks-tokens-per-user.png)

[Cost tracking](/docs/observability/features/token-and-cost-tracking)

### Optimize skills, tools, and context

Compare sessions to find unused tools, repeated file reads, and prompts that should be shorter. Test skill changes and inspect agent context for maximum efficiency.

![Skill evaluation comparison showing reference-file selection and task-completion scores for coding-agent tasks](/images/coding-agents/hooks-skill-evaluation.png)

[Optimizing an AI skill](/blog/2026-03-24-optimizing-ai-skill-with-autoresearch)

**Coding agents:** [Claude Code](/integrations/developer-tools/claude-code), [Codex](/integrations/developer-tools/codex), [OpenCode](/integrations/developer-tools/opencode), [Cursor](/integrations/developer-tools/cursor), [GitHub Copilot](/integrations/developer-tools/github-copilot), [more coding agents](/integrations#developer-tools)

## Learn how to trace and govern coding agents

- **Hooks path only:** [Tracing coding agents with Langfuse](/resources/engineering/coding-agent-tracing) — Setup patterns for Claude Code, Codex, Copilot, Cursor, and more — plus cost tracking and team governance.
- [What is an LLM gateway?](/resources/engineering/llm-gateway) — When a gateway is the right enforcement layer for model access, budgets, and tracing.
- [Evaluating AI agent skills](/blog/2026-02-26-evaluate-ai-agent-skills) — Measure whether skills actually improve quality and reduce wasted context.
- [Optimizing an AI skill with Autoresearch](/blog/2026-03-24-optimizing-ai-skill-with-autoresearch) — Iterate on skills with traces and experiments so token spend actually drops.

## Ready to govern coding agent usage?

Use a gateway or hooks to trace sessions, attribute spend, and improve token efficiency with Langfuse.

- [Start free](/cloud)
- [Documentation](/docs)
- [Talk to sales](/talk-to-us)

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/coding-agents.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx @langfuse/cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
