Claude Code through PromptGate
This recipe routes Claude Code’s traffic through your PromptGate instance. The result: Claude Code keeps doing exactly what it does, but every prompt + response is recorded, every cost is in your dashboard, every secret leak is caught.
Prerequisites
Section titled “Prerequisites”- A PromptGate instance reachable from your laptop (e.g.
http://localhost:8080for self-host or your deployed URL). - An Anthropic credential configured under Credentials.
1. Create an Agent Proxy project
Section titled “1. Create an Agent Proxy project”Projects → Create project → name it (e.g. Engineering Egress), pick Agent Proxy as the type. Default-secure guardrails (Reversible Redaction, Secret Scanner) become available under the Guardrails tab.
2. Enable the Anthropic provider
Section titled “2. Enable the Anthropic provider”On the project’s Setup → Providers tab, toggle Anthropic on and pick the credential you set up.
3. Quick-issue a token (one-click) — optional but recommended
Section titled “3. Quick-issue a token (one-click) — optional but recommended”Setup → Overview → Quick setup · Local token → Generate local token. PromptGate mints a fresh chat-scoped token, fills it directly into each agent’s config snippet on the page, and shows it exactly once. Just click Copy on the Claude Code snippet and paste into your shell.
The token shows up as local · <hostname> · <YYYY-MM-DD HH:MM> on the Tokens page — revoke any time.
If you’d rather mint manually: API Tokens → New token with the chat scope and copy the plaintext.
4. Point Claude Code at PromptGate
Section titled “4. Point Claude Code at PromptGate”From the Quick-setup card on the Setup page, click Copy on the Claude Code snippet:
ANTHROPIC_BASE_URL=https://your-promptgate-host/api/<project-uuid>ANTHROPIC_AUTH_TOKEN=pg_live_...Paste in your shell, restart Claude Code. From its perspective nothing changed — it’s still calling the Anthropic Messages API at /v1/messages.
5. Verify
Section titled “5. Verify”Run any Claude Code session, then open Live Logs in PromptGate. Each request appears immediately with prompt + response + token count.
Cost optimisation
Section titled “Cost optimisation”The killer follow-up: route small prompts to a cheaper model. Define a wrapper alias claude-fast that points at anthropic:claude-haiku-… and have Claude Code use the fast model for trivial tasks:
# In the same project, add a routing rule on the alias:# when input_tokens < 4000 → claude-haiku# else → claude-3-5-sonnetPer-team experience varies, but typical savings on coding-agent traffic are 70-85% because the bulk of requests are small “what does this function do?” prompts that Haiku handles fine.
Security follow-up
Section titled “Security follow-up”- Enable Reversible Redaction with
email,phone, and a fewcustom_patternsfor your customer-id format. Your developers paste real customer data into Claude Code; the LLM only ever sees[[CUSTOMER_001]]. - Enable Secret Scanner in
blockmode. The first time someone copy-pastes a.envfile with an AWS key into Claude Code, PromptGate intercepts loudly. - Subscribe to webhooks for
endpoint.anomalyso a sudden spend spike pages whoever is on call.
Troubleshooting
Section titled “Troubleshooting”- 401 from Claude Code: the
ANTHROPIC_AUTH_TOKENenv doesn’t carry a validpg_live_…token, or the token’s scopes don’t includechat. - 400 “This project is not an AI Wrapper or Agent Proxy”: the token was issued under an
ai_gatewayproject. Tokens are project-scoped — issue a new one under the Agent Proxy project. - All requests blocked: check Guardrails → Secret Scanner. Block mode is loud by design; switch to
redactif you want to keep working with secret-bearing prompts.
© Akyros Labs LLC. All rights reserved.