Skip to main content

Claude Code Integration

Claude Code is Anthropic's CLI tool for AI-assisted software development. The LangGuard integration captures traces, agent activity, and telemetry via OpenTelemetry.

Overview

The Claude Code integration enables LangGuard to:

  • Real-time trace ingestion from Claude Code
  • Agent activity and conversation monitoring
  • Tool usage and performance metrics
  • Compatible with any OTEL collector
  • Seamless integration with LangGuard's observability platform

Environment Variable Setup

Configure Claude Code to send OpenTelemetry traces directly to LangGuard by setting the following environment variables.

Required Variables

VariableValueDescription
OTEL_EXPORTER_OTLP_ENDPOINThttps://app.langguard.aiLangGuard OTLP endpoint
OTEL_EXPORTER_OTLP_PROTOCOLhttp/jsonProtocol for OTLP export
OTEL_SERVICE_NAMEclaude-code-agentService name (optional)

Installation & Setup

macOS/Linux

Add the following to your ~/.bashrc or ~/.zshrc:

# Add to ~/.bashrc or ~/.zshrc
export OTEL_EXPORTER_OTLP_ENDPOINT="https://app.langguard.ai"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/json"
export OTEL_SERVICE_NAME="claude-code-agent"

Then reload your shell configuration:

source ~/.bashrc  # or source ~/.zshrc

Windows (PowerShell)

Add the following to your PowerShell profile:

# Add to PowerShell profile
$env:OTEL_EXPORTER_OTLP_ENDPOINT="https://app.langguard.ai"
$env:OTEL_EXPORTER_OTLP_PROTOCOL="http/json"
$env:OTEL_SERVICE_NAME="claude-code-agent"
Finding Your PowerShell Profile

Run $PROFILE in PowerShell to see the path to your profile file. Create it if it doesn't exist.

What Gets Captured

Agent Sessions

Each Claude Code session is tracked:

EventDescription
Session startWhen Claude Code is launched
Session endWhen the session completes or is terminated
Conversation turnsEach interaction with the agent

Tool Usage

All tool invocations are monitored:

  • File reads and writes
  • Shell command execution
  • Code edits and modifications
  • Search operations

Performance Metrics

  • Response latency
  • Token usage
  • Tool execution time
  • Error rates

Troubleshooting

No Traces Appearing

  1. Verify environment variables are set correctly
  2. Restart your terminal after adding variables
  3. Check network connectivity to the LangGuard endpoint

Environment Variables Not Loading

macOS/Linux:

  • Ensure you've sourced your shell config (source ~/.zshrc)
  • Verify with echo $OTEL_EXPORTER_OTLP_ENDPOINT

Windows:

  • Restart PowerShell after updating profile
  • Verify with echo $env:OTEL_EXPORTER_OTLP_ENDPOINT

Connection Errors

  1. Check that the endpoint URL is correct
  2. Verify your network allows outbound HTTPS connections
  3. Contact support if issues persist

Next Steps