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

  1. Set up an agentgateway proxy.
  2. Install the Claude Code CLI (npm install -g @anthropic-ai/claude-code).
  3. 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:80

Set up the Anthropic backend

Create a secret, backend, and route to proxy Claude Code traffic through agentgateway.

  1. Export your Anthropic API key.

    export ANTHROPIC_API_KEY="sk-ant-your-key-here"
  2. 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
    EOF
  3. Create an AgentgatewayBackend with the /v1/messages route 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
    EOF

    Pin 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
    EOF
  4. Create an HTTPRoute to forward all traffic to the Anthropic backend. This route uses a / path prefix so that all requests, including /v1/messages and /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

  1. Send a single test prompt through agentgateway.

    claude -p "Hello"
  2. Verify the request appears in the agentgateway proxy logs.

    kubectl logs deployment/agentgateway-proxy -n agentgateway-system --tail=5

    Example 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=706ms
  3. Optionally, start Claude Code in interactive mode.

    claude

    Every request, including prompts, tool calls, and file reads, flows through agentgateway.

Next steps

Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.