Magpie: Local Gateway Pools AI Subscriptions Across Coding Agents
Magpie is a local gateway that pools AI subscriptions like Claude Pro, ChatGPT Plus, and Copilot across coding agents such as Claude Code and Codex, translating protocols, auto-routing via configurable strategies, masking secrets, and atomically rewriting agent configs to eliminate per-agent API keys and quota silos.
Introduction: The Problem of Fragmented AI Subscriptions
A developer asked how to use Kimi's model in Claude Code while using ChatGPT Plus quota in Codex without constantly editing config files. The answer: install Magpie. This article analyzes why Magpie is gaining adoption by comparing it with CC Switch and detailing its architecture.
CC Switch vs Magpie: Config Rewriting vs Request Routing
CC Switch manages provider configurations by rewriting each agent's config files (JSON/TOML) with the selected API key and endpoint. Agents still connect directly to providers, each using its own key and quota. Resources remain isolated: Claude Code cannot use Codex's subscription and vice versa. CC Switch later added local routing and aggregation modes, but its core remains helping clients find the correct upstream, not pooling upstreams.
Magpie runs a local gateway on 127.0.0.1:3425. All agents connect to this gateway, which forwards requests to the appropriate model or subscription based on user selection. As the article puts it: "CC Switch changes the signpost; Magpie rebuilds the intersection."
Magpie Architecture: Three Core Design Points
Protocol Translation
The gateway speaks four protocols simultaneously — OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, and Google Gemini — and translates between them, including streaming, tool calls, and reasoning content.
Subscription Discovery
Magpie reads login files from each agent (Claude Code config, Codex auth.json) and macOS Keychain to detect active subscriptions. It converts these into Providers (e.g., claude, codex, copilot) and exposes all providers' models in every agent's model selector.
Atomic Config Rewrite
When a user selects a model for an agent via Magpie's menu bar, Magpie atomically rewrites that agent's config file, preserving comments, order, and formatting. The agent believes it is using a normal model; no hidden proxying occurs.
Structural Difference
With CC Switch, each agent connects to its own provider; agents are islands. With Magpie, all agents connect to the single Magpie gateway, which unifies outbound connections. Agents share a common resource pool.
Core Principles
5.1 Subscription → Provider: One Subscription, All Agents
If you have Claude Pro in Claude Code, ChatGPT Plus in Codex, and Copilot in GitHub Copilot, Magpie reads these login states and creates three providers: claude, codex, copilot. Every agent's model selector then shows models from all three providers. Selecting codex/gpt-5.5 in OpenCode routes via Magpie using Codex's login; selecting claude/claude-opus in Claude Code routes via Magpie using Claude's login. No API keys are copied; Magpie reuses each agent's own login flow and token refresh.
5.2 Routing Groups: Quota Exhaustion Without Agent Errors
Models can be grouped (e.g., group/daily-coding with DeepSeek, GLM, Kimi). The gateway selects a member per request based on strategy:
smart : Among subscriptions with quota, use the one that resets soonest to reduce waste
order : Try members sequentially; if first fails, move to next
rotate : Round-robin across members
usage : Use the member with the least usage
pace : Use the member with the most remaining weekly quota
Crucially, when a subscription's quota is exhausted, Magpie automatically switches to the next account or provider. The agent sees no 429 error and experiences no interruption. Multiple accounts for the same provider are also supported for automatic rotation.
5.3 Secret Masking: Keys Never Leave Your Machine
Agents may embed API keys, passwords, or emails from .env, config files, or logs into prompts. Magpie intercepts requests before they leave the machine, replacing sensitive values with placeholders like {{API_KEY_k3v9x2mq}}. The provider never sees real secrets; the agent and local tools still receive real values. This is an extra gateway-layer protection, not automatic with self-hosting.
Hands-On: Install to Production
6.1 Installation
curl -fsSL https://usemagpie.ai/install.sh | shAlso available via platform-specific packages from usemagpie.ai (macOS, Windows, Linux), Docker image, and pure CLI.
6.2 Startup
Magpie runs in the menu bar / system tray. Gateway defaults to 127.0.0.1:3425. The UI auto-discovers installed agents and logged-in subscriptions.
6.3 Model Selection per Agent
In the menu bar panel, click an agent's current model to open a 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 entries point to different models.
6.4 Environment Variable Integration for Unsupported Tools
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 Configuration Switch
Save snapshots of all agents' settings as Profiles (e.g., "Focus Mode" with strong models, "Budget Mode" with cheap models) and switch instantly.
AI-Assisted Routing Log Analysis
Magpie's Routing view shows each request's chosen provider and strategy. Export logs and feed them to an AI to diagnose quota usage patterns.
Example: A routing group group/daily-coding contains DeepSeek, GLM, Kimi. Kimi is rarely used. AI analyzes logs and finds smart strategy always picks DeepSeek because its quota resets sooner. To balance usage, AI suggests switching to rotate or pace , noting that smart optimizes for waste reduction, not equal distribution. The human decides based on quality preferences.
Pros and Cons
Pros
Subscription pooling maximizes resource utilization — 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, formatting; MCP, plugins, hooks remain intact.
Routing groups prevent interruption on quota exhaustion — Multi-account, multi-provider auto-failover; agent-side transparent.
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
Requires a local gateway process — Persistent menu-bar app; additional component to manage (though low resource usage).
Subscription discovery reads login files — Accesses agent configs and Keychain; privacy-sensitive users must disable or use API-key-only mode.
Ecosystem still maturing — Open-sourced September 2026 (v0.1.3353); docs and community growing.
Not zero-config — Concepts like Provider, Routing Group, Profile must be understood; higher learning curve than CC Switch's button-click simplicity.
Applicability Matrix
Multiple agents, want shared subscriptions — ✅✅✅ Strongly recommended. Reason: Subscription pooling: one sub, all agents.
Quota-sensitive, task-based model allocation — ✅✅✅ Strongly recommended. Reason: Routing groups with strategies.
Avoid repeated config rewrites — ✅✅✅ Strongly recommended. Reason: Atomic rewrite preserves format.
Need multi-account auto-rotation — ✅✅✅ Strongly recommended. Reason: Quota exhaustion auto-switch.
Single agent, single provider — ⚠️ Evaluate. Reason: Magpie's value shines in "multi" scenarios.
Extreme privacy sensitivity — ⚠️ Evaluate. Reason: Disable subscription discovery or use API-key mode.
Conclusion
When you only use Claude Code, you don't need Magpie. When you simultaneously run Claude Code, Codex, OpenCode and hold three or four subscriptions, "each agent using its own" becomes the biggest waste. Magpie's local gateway abstracts agents from providers, enabling unified scheduling, routing, and rotation. This is the leap from "configuration tool" to "infrastructure."
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.
