langsmith-tracing — Claude Code hook: what it does, how to install
Exports Claude Code conversation traces to LangSmith for session tracking and analysis. Runs in the background right after Claude finishes responding.
npx claude-code-templates@latest --hook monitoring/langsmith-tracingWhat langsmith-tracing does
The hook triggers on the Stop event right after Claude finishes an answer, calling .claude/hooks/langsmith-tracing.sh in the background. It reads the conversation transcript, transforms it into LangSmith format, and posts it to the LangSmith API. Requests stay grouped under thread_id to preserve session continuity. System prompts remain excluded from all exported traces.
The script relies on jq, curl, and uuidgen. Without jq installed on the system, transcript parsing fails completely. Execution details and diagnostic messages land in ~/.claude/state/hook.log.
Configuration lives in .claude/settings.local.json with environment flags: TRACE_TO_LANGSMITH=true, CC_LANGSMITH_API_KEY, and CC_LANGSMITH_PROJECT. Verbose logging can be toggled with CC_LANGSMITH_DEBUG=true.
What it helps with
- forward Claude Code run traces directly to LangSmith
- maintain session structure across conversations using
thread_id - inspect hook execution issues via
~/.claude/state/hook.log - keep system prompts private when collecting LLM telemetry
Example prompts for the agent
- Fix the authentication handler and add unit tests for it
- Investigate why the project build is failing inside the container
How to install langsmith-tracing
1claude-code-templates
npx claude-code-templates@latest --hook monitoring/langsmith-tracing2Manually: put the files in place
.claude/settings.jsonThe hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json
Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command
Questions about langsmith-tracing
How to install langsmith-tracing in Claude Code?
Run npx claude-code-templates@latest --hook monitoring/langsmith-tracing and verify the hook configuration inside .claude/settings.json.
What does langsmith-tracing do?
It activates on the Stop event after Claude Code answers, formats the session transcript, and pushes traces to the LangSmith API linked by thread_id.
What dependencies are required besides the API key?
You need jq, curl, and uuidgen on your system. You must also supply TRACE_TO_LANGSMITH, CC_LANGSMITH_API_KEY, and CC_LANGSMITH_PROJECT inside .claude/settings.local.json.
Source text
langsmith-tracing.json · MIT
{
"description": "Automatically send Claude Code conversation traces to LangSmith for monitoring and analysis. Prerequisites: jq (brew install jq on macOS or sudo apt-get install jq on Linux), curl and uuidgen (usually pre-installed), LangSmith account and API key. Configuration: Install langsmith-tracing setting (npx claude-code-templates@latest --setting telemetry/langsmith-tracing) or manually add to .claude/settings.local.json the following environment variables: TRACE_TO_LANGSMITH=true, CC_LANGSMITH_API_KEY=lsv2_pt_..., CC_LANGSMITH_PROJECT=project-name, CC_LANGSMITH_DEBUG=true (optional). How it works: Runs in background on Stop event after each Claude response, reads conversation transcript, converts to LangSmith format, sends to LangSmith API, groups by thread_id for session continuity. Debugging: Check logs at ~/.claude/state/hook.log. Privacy note: System prompts not included in traces.",
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/langsmith-tracing.sh\""
}
]
}
]
}
}
© davila7 · MIT · davila7/claude-code-templates