GitHub - langchain-ai/langsmith-claude-code-plugins: LangSmith plugins for Claude Code
Service

GitHub - langchain-ai/langsmith-claude-code-plugins: LangSmith plugins for Claude Code

langchain-ai
2026.04.04
·GitHub·by 이호민/AI
#Claude Code#LangSmith#LLM#Plugin#Tracing

Key Points

  • 1This paper introduces a LangSmith Tracing Plugin for Claude Code, designed to automatically trace conversations, tool calls, and subagent executions to LangSmith for comprehensive observability.
  • 2The plugin captures detailed LLM run information, including inputs, outputs, metadata, and token usage, along with tool names, inputs, and outputs, all configurable via environment variables or a settings file.
  • 3It supports seamless integration by allowing Claude Code traces to be nested under existing LangSmith runs, providing a complete view within broader traced workflows.

This document details the LangSmith Tracing Plugin for Claude Code, a specialized plugin designed to integrate Claude Code's operational insights with LangSmith, a platform for observing and evaluating large language model applications. The plugin's core methodology involves instrumenting Claude Code's runtime to capture and export execution traces, conversation states, and tool interactions to a designated LangSmith project.

Core Methodology and Tracing Mechanism:

The plugin operates by intercepting key events within a Claude Code session and transforming them into structured LangSmith traces. It captures the following granular details:

  1. LLM Run Tracing: For each interaction involving the underlying language model, the plugin records:
    • Inputs: The accumulated conversation messages provided to the LLM.
    • Outputs: The generated assistant response content.
    • Metadata: Comprehensive contextual information including ls_provider (e.g., "anthropic"), ls_model_name, ls_invocation_params (detailing the specific model and stop reason), and token usage metrics.
  2. Tool Run Tracing: When Claude Code invokes an external tool, the plugin logs:
    • The tool name that was executed.
    • The specific inputs provided to the tool.
    • The output content returned by the tool's execution.
  3. Conversation State Tracing: The plugin actively monitors the status of conversation turns. If a user interrupts a response midway, the corresponding run in LangSmith is explicitly marked with a status of "interrupted".

The integration is configured primarily through environment variables, which can be set either via Claude Code's internal settings file (~/.claude/settings.json) or standard shell environment variables (.zshrc, .bashrc, etc.). Key variables include TRACE_TO_LANGSMITH (must be "true" to enable tracing), CC_LANGSMITH_API_KEY (your LangSmith API key), and CC_LANGSMITH_PROJECT (the target LangSmith project name, defaulting to "claude-code"). Optional variables like LANGSMITH_ENDPOINT allow specifying a custom LangSmith API base URL, CC_LANGSMITH_DEBUG enables verbose logging, and CC_LANGSMITH_PARENT_DOTTED_ORDER facilitates nesting.

Programmatic Integration and Trace Nesting:

A significant feature is the ability to nest Claude Code traces within an existing LangSmith run hierarchy. This is particularly useful when Claude Code is invoked as a subprocess within a larger, already-traced application workflow. By leveraging LangSmith's RunTree concept, the dotted_order identifier of a parent run can be passed as the CC_LANGSMITH_PARENT_DOTTED_ORDER environment variable to the claude CLI command. This results in a trace structure where the Claude Code Turn (represented as a chain) becomes a child of the Your outer run (chain), with individual Claude (llm) and Tool runs nested further as children of the Claude Code Turn. Examples in Python (using subprocess.run) and TypeScript (using node:child_process.execSync) illustrate this seamless integration pattern.

Known Limitations:

A current limitation is that subagents are only traced upon their completion. Consequently, if a conversation turn is interrupted while a subagent is actively running, the in-progress subagent runs will not be captured and traced in LangSmith.

The plugin requires Node.js v18+ for installation and development, which can be performed via Claude Code's plugin marketplace commands or by building from source using pnpm.