This guide provides instructions for integrating Claude Code with the Truefoundry AI Gateway.

What is Claude Code?

Claude Code is Anthropic’s agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster through natural language commands. It serves as an intelligent pair programming partner that can read, analyze, and work with your entire project structure.

Key Features of Claude Code

  • Intelligent Code Understanding: Comprehends complex codebases with context-aware analysis, reading and understanding your entire project structure to offer relevant, intelligent assistance
  • Real-time Collaboration: Acts as a pair programming partner that actively collaborates by suggesting code, editing files, and executing command-line tools while keeping you in complete control
  • Full-Stack Development Support: Assists in building sophisticated applications from front-end design to back-end architecture, databases, and production-ready code across the entire development stack

Prerequisites

Before integrating Claude Code with TrueFoundry, ensure you have:
  1. TrueFoundry Account: Create a Truefoundry account with atleast one model provider and generate a Personal Access Token by following the instructions in Generating Tokens
  2. Claude Code Installation: Install Claude Code following the official documentation
  3. Configure models in Truefoundry for each provider you want to use

Integrate Truefoundry with Claude Code

Claude Code uses a settings.json file for configuration. You’ll need to modify the environment variables to route requests through Truefoundry. First, get the base URL and model name from your TrueFoundry AI Gateway playground using the unified code snippet (ensure you use the same model name as written):
TrueFoundry playground showing unified code snippet with base URL and model name highlighted for Claude Code integration

Get Base URL and Model Name from Unified Code Snippet

Claude Code can be configured either globally or per project by editing the settings file:
  • Global: ~/.claude/settings.json
  • Project-specific: .claude/settings.json in your project directory
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://{controlPlaneUrl}/api/llm/v1",
    "ANTHROPIC_CUSTOM_HEADERS": "Authorization: Bearer your-truefoundry-api-key\nx-tfy-provider-name: <tfy-provider-name>",
    "ANTHROPIC_MODEL": "anthropic/claude-3-5"
  }
}
Replace:
  • your-truefoundry-api-key with your TrueFoundry API key
  • tfy-provider-name with the TrueFoundry Provider name
  • controlPlaneUrl with your Control Plane URL
  • projectId with your Google Project Id
  • region with Region of the Model
  • Update the model name if using a different Claude model

Using Claude Code

After configuring the settings file, you can use Claude Code as normal. The Truefoundry AI Gateway will handle routing your requests to the appropriate provider based on your configuration.

Example Commands

# Get help with a coding problem
claude "How do I implement a binary search tree in Python?"

# Generate a script
claude "Create a script that processes CSV files and extracts specific columns"

# Debug code
claude "Debug this function: def factorial(n): if n == 0: return 1 else: return n * factorial(n)"