DocsClaude Code Integration

Claude Code Integration

Route Claude Code traffic through Grepture for observability, cost tracking, and PII protection. Set up in under 2 minutes.

Overview

Claude Code is Anthropic's CLI tool for agentic coding. By routing Claude Code through Grepture, you get:

  • Observability — log every request and response in your Grepture dashboard
  • Cost tracking — see per-request token usage and spend across your team
  • PII redaction — detect and redact sensitive data before it reaches Anthropic

Setup takes under 2 minutes. No SDK installation required — just three environment variables.

Prerequisites

  1. A Grepture account (sign up here)
  2. Your Grepture API key (find it in the dashboard under API)
  3. An Anthropic API key for Claude Code
  4. Claude Code installed (npm install -g @anthropic-ai/claude-code)

Configuration

Claude Code reads its configuration from ~/.claude/settings.json (global) or .claude/settings.json (per-project). Add the following environment variables:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://proxy.grepture.com/claude",
    "ANTHROPIC_API_KEY": "sk-ant-api03-your-key-here",
    "ANTHROPIC_CUSTOM_HEADERS": "x-grepture-api-key: grp_your-key-here"
  }
}
VariableDescription
ANTHROPIC_BASE_URLPoints Claude Code at the Grepture proxy instead of the Anthropic API directly
ANTHROPIC_API_KEYYour Anthropic API key — forwarded to Anthropic by the proxy
ANTHROPIC_CUSTOM_HEADERSYour Grepture API key, sent as a custom header for authentication

How it works

When Claude Code makes a request:

  1. The request is sent to https://proxy.grepture.com/claude/v1/messages
  2. Grepture authenticates you using the x-grepture-api-key header
  3. Your detection rules are applied (PII redaction, secret scanning, etc.)
  4. The request is forwarded to https://api.anthropic.com/v1/messages with your Anthropic API key
  5. The response flows back through Grepture, where it is logged and any redacted tokens are restored

The /claude prefix is stripped before forwarding, so Anthropic receives a standard /v1/messages request.

Verify it works

After configuring, run Claude Code normally:

claude

Then open your Grepture dashboard. You should see Claude Code requests appearing in the traffic log with:

  • Model name (e.g. claude-sonnet-4-20250514)
  • Token counts (input + output)
  • Cost per request
  • Full request/response bodies (if logging is enabled)

Team setup

For teams, add the configuration to a shared .claude/settings.json in your repository. Each developer uses their own ANTHROPIC_API_KEY, but the ANTHROPIC_BASE_URL and x-grepture-api-key can be shared across the team.

This gives you a single dashboard view of all Claude Code usage across your organization — useful for tracking spend, auditing prompts, and enforcing data protection policies.

Detection rules

All Grepture detection rules apply to Claude Code traffic, including:

  • PII detection — emails, phone numbers, SSNs, credit cards, and 50+ patterns
  • Secret scanning — API keys, tokens, connection strings
  • Custom regex rules — your own patterns (Pro plan)
  • AI-powered NER — names, organizations, addresses (Pro plan)

Configure rules in the Grepture dashboard under Rules. They apply automatically to all traffic, including Claude Code.

Troubleshooting

Claude Code returns an authentication error

Verify your ANTHROPIC_API_KEY is valid by testing directly against Anthropic:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-4-20250514","max_tokens":10,"messages":[{"role":"user","content":"Hi"}]}'

Requests don't appear in the dashboard

Check that your x-grepture-api-key is correct and that ANTHROPIC_BASE_URL is set to https://proxy.grepture.com/claude (note the /claude suffix).

Latency increase

The proxy adds minimal latency (typically under 10ms). If you experience higher latency, check your network route to the proxy. Grepture is EU-hosted — if your team is outside Europe, contact us about regional deployment options.