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
This page covers observability via OpenTelemetry. To enforce LangGuard policies on each tool call inside Claude Code, install the Arbiter plugin. See Arbiter Deployment.
Environment Variable Setup
Configure Claude Code to send OpenTelemetry traces directly to LangGuard by setting the following environment variables.
Required Variables
| Variable | Value | Description |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | https://app.langguard.ai | LangGuard OTLP endpoint |
OTEL_EXPORTER_OTLP_PROTOCOL | http/json | Protocol for OTLP export |
OTEL_SERVICE_NAME | claude-code-agent | Service 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"
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:
| Event | Description |
|---|---|
| Session start | When Claude Code is launched |
| Session end | When the session completes or is terminated |
| Conversation turns | Each 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
- Verify environment variables are set correctly
- Restart your terminal after adding variables
- 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
- Check that the endpoint URL is correct
- Verify your network allows outbound HTTPS connections
- Contact support if issues persist
Next Steps
- Integrations Overview - See all available integrations
- Policies - Apply governance rules to agent traces