# Claude Code through Grodmir

Tested with Claude Code 2.1 against a live gateway (`dataplane/tests/test_agents_live.py`).

## 1. Point it at the gateway

```sh
export ANTHROPIC_BASE_URL=https://aiguard.example.com   # your data plane
export ANTHROPIC_API_KEY=aig_...                         # a virtual key, never a provider key
claude
```

Provider keys exist only in the gateway. The model only sees tokens such as `[PERSON_1]`; the
gateway puts the original values back in the answer Claude Code receives.

## 2. Repository rules and client assignment (optional)

With a [`.aiguard.yaml`](https://grodmir.com/dokumentacja/zrodla/repo-rules.md) in the repository, start Claude Code like this:

```sh
export ANTHROPIC_CUSTOM_HEADERS="$(aiguard repo headers --format claude)"
claude
```

A shell function makes it automatic:

```sh
claude-guarded() { ANTHROPIC_CUSTOM_HEADERS="$(aiguard repo headers --format claude)" claude "$@"; }
```

## 3. Block excluded files before they are read (optional)

Copy `deploy/integrations/claude-code/settings.json` to `.claude/settings.json` (commit it, so
the whole team gets it). `aiguard` must be on the `PATH` of the machine. The hook refuses Read,
Edit, Write, Grep, Glob and Bash calls that touch a path from `exclude_paths`.

## What to expect

- Requests with detected data are transformed or blocked per your policy; a block appears as an
  API error with the data categories and a request id.
- The gateway pseudonymises personal-data-like text in Claude Code's own system prompt too. The
  local NER model has false positives on such text (Phase 2 limitation, see
  `docs/progress/phase-5.md`); expect many `person.name` and `address` detections.
- Claude Code metadata (for example its session id) can be removed as a token-shaped secret.
- Hook and rule limits: see [repo-rules.md](https://grodmir.com/dokumentacja/zrodla/repo-rules.md#what-it-does-not-do).

## Verify

```sh
AIGUARD_TEST_CLAUDE_CODE=1 uv run pytest dataplane/tests/test_agents_live.py -k claude
```
