AgentSkillsCN

Trace Claude Code

根据用户需求,为 Cursor 编写 Slash 命令。遵循 Cursor 官方命令格式(纯 Markdown、.cursor/commands/、kebab-case 文件名),产出可复用的工作流指令。当用户提出“编写一个命令”“创建一个 /xxx 命令”或“根据 xxx 编写 Cursor 命令”时,可使用此技能。

SKILL.md

Judgeval Tracing for Claude Code

Automatically trace Claude Code sessions to Judgeval for observability and debugging.

Features

  • Session Tracing: Capture complete conversation sessions with start/end times
  • Turn Tracking: Track each user prompt as a separate turn
  • LLM Spans: Log every model call with input/output and token usage
  • Tool Spans: Track tool invocations (file operations, terminal, MCP tools)
  • Cache Metrics: Track cache creation and read tokens for prompt caching

Trace Structure

code
Session (task span)
├── Turn 1 (task span)
│   ├── claude-opus-4-5 (llm span)
│   ├── Read: file.py (tool span)
│   ├── Subagent: code-reviewer (task span)  ← Subagent with nested spans
│   │   ├── claude-3-5-haiku (llm span)
│   │   ├── Read (tool span)
│   │   └── claude-3-5-haiku (llm span)
│   └── claude-opus-4-5 (llm span)
└── Turn 2 (task span)
    └── ...

Setup

After installing the plugin, run setup in your project directory:

bash
cd /path/to/your/project
bash ~/.claude/plugins/marketplaces/judgeval-claude-plugin/skills/trace-claude-code/setup.sh

This will prompt you for:

  • JUDGMENT_API_KEY - Your Judgeval API key
  • JUDGMENT_ORG_ID - Your organization ID
  • JUDGMENT_API_URL - API URL (default: https://api.judgmentlabs.ai)
  • JUDGEVAL_CC_PROJECT - Project name (default: claude-code)

Environment Variables

VariableRequiredDescription
TRACE_TO_JUDGEVALYesSet to true to enable tracing
JUDGMENT_API_KEYYesYour Judgeval API key
JUDGMENT_ORG_IDYesYour organization ID
JUDGMENT_API_URLNoAPI URL (default: https://api.judgmentlabs.ai)
JUDGEVAL_CC_PROJECTNoProject name (default: claude-code)
JUDGEVAL_CC_DEBUGNoSet to true for debug logging

Hooks

HookTriggerAction
session_start.shSession beginsCreates root trace span
user_prompt_submit.shUser sends promptCreates Turn span
post_tool_use.shTool completesTracks tool count
stop_hook.shResponse completeMarks turn for finalization
subagent_stop.shSubagent completesParses subagent transcript, creates nested spans
session_end.shSession endsCreates LLM/Tool spans, finalizes session

Span Attributes

Session Span

  • judgment.span_kind: "task"
  • judgment.input: Session description
  • judgment.output: Completion summary
  • turn_count: Number of turns

LLM Span

  • judgment.span_kind: "llm"
  • judgment.input: Conversation history
  • judgment.output: Model response
  • judgment.llm.model: Model name
  • judgment.llm.provider: "anthropic"
  • judgment.usage.non_cached_input_tokens: Input tokens
  • judgment.usage.output_tokens: Output tokens
  • judgment.usage.cache_creation_input_tokens: Cache write tokens
  • judgment.usage.cache_read_input_tokens: Cache read tokens

Tool Span

  • judgment.span_kind: "tool"
  • judgment.input: Tool input
  • judgment.output: Tool output
  • tool_name: Tool identifier

Logs

Hook logs are written to: ~/.claude/state/judgeval_hook.log

Enable debug logging:

bash
export JUDGEVAL_CC_DEBUG=true

Troubleshooting

Traces not appearing:

  1. Check TRACE_TO_JUDGEVAL=true is set
  2. Verify API key and org ID are correct
  3. Check logs for errors

Missing spans:

  1. Ensure all hooks are executable
  2. Check for jq/curl availability
  3. Review debug logs