1. The Seven-Day Migration Thought Experiment
Every few months, a scenario makes the rounds among engineering teams: imagine waking up to an email saying your primary AI coding supplier just raised prices 10x, and you have one week to switch. Whether that exact shock hits tomorrow or simply arrives slowly through rate limits, deprecations, or policy shifts, any serious engineering team should treat model vendors the same way it treats cloud regions, payment gateways, or database hosts.
The standard advice circulating right now is solid as a baseline. Put a router in front of your inference calls, use coding clients that support multiple backends, and store repository instructions in agent-neutral conventions like AGENTS.md and shared skills directories instead of locking your workflow into vendor-specific files like CLAUDE.md or .claude.
That advice gets you roughly thirty percent of the way to portability. The other seventy percent is where teams actually stall out when a switch becomes real, because the nastiest lock-in rarely lives in the API client or the markdown filename. It hides in state, side-effect control, and model scaffolding.
Figure 1: Separating repository rules, external MCP memory, tier-aware model routing, and offline transactional diff verification keeps every coding guarantee intact when swapping cloud or local backends.
2. Layer One: State and Memory Lock-In
Most setups claim to be model agnostic because flipping an environment variable or OpenRouter slug routes requests to a new model. The moment that switch happens, though, everything built up inside the old coding tool's private session history, custom hooks, and local scratchpads disappears.
The replacement model arrives with total amnesia. It forgets architectural decisions made two weeks ago, breaks subtle invariants that the team already learned the hard way, and proposes edits without tracing which callers depend on a function signature. A router forwards prompts cleanly, yet it cannot carry institutional memory across agents if that memory only existed inside one vendor's runtime.
What finally broke that lock-in in my own lab was treating language models as stateless compute and moving persistent state completely outside the coding agent. Working memory, architectural invariants, and code-graph lookups sit behind standard Model Context Protocol (MCP) servers backed by local SQLite or PostgreSQL. In krusch-context-mcp (v2.0.3, 155/155 automated tests), every saved project rule anchors to exact source line spans with SHA-256 hashes, so when the underlying file changes, the memory flags itself as STALE_DRIFT instead of steering the next model with outdated advice. Bundling memory, AST symbol graphs, and execution checks into a single neutral entry point like krusch-stack (v1.3.1, 91/91 tests) means switching from one coding IDE or CLI to another does not reset what the agent knows about the codebase.
3. Layer Two: Side-Effect Control When a New Model Misbehaves
Even when memory transfers cleanly, swapping models under deadline pressure introduces a quieter danger: different model families have very different tool-calling habits. One model respects careful incremental edits, while another rewrites entire files aggressively, leaves half-finished patches on a timeout, or oscillates in a broken edit-test loop when a stack trace gets messy.
If your safety model consists of polite instructions inside AGENTS.md telling the agent to "be careful and run tests," switching models changes your blast radius overnight. Prompts are suggestions, not execution invariants.
To keep repository safety independent of whichever model happens to be behind the router, I built krusch-coding-harness (118/118 tests) as a database-backed transaction manager. Candidate models never write straight to the live checkout. Instead, proposed edits stage as unified diffs in PostgreSQL (or embedded PGlite for single-machine runs), run inside an offline Linux Bubblewrap (bwrap --unshare-net) sandbox with network access disabled, and swap onto disk through hardware fsyncSync and atomic renameSync only after tests pass and SHA-256 file-drift checks confirm nothing in the working tree changed underneath. A built-in cost-killswitch.js guard caps runaway loops at $0.50 and fails over automatically, while the verify-models command verifies prompt-prefix parity across Claude, Gemini, and local Ollama backends. Whether a frontier cloud API or a local open-weights model generated the patch, the verification boundary never weakens.
4. Layer Three: Scaffolding Portability and the Down-Tier Trap
There is one more gap that almost every router-only plan overlooks. When a provider raises prices 10x, most teams do not simply swap one expensive flagship API for another flagship API at the same burn rate. The real economic response is pushing routine operational turns (syntax fixes, schema lookups, log triage, boilerplate tests) down to cheaper cloud tiers or local GPUs, while reserving flagship reasoning calls for hard design and root-cause problems.
A dumb proxy struggles badly with down-tiering because model classes do not share the same prompt ergonomics. Smaller local models need tight upfront structure, grounded schemas, and guardrails against spin loops, whereas heavy outer checklists actively slow down and confuse frontier reasoning models. Sending the exact same prompt template to every tier makes smaller models look unusable and wastes tokens on larger ones.
| Portability Layer | Router + AGENTS.md Only | 4-Layer Decoupled Harness | Failure Mode Prevented |
|---|---|---|---|
| Repo Instructions | AGENTS.md + neutral skills |
AGENTS.md + shared skills + MCP retrieval |
Vendor-locked CLAUDE.md / IDE rules |
| Working Memory & AST | Lost inside previous agent's session history | External SQLite / PG via krusch-context-mcp + AST graph |
Day-1 model amnesia & drifted rule enforcement |
| Routing & Cost Floor | Cloud-to-cloud API proxy | <15µs Stage-0 cascade + $0.50 kill-switch + local GPUs |
Correlated cloud price hikes & routing-tax latency |
| Prompt Scaffolding | Single static prompt across all models | SMALL_MODEL / MID_MODEL / FRONTIER_REASONING tiers |
Over-scaffolding reasoners or under-guiding small models |
| Write & Test Safety | Direct checkout writes gated by prompt advice | PG staged diffs + bwrap --unshare-net + atomic renameSync |
Half-edited trees & unverified tool-calling regressions |
// Portability separates four concerns that most setups fuse together:
// 1. Neutral repo docs (AGENTS.md + shared skills)
// 2. External MCP memory & AST lookups (SQLite / PostgreSQL)
// 3. Microsecond tier routing + local GPU fallback floor
// 4. Transactional diff staging + scale-aware verification gate
const mcpContext = await retrieveMcpContext({ verifySpanHashes: true });
const route = selectCascadeTier({ prompt, breaker, allowLocalFloor: true });
const policy = resolveScaleProfile({ model: route.model, thinking: route.thinking });
const stagedDiff = await generateCandidatePatch({ route, policy, mcpContext });
await verifyInOfflineSandboxAndApplyAtomically(stagedDiff);
That realization pushed me to build scale-aware policies into grounded-harness (v0.2.2, 15/15 tests) alongside a microsecond local dispatcher in krusch-cascade-router (v1.1.0) and the unified multi-provider client in @krusch/toolkit (v1.8.1, 191/191 Node and 201/201 pytest tests). Turn-0 grounding hands the model deterministic workspace schemas before its first tool call, the scale policy adjusts scaffolding based on whether the backend is a small local model, a mid-size coder, or a frontier reasoner, and the stop gate stays silent on clean runs while catching concrete defects before completion. Keeping local open-weights inference at the bottom of the cascade also protects against correlated cloud price hikes or outages, since routine coding work never stalls completely even if every external API goes dark.
5. Running a Real Portability Fire Drill (and Honest Trade-Offs)
Running that drill in my own workspace caught subtle habits I had not noticed. Even with dozens of AGENTS.md files and a multi-provider adapter already in place, I still spotted minor naming drift like provider-named handoff notes and singular .agent/ directories sitting beside the emerging .agents/ cross-tool layout. None of those stop a migration on their own, yet finding them on a quiet Tuesday beats untangling them during a seven-day billing panic.
Honest engineering also requires naming the trade-offs and scope boundaries of this architecture:
- Operational Footprint vs. Single-CLI Speed: Maintaining external MCP memory stores, PostgreSQL diff staging, and tier-aware cascade routing adds real infrastructure compared to installing a single proprietary coding CLI and letting it edit files directly. When I am making a quick five-minute tweak in a throwaway prototype, a lightweight single-vendor tool is faster to pick up.
- Linux Namespace Isolation vs. Cross-Platform Hosts: Native offline Bubblewrap (
bwrap --unshare-net) sandboxes rely on Linux user namespaces. On macOS or Windows workstations, reaching the same kernel-level filesystem and network isolation requires running the verification jail inside Docker or a Linux VM. - Deterministic Gates vs. Semantic Product Judgment: Static AST checks, SHA-256 drift guards, and offline test suites guarantee that a swapped model will not corrupt your working tree or break existing assertions, yet they cannot prove that a generated design matches unstated product intent. Code review and integration tests still matter after any provider cutover.
- Capability Floor on Frontier Reasoning: Down-tiering routine work to smaller or local models protects budget and uptime, yet genuinely hard multi-file debugging or ambiguous architecture work still benefits from frontier reasoning tiers. The goal of a portable harness is keeping that escalation optional and reversible rather than mandatory on every turn.
6. Inspect and Verify the Open-Source Stack Locally
Every layer referenced in this architecture ships under the MIT License and can be inspected or tested locally without cloud credentials:
# 1. Initialize the neutral 3-tier MCP stack & run the local walkthrough
npx krusch-stack demo && npx krusch-stack init --ide all --defer-tools && npx krusch-stack doctor
# 2. Verify transactional staging, drift refusal & cross-provider prefix parity
git clone https://github.com/kruschdev/krusch-coding-harness.git && cd krusch-coding-harness
npm install && npm run test:unit
./bin/krusch-coding-harness.js demo-invariant
./bin/krusch-coding-harness.js verify-models
# 3. Verify scale-aware Turn-0 grounding & defect-only stop gates
git clone https://github.com/kruschdev/grounded-harness.git && cd grounded-harness
npm install && npm test