Claude Code

Claude Code is Anthropic’s agentic coding tool that lives in your terminal. Respan gives you hierarchical traces of every conversation including thinking blocks, tool calls, and token usage — and gateway routing through the Anthropic-compatible Respan endpoint.

Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.

Run npx @respan/cli setup to set up with your coding agent.

Claude Code stores conversation transcripts as JSONL files. The Respan hook reads new entries on the Stop event and exports them as structured traces.

Setup

1

Prerequisites

  • Claude Code installed (npm install -g @anthropic-ai/claude-code)
  • Python 3.8+ with requests library
2

Set environment variables

Add to your shell profile (.bashrc, .zshrc, or PowerShell $PROFILE):

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export TRACE_TO_RESPAN="true"
3

Download the hook script

$mkdir -p ~/.claude/hooks
$curl -o ~/.claude/hooks/respan_hook.py \
> https://raw.githubusercontent.com/respanai/respan-example-projects/main/python/dev-tools/claude-code/respan_hook.py
4

Configure Claude Code settings

Add the hook to ~/.claude/settings.json:

1{
2 "hooks": {
3 "Stop": [
4 {
5 "hooks": [
6 {
7 "type": "command",
8 "command": "python ~/.claude/hooks/respan_hook.py"
9 }
10 ]
11 }
12 ]
13 }
14}
5

View your trace

Open the Traces page to see hierarchical conversation traces with thinking blocks, tool calls, and token usage.

Captured data

DataDescription
User promptThe user’s input text.
Assistant responseClaude’s final response.
Thinking blocksExtended thinking content.
Tool callsTool name, input, and output.
Token usageInput, output, and cache tokens.
TimingStart time, end time, latency.
ModelModel name (e.g. claude-sonnet-4-5-20250929).

Span types

Spanlog_typeDescription
RootagentThe complete conversation turn.
ThinkinggenerationExtended thinking blocks.
TooltoolTool invocations (Read, Write, Bash, etc.).

Debugging

Check the log file for issues.

$tail -f ~/.claude/state/respan_hook.log

The hook tracks processed turns in ~/.claude/state/respan_state.json. Delete it to reprocess all turns.

IssueSolution
No traces appearingCheck TRACE_TO_RESPAN=true is set.
API errorsVerify RESPAN_API_KEY is correct.
Missing thinkingEnsure extended thinking is enabled in Claude Code.
Duplicate tracesClear state file to reset.