TL;DR: 에이전트 중심 워크플로우에서 Claude Code 토큰 비용은 각 도구 정의가 컨텍스트에 주입됨으로 인해 빠르게 증가합니다. Claude Code 앞에 있는 AI 게이트웨이에서는 응답을 캐싱하고, 더 저렴한 모델로 전환하며, 코드 모드를 사용하여 도구 정의 오버헤드를 줄일 수 있습니다. Bifrost 와 테스트한 설정에서 가장 큰 단일 최적화는 MCP 의 코드 모드로, 도구 정의 토큰을 58% 에서 92.8% 까지 줄입니다. 이 글은 Claude Code, MCP 서버 기본 개념, 그리고 CLI 에이전트에서 ANTHROPIC_BASE_URL 이 하는 일을 알고 있다는 가정하에 작성됩니다.
Claude Code 토큰 비용이 어디서 오나요?
일반적인 Claude Code 워크로드에서 비용을 주도하는 세 가지 요소가 있습니다. 첫째, 모델 자체입니다. 기본 Claude Code 는 대부분의 작업에 Sonnet 을 사용하고 어려운 작업에는 Opus 를 사용합니다. Opus 는 토큰당 Sonnet 보다 수 배 비싸고, Sonnet 은 Haiku 보다 수 배 비쌉니다.
둘째, 반복 작업입니다. Claude Code 는 장기간 세션에서 파일을 다시 읽으며, grep 를 재실행하고 동일한 문제를 다시 생각합니다. 두 개의 인접한 프롬프트가 동일한 코드 경로를 타격하면, 캐싱되지 않는 한 두 번째는 전체 비용이 청구됩니다.
셋째, MCP 도구 카탈로그입니다. 각 연결된 MCP 서버의 모든 도구 정의는 각 요청마다 컨텍스트에 주입됩니다. Anthropic 의 Model Context Protocol 개요는 프로토콜 수준에서 도구 발견이 어떻게 작동하는지 설명합니다. 몇 개의 서버가 연결되면 모델이 결코 호출하지 않을 도구를 설명하기 위해 토큰 수천을 지불할 수 있습니다.
게이트웨이는 세 가지 모두를 해결합니다.
단계 1: Claude Code 를 게이트웨이로 지시
Bifrost 의 경우, Claude Code 가 API 호스트를 발견하도록 읽는 환경 변수를 설정하세요.
export ANTHROPIC_BASE_URL = http://localhost:8080/anthropic
export ANTHROPIC_API_KEY = vk-prod-abc123
claude Bifrost 는 100% 호환되는 Anthropic 엔드포인트를 노출하므로, Claude Code 는 게이트웨이를 대화하고 있다는 것을 알지 못합니다. 완전한 통합 단계는 Bifrost Claude Code 문서에 있습니다.
단계 2: 필요할 때 Claude Code 를 더 저렴한 모델로 고정
Claude Code 는 시작 또는 세션 중 모델 오버라이드를 존중합니다. 게이트웨이에서는 Sonnet 을 기본 작업으로 고정하고, 필요할 때만 Opus 로 전환할 수 있습니다.
claude --model claude-sonnet-4-6
Bedrock 또는 Vertex 를 준수 이유로 라우팅하는 경우, 게이트웨이는 해당 백엔드로 매핑되는 핀ning 문법을 수용합니다:
export ANTHROPIC_DEFAULT_SONNET_MODEL = "bedrock/global.anthropic.claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_OPUS_MODEL = "vertex/claude-opus-4-7"
The Bifrost CLI agents 개요는 동일한 설정에서 Claude Code, Codex CLI, Gemini CLI 를 다룹니다.
단계 3: 의미론적 캐싱 활성화
Claude Code 는 동일한 세션 내에서 유사한 질문을 다시 묻습니다. 이중층 캐싱은 정확한 반복과 의미적으로 유사한 프롬프트를 모두 잡습니다.
semantic_cache : enabled : true
vector_store : weaviate
weaviate_url : ${WEAVIATE_URL}
similarity_threshold : 0.92
conversation_history_threshold : 3
ttl_seconds : 86400
각 요청은 캐싱에 참여하려면 x-bf-cache-key 헤더가 필요합니다. Claude Code 는 기본적으로 이 헤더를 설정하지 않으므로, 가상 키별로 Bifrost 를 주입하거나 CLI 호출을 헤더 설정 프로кси로 감싸야 합니다. 의미론적 캐싱 문서는 메커니즘을 다룹니다.
캐시는 모델과 제공자 격리되어 있으므로 Sonnet 응답은 Opus 요청에 절대 반환되지 않습니다.
단계 4: MCP 서버를 위한 코드 모드 사용
이것은 테스트에서 가장 큰 단일 최적화입니다. 코드 모드는 완전한 도구 정의 주입을 Python 스텝 생성 방식으로 대체합니다. 모든 도구를 보는 대신, 각 서버의 모든 도구를...
rver, the model sees four meta-tools: listToolFiles , readToolFile , getToolDocs , and executeToolCode . The model loads only the tool definitions it actually needs. Bifrost publishes Code Mode benchmarks on its MCP gateway resource page : MCP tools connected Token reduction Pass rate 96 tools 58% 100% 251 tools 84.5% 100% 508 tools 92.8% 100% At ~500 tools, the per-query payload drops from roughly 1.15M tokens to 83K, a 14x reduction. Tool calls execute inside a sandboxed Starlark interpreter so behaviour is bounded and auditable. The same numbers and detail are in the Bifrost benchmarks resource . Configuring Code Mode for Claude Code's MCP setup: mcp : code_mode : enabled : true sandbox : starlark servers : - name : github-mcp type : stdio command : [ " npx" , " -y" , " @modelcontextprotocol/server-github" ] - name : linear-mcp type : http url : ${LINEAR_MCP_URL} The MCP tool execution docs cover the sandbox model in depth. Step 5: Set Per-Session Budget Caps Long Claude Code sessions can run for hours. Per-virtual-key budget caps stop runaway sessions before they hit your finance team. virtual_keys : - key_name : claude-code-dev key : vk-cc-dev rate_limit : token_limit : 5000000 token_limit_duration : " 1d" budget_limit : 50.00 budget_duration : " 1d" allowed_models : [ " claude-sonnet-4-6" , " claude-opus-4-7" ] Reset durations are calendar-aligned ( 1d , 1w , 1M , 1Y in UTC) so caps line up with billing cycles. The four-tier budget hierarchy (Customer, Team, Virtual Key, Provider Config) is documented on the Bifrost governance resource . Comparison: Optimisation Levers Lever Mechanism Best for Model pinning Default to Sonnet, opt into Opus All Claude Code workloads Semantic caching Vector similarity match Sessions with repeated patterns Code Mode (MCP) Stub generation, demand-loaded tools Large MCP catalogs Per-VK budgets Hard caps with calendar resets Long-running sessions Trade-offs and Limitations Bifrost is self-hosted only with no managed cloud. If you do not have ops capacity to run a gateway, this is real overhead. Code Mode requires the model to call meta-tools to load definitions, which adds a small number of extra round trips compared to the upfront-definition approach. On large catalogs that is a clear net win. On a 5-tool setup it is not. Semantic caching introduces freshness questions for code workflows. If your repo state changed but the cached prompt looks identical, you get a stale response. Tight TTLs and per-key cache scoping reduce the risk. OpenRouter is not compatible because of a tool call streaming issue, so if you currently route Claude Code through OpenRouter you cannot keep that path through Bifrost. Bifrost is newer than LiteLLM , so the community and ecosystem of integrations is still building up. Quick Recap Three cost drivers: model choice, repeat work, and MCP tool definition payload Pin Claude Code to Sonnet by default, opt into Opus only when needed Dual-layer semantic caching captures repeat patterns inside long sessions Code Mode for MCP cuts tool definition tokens by 58% to 92.8% depending on catalog size Per-virtual-key budgets put hard caps on runaway sessions GitHub: https://git.new/bifrost | Docs: https://getmax.im/bifrostdocs | Website: https://getmax.im/bifrost-home