Set up Respan
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
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
~/.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:5. Use your agent as normal
No code changes required. Just run your CLI agent:- Claude Code
- Codex CLI
- Gemini CLI
- OpenCode
6. View traces
Open Traces to see your agent activity. Each agent turn produces a trace like this:- 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
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
| Flag | Description |
|---|---|
--customer-id | Customer identifier for traces (e.g., developer name) |
--workflow-name | Workflow name for grouping traces |
--span-name | Root span name (defaults to agent name) |
--project-id | Respan project ID |
--attrs | Custom attributes JSON (e.g., '{"team":"backend"}') |
--global | Apply to all projects (not just current directory) |
--local | Apply to current project only |
--dry-run | Preview changes without writing files |
Environment variables
| Variable | Agents | Description |
|---|---|---|
RESPAN_API_KEY | All | Override the stored API key |
RESPAN_CUSTOMER_ID | Claude Code, Codex, Gemini | Override customer identifier per session |
RESPAN_METADATA | Claude Code, Codex, Gemini | JSON string merged into span metadata |
RESPAN_WORKFLOW_NAME | Claude Code, Codex, Gemini | Override workflow name per session |
RESPAN_BASE_URL | All | Override API endpoint (for enterprise) |
TRACE_TO_RESPAN | Claude Code | Set to false to disable tracing |
CC_RESPAN_DEBUG | Claude Code | Enable debug logging |
CODEX_RESPAN_DEBUG | Codex CLI | Enable debug logging |
GEMINI_RESPAN_DEBUG | Gemini CLI | Enable debug logging |
Debug logs
| Agent | Log file |
|---|---|
| Claude Code | ~/.claude/state/respan_hook.log |
| Codex CLI | ~/.codex/state/respan_hook.log |
| Gemini CLI | ~/.gemini/state/respan_hook.log |
Disabling tracing
- Claude Code
- Codex CLI
- Gemini CLI
- OpenCode
Set
TRACE_TO_RESPAN to false in .claude/settings.local.json:Next steps
Monitor an AI agent
Set up evaluation and alerting for agent quality
Track cost per feature
Attribute LLM costs to teams and features