Claude Code
Configure Claude Code, the AI coding CLI by Anthropic, to route LLM requests through your agentgateway proxy running in Kubernetes.
Before you begin
- Set up an agentgateway proxy.
- Install the Claude Code CLI (
npm install -g @anthropic-ai/claude-code). - Get an Anthropic API key from the Anthropic Console.
Get the gateway URL
export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy \
-o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "Gateway address: $INGRESS_GW_ADDRESS"export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy \
-o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "Gateway address: $INGRESS_GW_ADDRESS"After port-forwarding, the gateway is accessible at http://localhost:8080. Use localhost:8080 wherever the instructions reference $INGRESS_GW_ADDRESS.
kubectl port-forward -n agentgateway-system svc/agentgateway-proxy 8080:80Set up the Anthropic backend
Create a secret, backend, and route to proxy Claude Code traffic through agentgateway.
Export your Anthropic API key.
export ANTHROPIC_API_KEY="sk-ant-your-key-here"Create a Kubernetes secret for your API key. For other authentication methods, see API keys.
kubectl apply -f- <<EOF apiVersion: v1 kind: Secret metadata: name: anthropic-secret namespace: agentgateway-system type: Opaque stringData: Authorization: $ANTHROPIC_API_KEY EOFCreate an AgentgatewayBackend with the
/v1/messagesroute and any other details such as models that you want to configure.Allow Claude Code to use any model. The
anthropic: {}syntax means no model is pinned.kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayBackend metadata: name: anthropic namespace: agentgateway-system spec: ai: provider: anthropic: {} policies: ai: routes: '/v1/messages': Messages '*': Passthrough auth: secretRef: name: anthropic-secret EOFPin the backend to a specific model. Make sure the model matches what Claude Code is configured to use.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayBackend metadata: name: anthropic namespace: agentgateway-system spec: ai: provider: anthropic: model: claude-sonnet-4-5-20250929 policies: ai: routes: '/v1/messages': Messages '*': Passthrough auth: secretRef: name: anthropic-secret EOFCreate an HTTPRoute to forward all traffic to the Anthropic backend. This route uses a
/path prefix so that all requests, including/v1/messagesand/v1/models, are forwarded to the backend.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: claude namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: / backendRefs: - name: anthropic namespace: agentgateway-system group: agentgateway.dev kind: AgentgatewayBackend EOF
Configure Claude Code
Set the ANTHROPIC_BASE_URL environment variable to point Claude Code at your gateway address.
export ANTHROPIC_BASE_URL="http://$INGRESS_GW_ADDRESS"kubectl port-forward -n agentgateway-system svc/agentgateway-proxy 8080:80 &
export ANTHROPIC_BASE_URL="http://localhost:8080"Verify the connection
Send a single test prompt through agentgateway.
claude -p "Hello"Verify the request appears in the agentgateway proxy logs.
kubectl logs deployment/agentgateway-proxy -n agentgateway-system --tail=5Example output:
info request gateway=agentgateway-system/agentgateway-proxy listener=http route=agentgateway-system/claude endpoint=api.anthropic.com:443 http.method=POST http.path=/v1/messages http.status=200 protocol=llm gen_ai.provider.name=anthropic gen_ai.request.model=claude-haiku-4-5-20251001 gen_ai.usage.input_tokens=14 gen_ai.usage.output_tokens=9 duration=706msOptionally, start Claude Code in interactive mode.
claudeEvery request, including prompts, tool calls, and file reads, flows through agentgateway.