DEV Community

Cover image for Audit Claude Code usage and govern it across a team
AgentKeyRoute
AgentKeyRoute

Posted on Edited on Originally published at agentkeyroute.com

Audit Claude Code usage and govern it across a team

Claude Code reads your repository, runs commands and sends what it reads to a model. Once more than a few developers use it, someone asks who is using it, what leaves the laptop, what it costs, and how you would prove any of that later. This guide puts a gateway in the path so those questions have answers.

The examples use AgentKeyRoute, an AI governance gateway (our product). Claude Code's side of the setup uses its documented LLM gateway settings.

How the request path works

Claude Code speaks the Anthropic API. You change two things: the address it calls and the credential it sends. The gateway accepts the request on /v1/messages, identifies the key, scans the content, applies the key's governance profile and your routing rules, redacts what needs redacting, forwards the call to an allowed model, then meters and records it.

Your provider credentials stay in the gateway. Developers hold only a gateway key, which can expire and can be revoked on its own.

Step 1: Add a provider and say what it is

In the console, open Providers & models, add Anthropic, Bedrock, Azure, Vertex AI or a self-hosted endpoint, and paste its key. Then mark where it runs (public, private cloud or on-prem) and tick only the contracts and attestations you actually hold.

This matters more than it looks. The coding profile used below applies SOC 2, which only lets sensitive data reach providers marked SOC 2 Type II or ISO 27001, or on-prem models. New organisations also start with routing rules that keep personal and confidential data off public APIs: personal-data-off-public-internet and confidential-private-cloud. If your only provider is a public API, some coding requests may be refused. That is the gateway failing closed, but decide on purpose where source code may go before you roll out.

Step 2: Create one key per developer

Open Connect an app, pick Claude Code, and describe who uses it and what data it sees. The recommended profile is usually Coding agents & developer tools. As shipped, it:

  • always blocks credentials and API keys
  • blocks card data and patient data
  • redacts personal data before it leaves for destinations that are not on-prem
  • blocks requests that look like prompt injection
  • allows source code, subject to the provider requirements above
  • asks for redacted content capture and one year of retention, within what your plan allows

Give each developer their own key. A shared key tells you the team spent money; a personal key tells you who, and lets you cut off one lost laptop without breaking everyone else.

Step 3: Point Claude Code at the gateway

Install it if you haven't:

npm install -g @anthropic-ai/claude-code
Enter fullscreen mode Exit fullscreen mode

For a quick test in one terminal:

export ANTHROPIC_BASE_URL="https://gateway.agentkeyroute.com"
export ANTHROPIC_AUTH_TOKEN="<your API key>"
export ANTHROPIC_MODEL="claude-sonnet"
claude
Enter fullscreen mode Exit fullscreen mode

The Anthropic base URL is the gateway address without /v1. Adding it is the usual cause of a 404. claude-sonnet is an example; list the models your key may use with:

curl https://gateway.agentkeyroute.com/v1/models \
  -H "Authorization: Bearer <your API key>"
Enter fullscreen mode Exit fullscreen mode

To make it permanent, put the same values in the developer's ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://gateway.agentkeyroute.com",
    "ANTHROPIC_AUTH_TOKEN": "<your API key>",
    "ANTHROPIC_MODEL": "claude-sonnet"
  }
}
Enter fullscreen mode Exit fullscreen mode

Keep the key out of the project's .claude/settings.json, which tends to get committed. Set both the URL and the token: Anthropic's docs note that with only the base URL set, a saved claude.ai login remains the active credential.

Claude Code also uses a smaller model for background tasks. If those calls fail, set ANTHROPIC_DEFAULT_HAIKU_MODEL to a model your key may use (environment variables).

Step 4: Roll the address out with managed settings

