# Claude Code & Tools

> Connect Claude Code to the Noirdoc gateway or mask local files and paths directly on your machine with the Claude Code plugin and the noirdoc CLI.

- **Source:** https://www.noirdoc.de/en/docs/tools/
- **API base URL:** `https://api.noirdoc.de/v1`

## Claude Code through the gateway

Route Claude Code through the Noirdoc gateway to Claude models from [`GET /v1/models`](/en/docs/keys-billing/#modelle-preise) (Claude Code is built for Claude models and does not support other models through a gateway):

### 1. Set environment variables and start

Set `ANTHROPIC_BASE_URL` to `https://api.noirdoc.de` (without `/v1`) and `ANTHROPIC_AUTH_TOKEN` to your `px-` key; select a Claude model such as `claude-sonnet-5-5` via `ANTHROPIC_MODEL`. Turn on [Noirdoc Shield](/en/docs/shield/) via `ANTHROPIC_CUSTOM_HEADERS` or directly on the API key (`shield_mode` set to **On**).

**Start Claude Code**

```bash
export ANTHROPIC_BASE_URL="https://api.noirdoc.de"
export ANTHROPIC_AUTH_TOKEN="$NOIRDOC_API_KEY"
export ANTHROPIC_MODEL="claude-sonnet-5-5"
export ANTHROPIC_CUSTOM_HEADERS="X-Noirdoc-Shield: on"
claude
```

| Environment variable       | Effect                                                                                                             |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `ANTHROPIC_BASE_URL`       | Base URL `https://api.noirdoc.de` without `/v1` (Claude Code appends `/v1/messages` itself).                       |
| `ANTHROPIC_AUTH_TOKEN`     | Sends your `px-` key as `Authorization: Bearer`. Do not set alongside `ANTHROPIC_API_KEY`.                         |
| `ANTHROPIC_API_KEY`        | Alternative to `ANTHROPIC_AUTH_TOKEN`; sends your `px-` key as `x-api-key` (set only one of the two variables).    |
| `ANTHROPIC_MODEL`          | Claude model ID from `GET /v1/models` (for example `claude-sonnet-5-5` or `claude-haiku-4-5`).                     |
| `ANTHROPIC_CUSTOM_HEADERS` | Additional headers, one `Name: Value` pair per line (for example `X-Noirdoc-Shield: on` or `X-Noirdoc-Tags: ...`). |

> **Preflight token counting:** Claude Code counts context tokens beforehand via `POST /v1/messages/count_tokens`. This call skips
> Noirdoc Shield at €0 (for Claude on Google Vertex AI, the gateway forwards to the Vertex counting
> method; see [Messages](/en/docs/reference/messages/#messages)), while actual `POST /v1/messages`
> requests run through Shield when enabled.

### 2. Add project context to CLAUDE.md or AGENTS.md

When your project integrates the Noirdoc gateway in code, add this short block to `CLAUDE.md` or `AGENTS.md` so coding agents consistently follow base URL, header and error-handling conventions:

**AGENTS.md / CLAUDE.md**

```markdown
# Noirdoc Gateway

- Base URL: `https://api.noirdoc.de/v1` (Anthropic SDK: omit `/v1`)
- Auth: `Authorization: Bearer $NOIRDOC_API_KEY` (`px-` key,
  server-side only)
- Shield: send `X-Noirdoc-Shield: on` for stateless pre-flight checks
- Error handling: always branch on `error.code`, never `error.message`
- Up-to-date docs (Markdown): `https://www.noirdoc.de/llms.txt` and
  `https://www.noirdoc.de/en/llms-full.txt` (DE: `/llms-full.txt`)
```

## Local Claude Code plugin

The open-source Claude Code plugin (MIT licence, usable independently of the gateway) connects the local `noirdoc` CLI directly with Claude Code. The plugin intercepts reads of protected paths, hands Claude a copy masked locally with placeholders such as `<<PERSON_1>>` and stores responses containing placeholders; you put the original values back in your own terminal outside Claude Code.

**Claude Code**

```text
/plugin marketplace add nextaim-de/noirdoc-claude-plugin
/plugin install noirdoc@nextaim
/noirdoc:noirdoc-setup
```

> **Local tool privacy pattern:** Keep plaintext data on your own machine when working with local tools and agents: the plugin and
> the `noirdoc` CLI substitute personal and client details with consistent placeholders before
> anything leaves disk, so the model reasons over structure and placeholders while you restore
> originals locally afterwards.

Source code, path rules and commands are documented at [github.com/nextaim-de/noirdoc-claude-plugin](https://github.com/nextaim-de/noirdoc-claude-plugin#readme).

## noirdoc CLI for documents

The Python package `noirdoc` (MIT licence) replaces personal data in PDF, DOCX, XLSX and plain-text files locally on your machine with consistent placeholders such as `<<PERSON_1>>`. With `--namespace`, placeholders stay identical across multiple files, and `noirdoc reveal` restores the original values locally. This makes the CLI well suited to sanitising binary office documents (PDF, DOCX, XLSX) beforehand or applying reversible pseudonymisation locally, whereas [Noirdoc Shield](/en/docs/shield/) in the gateway statelessly inspects and redacts inbound text without storing mappings.

**noirdoc CLI**

```bash
pip install "noirdoc[full]"
noirdoc redact --namespace client-mueller \
  letter.docx -o letter-masked.docx
noirdoc reveal --namespace client-mueller \
  letter-masked.docx -o letter.docx
```

Source code, supported formats and options are documented at [github.com/noirdoc-ai/mask-engine](https://github.com/noirdoc-ai/mask-engine#readme).
