Magpie: Local Gateway Pools AI Subscriptions Across Coding Agents
This article analyzes Magpie, a local gateway that pools AI model subscriptions across coding agents like Claude Code and Codex, detailing its architecture, protocol translation, routing strategies, secret masking, and how it differs from configuration tools like CC Switch.
Introduction: The Problem
A developer asked how to use Kimi's model in Claude Code and ChatGPT subscription in Codex without constantly editing config files. The suggestion: try Magpie. The key distinction: CC Switch rewrites configuration files; Magpie runs a local gateway that routes requests.
CC Switch: Configuration Manager
CC Switch is a desktop tool that manages API provider configs for Claude Code, Codex, etc. It rewrites each agent's config file (JSON/TOML) with the selected provider's key and endpoint. Convenient for single-agent, single-provider switching. However, each agent still connects directly to its provider — resources remain isolated. Claude Code cannot use Codex's subscription. CC Switch later added local routing and aggregation, but its core remains helping clients find upstreams, not pooling them.
Magpie: Local Gateway + Menu Bar App
Magpie reads each agent's existing login sessions (Claude Code config, Codex auth.json, macOS Keychain), turns them into Providers (claude, codex, copilot), exposes a local gateway at 127.0.0.1:3425, and rewrites each agent's config to point to this gateway. One click in the menu bar swaps models across agents. Core capabilities:
Protocol translation : Gateway speaks OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, Google Gemini, translating between them including streaming, tool calls, reasoning.
Subscription discovery : Reads agent login files and Keychain, converts logged-in subscriptions into Providers available to all agents.
Atomic config rewrite : When you select a model for an agent, Magpie atomically rewrites that agent's config file, preserving comments, order, and format. The agent believes it's using a normal model.
Architecture Comparison
CC Switch : Each agent connects to its own provider; CC Switch edits config files. Agents are islands.
Magpie : All agents connect to the same Magpie gateway; Magpie manages upstream providers. Agents share a unified resource pool.
Core Mechanisms
5.1 Subscription → Provider: One Subscription, All Agents
You log into Claude Pro in Claude Code, ChatGPT Plus in Codex, Copilot in GitHub Copilot. Magpie reads these sessions, creates three Providers: claude, codex, copilot. Every agent's model selector now shows all three Providers' models. Select claude/claude-opus in OpenCode → OpenCode calls Magpie → Magpie uses your Claude Code login to call Claude. Select codex/gpt-5.5 in Claude Code → Claude Code calls Magpie → Magpie uses your Codex login to call GPT. No keys copied; Magpie reuses each agent's login flow and token refresh.
5.2 Routing Groups: Quota Exhaustion Without Agent Errors
Group models (e.g., group/daily-coding with DeepSeek, GLM, Kimi). Gateway picks a member per strategy:
smart : Among subscriptions with quota, pick the one resetting soonest to reduce waste.
order : Sequential fallback.
rotate : Round-robin.
usage : Least-used member.
pace : Most remaining weekly quota.
Critical: When a subscription's quota exhausts, Magpie automatically switches to the next account or provider. Agent sees no 429, no interruption. Multiple accounts per provider supported.
5.3 Secret Masking: Keys Never Leave Your Machine
Default off. Before requests leave your machine, Magpie replaces API keys, passwords, emails in prompts with placeholders like {{API_KEY_k3v9x2mq}}. Provider never sees real secrets. Response placeholders are restored. This gateway-layer handling is not automatic with self-hosting.
Hands-On: Install to Production
6.1 Install
curl -fsSL https://usemagpie.ai/install.sh | shOr download from usemagpie.ai (macOS, Windows, Linux, Docker, CLI).
6.2 Launch
Runs in menu bar/tray. Gateway default: 127.0.0.1:3425. Auto-discovers installed agents and logged-in subscriptions.
6.3 Assign Models to Agents
Menu bar panel shows each agent's current model. Click → searchable list of all Providers' models. Example: assign codex/gpt-5.5 to Claude Code → Magpie rewrites Claude Code's config so its opus, sonnet, haiku point to different models.
6.4 Environment Variable Integration
For unsupported tools with custom base URL:
export OPENAI_BASE_URL=http://127.0.0.1:3425/v1
export OPENAI_API_KEY=magpie
export ANTHROPIC_BASE_URL=http://127.0.0.1:3425
export ANTHROPIC_API_KEY=magpie
export GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:3425
export GEMINI_API_KEY=magpie6.5 Profiles: One-Click Full Config Switch
Save snapshots of all agents' settings (e.g., "focus mode" = strong models, "budget mode" = cheap models) and switch instantly.
AI-Assisted Routing Log Analysis
Magpie's Routing view shows each request's provider and strategy. Feed logs to AI to analyze quota usage. Example: smart strategy always picks DeepSeek because its reset is soonest; Kimi never used. AI suggests rotate or pace for even usage, and notes smart optimizes for waste reduction, not balance. AI explains strategy behavior; you decide trade-offs.
Pros & Cons
Pros
Subscription pooling : One Claude Pro serves all agents; one ChatGPT Plus shared across Codex and others. No duplicate API purchases.
Non-destructive config edits : Atomic rewrites preserve comments, order, format. MCP, plugins, hooks untouched.
Routing groups with auto-failover : Multi-account, multi-provider automatic switching; agent unaware.
Cross-protocol sharing : OpenAI, Anthropic, Gemini protocols interoperate; agents using different protocols share models.
On-device secret masking : Keys masked before leaving machine; provider never sees real values.
Cons
Local gateway process required : Persistent menu-bar app; extra component to manage (though low resource use).
Subscription discovery reads login files : Reads agent configs and Keychain by default; privacy-sensitive users must disable or use API-key mode.
Early ecosystem : Open-sourced Sept 2026 (v0.1.3353); docs and community still growing.
Not zero-config : Must understand Providers, routing groups, Profiles. Higher learning curve than CC Switch's button-click.
Applicability Matrix
Multiple agents, share subscriptions — ✅✅✅ Strong — Subscription pooling
Quota-sensitive, task-based model allocation — ✅✅✅ Strong — Routing groups with strategies
Avoid repeated config rewrites — ✅✅✅ Strong — Atomic edits preserve format
Need multi-account auto-rotation — ✅✅✅ Strong — Quota exhaustion auto-switch
Single agent, single provider — ⚠️ Evaluate — Value in "multi" scenarios
Extreme privacy sensitivity — ⚠️ Evaluate — Disable discovery or use API-key mode
Conclusion
When you only had Claude Code, Magpie was unnecessary. Now with Claude Code, Codex, OpenCode, and three-four subscriptions, "each agent uses its own" is the waste. Magpie's local gateway decouples agents from providers: agents no longer care who's behind; Magpie handles unified scheduling, routing, rotation. This is the leap from "configuration tool" to "infrastructure."
References:
GitHub: https://github.com/yetone/magpie
Official download: https://usemagpie.ai
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
