跪拜 Guibai
← All articles
AI Programming · AIGC

Magpie: A Local Gateway That Lets Claude Code Run Kimi and Codex Run DeepSeek

By Yue的AI工坊 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Multi-agent setups are now common enough that managing per-tool config files, separate keys, and subscription lock-in is a real cost. Magpie centralizes model choice, enables failover across accounts without losing prompt cache, and keeps secrets on the machine, which changes how developers run and fund their AI toolchains.

Summary

Magpie runs a local gateway on 127.0.0.1:3425 that speaks OpenAI, Anthropic, and Gemini protocols and converts between them, so an agent locked to one protocol can use a model from any vendor. It also edits each agent's configuration file directly, preserving comments and formatting, so switching Claude Code to DeepSeek or Codex to Kimi is a four-command operation with no environment variable juggling.

Beyond basic model swapping, Magpie adds profiles for one-command switching between full setups, routing groups that combine multiple accounts and providers into a single logical model with automatic failover, and intent routing that uses a tiny classifier model to send cheap questions to cheap models and test-writing to stronger ones. A built-in redaction layer replaces keys and personal data with stable placeholder hashes before requests leave the machine, and usage tracking shows where money goes per agent and model.

The project hit 29,000 GitHub stars in roughly six weeks after its repo was created, a sign that multi-agent model management has become a genuine pain point. The tutorial walks through installation, pitfalls like claude.ai logout, and three ready-to-copy configurations for saving money, pooling subscriptions, or auto-routing by task.

Takeaways
— Magpie is an open-source local gateway that speaks OpenAI, Anthropic, and Gemini protocols and converts between them, running on 127.0.0.1:3425.
— It edits agent configuration files atomically, preserving comments and ordering, for Claude Code, Codex, Gemini CLI, OpenCode, Pi, and Crush.
— Providers can be vendor presets (just a key), logged-in subscriptions (Claude, ChatGPT, Copilot, Gemini, Antigravity), local models (Ollama, LM Studio), or custom OpenAI/Anthropic-compatible endpoints.
— Profiles save all agents' current settings under a name and switch back with one command, e.g. magpie save cheap && magpie use cheap.
— Routing groups combine multiple models or accounts into one logical model; auto/ groups are created automatically when two providers offer the same model.
— Routing modes include smart, order, rotate, usage, pace, weight, fast, cheap, and drain, with cheap considering time-of-day pricing.
— Session stickiness defaults to stays=auto to preserve prompt cache across accounts; strict mode never switches and hands errors to the agent.
— Rules can match on token count, images, reasoning, agent, intent, compaction, time slots, and project folders, and compact summaries can be sent to a cheap model.
— Intent routing uses a small classifier model that only sees the latest message and returns a number to pick a rule; it costs nothing when a non-intent rule matches first and times out at 8 seconds by default.
— Privacy redaction replaces secrets and personal info with stable placeholder hashes before requests leave the machine, restores them in responses, and fails closed with a 503 rather than sending plaintext.
— Remote magpie lets one machine share models to other machines via gateway keys with per-key quotas and model restrictions; short-lived keys can be issued for sandboxes and CI.
— Gateway middleware can rewrite every request with a few lines of JavaScript, and community plugins cover model mapping, system prompts, and think-tag processing.
— GitHub Actions can exchange OIDC tokens for short-lived gateway keys, avoiding gateway keys in repo secrets.
— The tutorial warns that running Claude Code through magpie with a key logs you out of claude.ai unless you set the login method to claude.ai login; Remote Control and ultrareview remain unavailable.
Conclusions

Magpie's 29,000 stars in about six weeks shows that the pain of managing multiple agents and providers is no longer niche; tooling that treats models as interchangeable commodities has clear demand.

Intent routing is deliberately simple: a tiny classifier that returns one number, with no embeddings or training, keeps the feature cheap and predictable, and a timeout or error falls back to normal routing instead of blocking.

The redaction design makes a strong privacy claim: placeholders are stable hashes so caches and thinking signatures survive, and the system fails closed rather than risking a plaintext leak.

Cheap routing that accounts for time-of-day pricing, like DeepSeek doubling during peak hours, signals that cost optimization in AI tooling is moving from static choices to real-time arbitrage.

The official warning about Antigravity account bans is a reminder that using subscriptions across agents often sits in a gray zone of vendor terms; the tool being open source doesn't change that risk.

Concepts & terms
Routing group
A Magpie abstraction that combines multiple models or provider accounts into a single logical model, with configurable routing modes (smart, order, rotate, etc.) and automatic failover when one account runs out of quota.
Intent routing
A Magpie feature where each turn sends your latest message and a numbered list of intents to a small classifier model, which returns a number that selects the first matching rule for that turn.
Profile (方案)
A snapshot of all agents' current settings stored under a name, allowing one-command switching between complete configurations, e.g. a cost-saving setup and a main setup.
Privacy redaction
A Magpie security feature that replaces secrets and personal information with stable placeholder hashes before a request leaves the machine, and restores the original values in responses, so agents still see real keys.
Stable placeholder
A redaction token like {{API_KEY_srhjgvja}} generated from a type plus an 8-character keyed hash, so the same value always maps to the same placeholder, preserving prompt cache and conversation context.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