
Prerequisites
Before setting up tracing, ensure you have:- Claude Code CLI installed.
- A LangSmith API key.
- Node.js installed.
Getting started
From within Claude Code, run: If you are migrating from the previously recommended version of tracing Claude Code with manually created stop hooks, see Migrating from the manual stop hook.
Setting environment variables
Option 1: Project-level configuration (recommended) The plugin requires the following environment variables:TRACE_TO_LANGSMITH: "true"- Enables tracing for this project. Remove or set tofalseto disable tracing.CC_LANGSMITH_API_KEY- Your LangSmith API keyCC_LANGSMITH_PROJECT- The LangSmith project name where traces are sent- (optional)
CC_LANGSMITH_METADATA- JSON object of custom metadata to attach to all runs (e.g. PR URL, author) - (optional)
CC_LANGSMITH_DEBUG: "true"- Enables detailed debug logging. Remove or set tofalseto disable debug logging.
.claude/settings.local.json in your project directory and populate it as follows:
Alternatively, to enable tracing to LangSmith for all Claude Code sessions, you can add the above JSON to your global Claude Code settings.json file.
~/.zshrc, ~/.bashrc, or ~/.bash_profile):
Verify setup
Traces will appear complete in LangSmith after Claude Code responds. Note that if you interrupt a run while it is in progress, the plugin will only flush that run when you send the next message or end the session. In LangSmith, you’ll see:- Each message to Claude Code appears as a trace.
- All turns from the same Claude Code session are grouped using a shared
thread_idand can be viewed in the Threads tab of a project.
Custom metadata
Set theCC_LANGSMITH_METADATA environment variable to a JSON object to attach custom metadata to all traced runs. This is useful for tagging traces with contextual information such as PR URLs, authors, or environment names.
- Settings file (recommended)
- Shell environment variable
Usage with GitHub Actions
You can use this plugin withanthropics/claude-code-action to trace Claude Code runs in CI. Add the following to your workflow:
LANGSMITH_API_KEY and ANTHROPIC_API_KEY as repository secrets.
This lets you correlate traces back to specific PRs, commits, and authors in LangSmith.
Nesting traces under an existing run
You can also set an environment variable namedCC_LANGSMITH_PARENT_DOTTED_ORDER to nest all Claude Code traces as children of an existing LangSmith run. This is useful when Claude Code is invoked programmatically as part of a larger traced workflow.
Python
Trace to multiple destinations (replicas)
You can trace to multiple LangSmith projects or workspaces simultaneously using theCC_LANGSMITH_RUNS_ENDPOINTS environment variable. Set CC_LANGSMITH_RUNS_ENDPOINTS to a JSON array of replica configurations. This overrides other client settings.
Tracing to multiple replicas is useful for:
- Sending traces to both a production and staging project
- Tracing to multiple workspaces with different API keys
- Adding extra metadata to specific replica destinations
| Field | Required | Description |
|---|---|---|
apiUrl | Yes | LangSmith API URL (typically https://api.smith.langchain.com) |
apiKey | Yes | API key for the destination workspace |
projectName | Yes | Project name in the destination workspace |
updates | No | Optional metadata/fields to override on the replicated runs |
CC_LANGSMITH_RUNS_ENDPOINTS environment variable:
- Settings file (recommended)
- Shell environment variable
In your local
.claude/settings.local.json or global ~/.claude/settings.json:Troubleshooting
No traces appearing in LangSmith
-
Check the hook is running:
You should see log entries after each Claude response.
-
Verify environment variables:
- Check that
TRACE_TO_LANGSMITH="true"in your project’s.claude/settings.local.json - Verify your Personal Access Token (PAT) is correct (starts with
lsv2_pt_) - Ensure the project name exists in LangSmith
- Check that
-
Enable debug mode to see detailed API activity:
Then check logs for API calls and HTTP status codes.
Subagent runs do not appear after user interruption
Currently, subagents are only traced upon completion. This means if you interrupt a conversation turn in the middle of a subagent run, the subagent’s child runs will not be traced.Managing log file size
The hook logs all activity to~/.claude/state/hook.log. With debug mode enabled, this file can grow large:
Migrating from the manual stop hook
If you were using the previous version of tracing Claude Code with LangSmith, you will need to remove~/.claude/hooks/stop_hook.sh and remove the reference to the hook from any previous settings.local.json or settings.json files you added it to previously, then following the plugin installation instructions above.
Source code
The plugin is open-source under the MIT license and is available in this GitHub repo.Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

