Trace CLI coding agents
Set up Respan
- Sign up — Create an account at platform.respan.ai
- Create an API key — Generate one on the API keys page
Overview
CLI coding agents like Claude Code, Codex CLI, Gemini CLI, and OpenCode run in sandboxed terminal environments — making multiple LLM calls, reading files, executing shell commands, and editing code autonomously. Without observability, you have no visibility into what the agent did, how many tokens it consumed, or whether it made the right decisions.
This cookbook shows how to add full tracing in 6 steps — no code changes required.
1. Install the CLI
2. Authenticate
Replace YOUR_API_KEY with the key from the API keys page.
Verify you’re authenticated:
3. Integrate your agent
Run the integration command for your CLI agent:
Claude Code
Codex CLI
Gemini CLI
OpenCode
This installs a Node.js hook at ~/.respan/hooks/claude-code.cjs and registers it in ~/.claude/settings.json. Every time Claude Code responds, the hook captures the turn and sends it to Respan.
4. Add attributes (optional)
Tag traces with customer IDs, project names, or custom metadata for filtering and cost tracking.
Via integrate flags
Claude Code
Codex CLI
Gemini CLI
OpenCode
Via environment variables (per session)
Override attributes for a single session without re-running integrate:
For OpenCode, use the standard OTEL variable:
5. Use your agent as normal
No code changes required. Just run your CLI agent:
Claude Code
Codex CLI
Gemini CLI
OpenCode
Or non-interactively:
6. View traces
Open Traces to see your agent activity. Each agent turn produces a trace like this:
Each span includes:
- Input/output — The user message and agent response
- Model — Which model was used (e.g.,
claude-opus-4-6,gpt-5.4,gemini-3-flash) - Token usage — Prompt tokens, completion tokens, and reasoning tokens
- Cost — Computed automatically from token counts
- Latency — Time for each step
- Tool details — File paths, shell commands, code edits
Filter traces by customer_identifier, workflow_name, or any custom metadata field to find specific sessions.
Go to Users to see per-developer breakdowns of token usage, cost, and session count.
Configuration reference
Integrate flags
Environment variables
Debug logs
Disabling tracing
Claude Code
Codex CLI
Gemini CLI
OpenCode
Set TRACE_TO_RESPAN to false in .claude/settings.local.json: