Unlimited Claude Code Access
Claude Code is Anthropic's official command-line agent for software development. It operates with a 200k context window, spawns subagents with their own independent contexts, reads entire files into conversation history, and resends the full context with every turn — creating quadratic token growth over long sessions. This makes it one of the most token-intensive developer tools available. Connecting Claude Code to a flat-rate unlimited gateway transforms it from a carefully rationed tool into a true always-on development partner.
Why Claude Code's Token Consumption Grows Quadratically
Claude Code is stateless between turns from the API's perspective. Every message you send includes the entire conversation history — all previous messages, all file contents that were read, all tool results, all assistant responses. The first message might be 5,000 tokens. By the tenth exchange, you are sending 50,000 tokens of history plus whatever new content was added. By the twentieth exchange, the context can exceed 150,000 tokens per request.
Subagents make this worse. When Claude Code delegates work to a subagent, that agent gets its own context window and starts accumulating its own history independently. The parent agent's context grows to include the subagent's summary, while the subagent itself runs up its own token bill. Agent teams — where multiple subagents collaborate — multiply this further. A complex task might have a parent agent and three subagents, each with 100k+ tokens of context, all running on the same API key.
The /compact command helps by summarizing history and truncating old context, but it is a manual intervention that trades detail for space. On per-token billing, users compulsively compact to control costs. On unlimited, you can let conversations grow naturally, compact only when context quality degrades, and use subagents freely without mental arithmetic about their cost.
Environment Variable Configuration
Claude Code reads its API configuration from environment variables. The two essential variables are ANTHROPIC_BASE_URL and either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN. Set ANTHROPIC_BASE_URL to https://unlimited.aiprimetech.io — the root host without /v1, because the Anthropic SDK appends the API path automatically. For the key, use ANTHROPIC_API_KEY if your gateway expects x-api-key header authentication (standard Anthropic format).
Set these in your shell profile (.bashrc, .zshrc, or PowerShell $PROFILE) for persistent configuration. On Windows, you can also set them as system environment variables through the Advanced System Settings dialog. Claude Code reads them on startup — if you change them, restart the Claude Code session for the new values to take effect.
For per-project overrides, create a .env file in your project root. Claude Code loads .env files from the working directory. This lets you use different API configurations per project — useful if you have some projects on unlimited and others on direct Anthropic billing. The .env file takes precedence over system environment variables.
Model Mapping for Sonnet, Opus, Haiku, and Fable
Claude Code uses internal model aliases that you can override with environment variables. ANTHROPIC_DEFAULT_SONNET_MODEL controls what model is used for the default 'sonnet' selection. ANTHROPIC_DEFAULT_OPUS_MODEL overrides the 'opus' choice. ANTHROPIC_DEFAULT_HAIKU_MODEL and ANTHROPIC_DEFAULT_FABLE_MODEL control the remaining tiers. Set these to the exact model IDs your gateway supports.
For example, set ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-5 and ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-6. When you select a model tier in Claude Code using /model or the startup flag, it resolves to whatever you mapped. This is particularly useful if the gateway exposes custom model identifiers or if you want to pin specific model versions.
On unlimited, the model choice is purely a quality-versus-speed decision. There is no cost difference between tiers. Use Opus as your default for maximum quality and only drop to Sonnet or Haiku when you need faster responses during rapid iteration. The /effort command further tunes how thoroughly Claude Code approaches each task — combine high effort with Opus for the most capable configuration.
Subagents, Agent Teams, and Background Agents
Claude Code can spawn subagents — independent Claude instances with their own context windows that handle delegated subtasks. When the main agent encounters a complex task, it can delegate research, implementation, or verification to subagents that work in isolation and report back. Each subagent starts with a fresh context and accumulates its own conversation history.
Agent teams extend this concept by allowing multiple subagents to collaborate on related work simultaneously. The main agent acts as a coordinator, dispatching work and synthesizing results. This is extremely powerful for large-scale changes — one subagent can refactor module A while another handles module B — but the API consumption scales linearly with the number of active agents.
Background agents run asynchronously while you continue working in the main session. They operate on separate tasks and report results when complete. On per-token billing, running multiple background agents simultaneously gets expensive fast. On unlimited, you can launch several background agents, let them work on different aspects of your project, and review their output when ready — all covered by the flat rate.
Set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 to prevent Claude Code from sending telemetry and non-essential requests. This is a good practice on any custom gateway to reduce noise. Additionally, CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 tells Claude Code to query the gateway for available models rather than using hardcoded lists.
Headless Mode and CI/CD Integration
Claude Code's headless mode (--headless flag) runs without interactive prompts, making it suitable for CI/CD pipelines, automated code review, and batch processing. In headless mode, Claude Code reads input from stdin or command-line arguments and outputs results to stdout. It terminates when the task is complete rather than waiting for further input.
For CI integration, set the environment variables in your pipeline configuration (GitHub Actions secrets, GitLab CI variables, Jenkins credentials) and invoke Claude Code with the task description as an argument. Common CI use cases include automated PR review, documentation generation, test writing, and migration scripts.
On unlimited, headless mode unlocks high-throughput workflows. You can run Claude Code across every PR in a repository, generate test suites for untested modules in batch, or automate documentation updates on every release — all without per-invocation cost concerns. The flat rate covers the entire volume as long as it stays within fair-use rate limits.
CLAUDE.md Project Memory and Hooks
CLAUDE.md files provide persistent project context that Claude Code loads automatically. Place a CLAUDE.md at your project root with coding standards, architecture decisions, common patterns, and project-specific instructions. This content is included in every request's system prompt, adding tokens to every call but dramatically improving response quality and consistency.
On per-token billing, users keep CLAUDE.md minimal to control costs — every word adds tokens to every single request for the lifetime of the session. On unlimited, write as much context as genuinely helps: detailed architecture docs, full style guides, dependency explanations, team conventions. The extra tokens per request cost nothing extra and the quality improvement compounds over every interaction.
Hooks allow you to run custom scripts at specific points in Claude Code's execution — before and after tool calls, on session start, on compact. Use hooks to inject dynamic context, validate changes against CI, auto-format code, or trigger notifications. Hooks integrate with the unlimited gateway seamlessly since they operate at the CLI level rather than the API level.
Troubleshooting Claude Code Gateway Issues
If Claude Code cannot connect, verify ANTHROPIC_BASE_URL is set to the root host without /v1. Run echo $ANTHROPIC_BASE_URL (or $env:ANTHROPIC_BASE_URL on PowerShell) to confirm the value. The SDK appends /v1/messages automatically — if you include /v1 in the base URL, requests go to /v1/v1/messages which returns a 404.
Model-not-found errors mean the model ID in your mapping variable does not match what the gateway serves. Check the exact supported identifiers in your AI Prime Tech dashboard and update ANTHROPIC_DEFAULT_SONNET_MODEL accordingly. Remember that model IDs are case-sensitive and include version suffixes.
If sessions work but subagents fail, the issue may be that subagents inherit environment variables differently depending on how they are spawned. Ensure your environment variables are set at the system level rather than only in the current shell session, especially on Windows where child processes may not inherit shell-local variables.
# Shell environment (add to .bashrc / .zshrc / $PROFILE)
export ANTHROPIC_BASE_URL="https://aiprimetech.io"
export ANTHROPIC_API_KEY="<your AI Prime Tech Unlimited key>"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
# Or per-project .env file:
# ANTHROPIC_BASE_URL=https://aiprimetech.io
# ANTHROPIC_API_KEY=sk-...
# ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-5
# Run Claude Code:
# claude (interactive)
# claude --headless (CI/CD mode)
Frequently asked questions
Why does Claude Code use so many more tokens than chat?
Claude Code resends the full conversation history with every turn — it is stateless on the API side. As the session grows, each request carries all previous messages, file contents, and tool results. This creates quadratic token growth where the 20th message in a session can be 10-20x larger than the first.
Do subagents count against my usage separately?
Each subagent runs its own independent conversation with its own context window. On the unlimited plan, all agent conversations — parent, subagents, background agents — are covered by the flat rate. There is no per-agent or per-conversation surcharge.
Should I include /v1 in ANTHROPIC_BASE_URL?
No. Set it to the root host: https://unlimited.aiprimetech.io — the Anthropic SDK automatically appends /v1/messages. Including /v1 in the variable causes a doubled path that returns 404 errors.
Can I use Claude Code headless mode in CI/CD with unlimited?
Yes. Set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY in your pipeline secrets and run claude --headless with task arguments. The unlimited plan covers CI usage at the same flat rate, subject to fair-use rate limits.
How do I switch models in Claude Code?
Use the /model command during a session or set ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_OPUS_MODEL environment variables to control which models are used for each tier. On unlimited there is no cost difference between models.
Get an API key — no Anthropic account or waitlist required.
Get your API keyAI Prime Tech is an independent API gateway. It is not affiliated with, endorsed by, or a reseller of Anthropic. Claude and related model names are trademarks of their respective owners.