Asking people to edit a file works for a pilot. For a team, push the gateway address through Claude Code's managed settings, which user and project settings cannot override (the docs list a few security-sensitive exceptions). The file lives at:

  • macOS: /Library/Application Support/ClaudeCode/managed-settings.json
  • Linux and WSL: /etc/claude-code/managed-settings.json
  • Windows: C:\Program Files\ClaudeCode\managed-settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://gateway.agentkeyroute.com"
  }
}
Enter fullscreen mode Exit fullscreen mode

Distribute the address centrally and each developer's key individually.

Settings management is configuration, not a network boundary. If you need to be sure nothing bypasses the gateway, also restrict direct egress to model APIs and keep raw provider keys off developer machines. Note too that Claude Code disables Remote Control while the base URL points somewhere other than Anthropic.

Step 5: Attribute requests to a person

A per-developer key already separates people. If you want a readable identity on each record, add the X-AIGov-User header:

{
  "env": {
    "ANTHROPIC_CUSTOM_HEADERS": "X-AIGov-User: alice@example.com"
  }
}
Enter fullscreen mode Exit fullscreen mode

Merge this into the env block from step 3. Anthropic's docs say this variable needs a recent version (v2.1.227 or later), so check what your team runs. The header is client-supplied, so treat the key as the stronger identity.

Step 6: Verify before you trust it

  1. In Claude Code, run /status. You should see an Anthropic base URL line, and an Auth token line naming ANTHROPIC_AUTH_TOKEN.
  2. Ask it something trivial, then open Requests in the console. The entry shows what was detected, which rule matched, which model answered, what was redacted, tokens, cost and latency.
  3. Paste a fake but realistically formatted API key into a prompt. It should be refused with data_blocked.
  4. Open API keys, select the key, and read which models each class of data would be routed to, or why it would be blocked.

Every response carries X-AIGov-Request-Id and every error message ends with it, so a developer who hits a refusal can send you one string and you can see the full decision trace. If prompt-injection blocking misfires on your codebase, adjust the sensitivity on the profile and test in the Playground, which calls no model.

What you get

Audit. Decisions and configuration changes are hash-chained, so editing or deleting a record breaks the chain. You can verify it in one click and export it. On Business and Enterprise plans you can also stream decisions and incidents to Splunk, Microsoft Sentinel, Datadog or a webhook.

Redaction and blocking. Detection covers secrets, personal, health and card data and more, using patterns, checksums and context. It reads text only: attachments such as screenshots are not scanned, so block them under the profile's content limits if that is a risk.

Budgets and kill switches. Each app registered through Connect an app is a workload with an owner and an optional monthly budget; when it is spent, requests return budget_exceeded. For a budget per developer, register one app per developer. You can stop a single key, a workload, a provider or everything.

Cost. Spend is attributed to app, team, person and model. For Claude usage that does not pass through the gateway, you can import daily totals per person from Anthropic's Usage & Cost API with an admin key. That import has no conversation content.

Plan limits. The Free plan covers a small pilot: 3 users, 3 keys, 3 apps, 25,000 requests a month, 7-day retention and no content capture. Check pricing for larger teams.

Deploying air-gapped

AgentKeyRoute can run on-premises with no internet access, as an Enterprise plan deployment. Load the container images with docker save and docker load, add your own models as Ollama or vLLM providers marked on-prem, and set MODEL_CATALOG_URL=off and OPENROUTER_ZDR_URL=off. Leave Stripe and SMTP unset.

Claude Code is then pointed at your internal gateway address. How well it performs depends heavily on the local model, especially for tool use, so test on real tasks first. Check Claude Code's own network traffic too; CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC is documented, and your egress firewall is the real proof.

Start with a small pilot

Pick two or three developers, issue them keys, run for a week and read the Requests view. You will learn which rules are too strict and what your team actually sends. See AgentKeyRoute for startups, or for enterprises if you need company-wide controls or on-premises deployment, and sign up free.

Sources


Originally published at agentkeyroute.com. AgentKeyRoute is an AI governance gateway for coding agents, apps and AI websites.

Top comments (0)