Skip to navigation

Claude Code Migration: How to Leave Without Losing Your Context

In short: A Claude Code migration should preserve prompts, hooks, context files and test workflows before changing the model or agent.

Published 18 min read
On this page

Direct answer

A Claude Code migration should preserve the project’s knowledge before it changes the model or agent. Move prompts, hooks, context files, permissions and test workflows first. Then run a bounded parallel test, compare accepted output and switch only when the new path meets the same standard.

A base URL change is not a migration. It can leave the project rules in an unread file, replace a hook with a manual step or move a task onto a model that handles the tool loop differently. Those gaps do not always appear in a demo. They appear on the first real bug, migration or production change.

Route status matters for the destination. The documented Claude Code route through the gateway is unavailable: all four Claude IDs were marked unavailable on 2026-11-27. The active route is an OpenAI-format agent using one key and 46 live free model IDs. Free IDs do not work inside Claude Code’s Anthropic-format route.

Migration inventory: name what must survive

Start with an inventory, not a new client. The goal is to separate portable knowledge from client-specific behavior. Portable knowledge can move as documents, scripts and tests. Client-specific behavior needs a replacement or an explicit acceptance of loss.

Category Examples Portable form Parity check
Project rules Architecture, conventions, forbidden paths Plain Markdown or structured docs New agent follows the same constraints
Task prompts Bug fix, feature, migration templates Versioned task files Same acceptance criteria produced
Context Decisions, constraints, known failures Project memory file and tickets Critical facts survive a fresh session
Hooks Formatting, checks, lifecycle commands Repository scripts Same event produces the same check
Tools File access, test runner, API client Explicit commands and permissions Tool succeeds and fails correctly
Tests Unit, integration and acceptance suite CI and local scripts Clean checkout passes
Credentials Keys, login route, billing owner Secret manager and redacted inventory Correct route works with least privilege
Operations Alerts, limits, rollback steps Runbook and key controls Cap and rollback behave as expected
Migration inventory covering prompts, hooks, context files and tests before changing agents.
Explanatory inventory diagram for this article. It is not a completed customer assessment. The caveat is that every item needs an owner and a parity test in the destination workflow.

The Claude Code lock-in and exit-cost analysis explains why the inventory matters. The exit cost is spread across configuration, habits and quota. A migration that preserves only the model endpoint leaves most of that cost unresolved.

Give each inventory item an owner. The person who understands the hook should write its replacement. The reviewer who knows the acceptance criteria should confirm the test parity. A migration owned by nobody becomes a list of good intentions.

Context files: move decisions, not just instructions

A context file should explain how to work in the repository. It should name the architecture, test command, deployment boundary, naming conventions and known failure modes. It should also say which decisions are settled and which still need investigation.

The Claude Code context versus memory guide distinguishes capacity, retained reasoning and task state. A new client may have plenty of context space and still fail to recover a decision that lived only in an old session. Write the decision down.

A useful context file has four parts:

  • Project map: where the main modules live and how they interact.
  • Rules: constraints that must not be violated.
  • Commands: the exact test, lint and build commands.
  • Known failures: bugs, flaky tests and environmental quirks with links to evidence.

Keep the file concise enough to read. A long document that repeats the entire repository is not a memory system. Link to the source of truth and update it when the architecture changes.

Context portability showing project rules, decisions and known failures moving into the new workflow.
Explanatory diagram based on the article’s context-portability model. It does not claim that every client reads the same file format. The caveat is that the destination loader and instruction precedence must be tested.

The Claude Code compaction retention test is relevant when a long session is summarized. Critical constraints should live outside the session so compaction cannot silently drop them. Use the same principle during migration: the repository, not the chat, owns the durable knowledge.

Preserve decision rationale

A rule without its rationale is easy to remove during a refactor. Note why the constraint exists. “Do not add a new queue here because the current worker assumes ordered delivery” is more useful than “avoid queues.”

The rationale also helps the destination model handle a novel case. It can reason from the constraint instead of pattern-matching a forbidden keyword.

Do not include secrets in the context file. The Claude Code settings-file secret exposure research shows how saved settings can contain literal commands and credentials. Secondary research: two summaries report 1,379 distinct secrets in public Claude Code settings files. A broader related sample contained 2,539 credentials across 1,994 repositories. The populations are different, and the primary page was unavailable in the research pass.

Hooks and tools: make behavior explicit

A hook is a client-triggered action. It might format files, run a check, block a command or prepare context. The underlying behavior is often portable even when the trigger is not.

Move the behavior into a repository script with a clear name. Document when it should run. Then decide how the destination client invokes it: automatically through a supported hook, through a task template or as a manual step in CI.

The Claude Code harness security boundary explains why tool authority belongs in the inventory. A migration should preserve least privilege. If the old client could read source files but not deployment secrets, the new client should not gain that access merely because its permission screen looks different.

Tool behavior Portable replacement Test
Format before commit Repository format script Script changes the intended files only
Block writes to a protected path Explicit guard script with nonzero exit Guard rejects the protected path
Run tests after edits Documented test command in task template Command fails when a test fails
Load project context Plain context file plus loader instructions Fresh session can repeat a critical rule
Call an external API Narrow client script with scoped credential Sandbox success and failure paths work
Produce a summary Structured report file Report contains required fields without secrets

The Claude Code custom API base URL guide is useful when the tool calls an API. Record the effective endpoint, format and credential type. A client can appear to work while using a saved login instead of the intended key.

The OpenAI versus Anthropic API format guide explains the format boundary. Claude Code uses the Anthropic Messages route. An OpenAI-format agent uses a different request shape. Do not copy an endpoint without checking the client’s format.

Prompt portability: keep the contract, rewrite the wrapper

A prompt is portable when it expresses the task and acceptance criteria without depending on a client-specific command. The wrapper may need to change. The contract should not.

For example, a Claude Code slash command might include a client-specific instruction to enter plan mode. The portable version should say: “Investigate first. Do not edit files. Return the relevant paths, proposed approach and open questions.” The destination client can then follow the intent through its own mechanism.

The Claude Code proof-of-work packet is a good acceptance wrapper. Ask for changed files, commands, results and external-state evidence. That structure survives a client change because it describes the work, not the interface.

The Claude Code false-success analysis explains why the wrapper should include a hidden acceptance check. A new model can produce a convincing summary while missing the real dependency. Keep the test constant across the old and new paths.

Version the prompts

Store task templates in the repository. Give each template a clear purpose and a short change history. When a prompt changes, record why. Otherwise the team cannot tell whether a quality difference came from the model, the client or the prompt.

The model selection guide for coding agents recommends evaluating on real tasks rather than trusting a leaderboard. The same applies to prompts. Run a small task set through each destination and compare accepted results.

A prompt that works only with one model may still be useful, but it should be labeled as such. Do not present it as portable project knowledge.

Cutover plan: parallel first, switch second

A cutover should be boring. The team should know what is moving, what is staying, how success is measured and how to go back. The Claude Code exit-plan checklist is the preparedness version of this process; the cutover plan is the execution version.

Phase Action Exit condition
Inventory List context, prompts, hooks, tools and credentials Every item has an owner
Prepare Create portable files and scripts Clean checkout can run them
Sandbox Run representative tasks in the destination Acceptance suite passes
Parallel Route a limited workload through both paths Results meet the same standard
Decide Compare quality, review time, cost and gaps Team records a decision
Cut over Move the agreed workload Monitoring shows stable operation
Observe Review failures and usage No unresolved critical regression
Cutover plan showing parallel run, output comparison and deliberate traffic switch.
Explanatory cutover diagram, not a promised timeline. It does not claim zero downtime or zero friction. The caveat is that the old path must remain usable until the new path has passed real work.

Keep the parallel period bounded. One representative task set is enough to start: a bug fix, a feature, a refactor and an integration check. Use the same starting commit and acceptance criteria for both paths.

Record the effective model, client version, endpoint and configuration for each run. The Claude Code April 2026 postmortem shows why dated baselines matter. Official: Anthropic describes three changes, says the fixes landed in v2.1.116 and says usage limits were reset on 2026-04-23. A comparison without version and configuration can confuse a code change with an environment change.

Compare accepted work, not chat style

A destination can sound better and still produce more rework. Compare changed files, test results, external-state evidence and reviewer time. The Claude Code cost per verified change provides the right denominator.

The monthly LLM API cost worksheet helps separate token spend from human review. A route with higher token cost can still win if it reduces rework. A cheaper route can lose if it needs more supervision.

Do not hide skipped checks. If the destination cannot run a hook or cannot reproduce a permission boundary, record the gap and its risk. A migration decision with a known gap is stronger than a demo that pretends the gap does not exist.

Rollback: define the triggers before cutover

Rollback is not a failure of planning. It is the control that makes a cutover reversible. Define the triggers before the switch, and test the rollback path while both routes are still available.

Trigger Signal Response
Quality drop Acceptance suite fails or review rework rises Pause new work on the destination
Tool failure A required hook or command cannot run Restore the previous task path
Cost spike Usage exceeds the agreed budget Stop the run and inspect the route
Permission gap Required action is blocked or access is too broad Revert to the reviewed configuration
Context loss Critical rules disappear after a fresh session Repair the context loader before continuing
External-state mismatch Durable result differs from the old path Halt cutover and investigate
Rollback triggers including quality drop, tool failure and cost spike during a Claude Code migration.
Explanatory rollback diagram for migration planning. It does not promise that every change can be reversed. The caveat is that data migrations and external side effects may need a separate recovery plan.

A rollback trigger needs an owner. The on-call developer should know who can pause traffic, who can restore the old configuration and where the decision is recorded. The Claude Code verification packet can carry that record.

Keep credentials separate. Create destination credentials through the normal secret process, scope them narrowly and revoke them when the experiment ends. The per-project API key and spend-limit guide describes a useful pattern. The coding-agent API key compatibility guide helps verify the client and route.

The Claude Code third-party harness rules matter during cutover. Official: the login guidance prohibits tools that misrepresent identity or route traffic against subscription limits. Do not make rollback depend on a route that conflicts with the documented rules.

Data handling is part of context portability

A migration changes where prompts, files and tool results travel. The team should compare retention, training and subprocessor terms before moving sensitive work.

Official: consumer users can allow data to be used for training. Non-opted-in consumer data has 30-day retention, and data retained after a training opt-in may be kept de-identified for up to five years. Commercial API, Team, Enterprise and Government data are not used for training by default. Standard commercial retention is 30 days. Zero data retention exists for qualified Enterprise accounts and eligible products, with exceptions.

The Claude Code privacy and retention rules and the zero-data-retention limits provide the detailed comparison. Do not describe standard retention as zero, and do not deny that qualified Enterprise ZDR exists.

A gateway can add another provider relationship. First-party policy claim: the gateway privacy policy says it does not train on prompts, files or outputs and does not sell them. Prompt and response bodies are not written to usage logs by default. Troubleshooting captures can last up to 30 days, opt-in prompt logs seven days, usage metadata up to 12 months and security logs up to 90 days. Account data is deleted or anonymised within 30 days after a deletion request, and upstream providers receive requests under their own terms.

Those are first-party policy statements, not an independent audit. Record the policy version and review date with the migration decision.

Routing uncertainty belongs in the plan

The gateway documentation contains a visible contradiction. The routing guide documents same-model retries and configurable fallback headers, while the gateway overview says the service does not answer with a different model. Do not promise guaranteed automatic fallback until that contradiction is resolved.

This matters during cutover because a fallback can hide a failed primary route. If the client receives a different model’s output, the acceptance test and cost record must reflect what actually happened. Until the behavior is clear, test the primary route explicitly and keep rollback available.

The Claude Code single points of failure analysis provides the broader resilience context. A migration can reduce concentration risk without removing every provider risk. The live status page can provide incident context, but it does not replace an acceptance test. The gateway popularity rankings are not a reliability guarantee.

A fresh-session parity drill

The most useful migration test is often the least glamorous: start a fresh session in the destination and ask it to recover the project’s critical knowledge without help from the old conversation. This tests the context files, instruction loader and task state together.

Choose five facts that matter: one architectural constraint, one test command, one known failure, one security boundary and one deployment rule. Write each fact in the source document. Then start a clean session and ask the destination agent to explain how it would handle a task that depends on all five.

Score the answer against the source document. Did it preserve the constraint, or did it repeat a keyword while losing the reason? Did it name the correct command? Did it respect the security boundary without being prompted? The Claude Code context versus memory guide explains why this is a separate skill from reading files.

A failed drill does not automatically mean the destination is unusable. It may mean the context file is too long, the loader does not read the right path or the instruction precedence is wrong. Repair the mechanism and rerun the drill. Do not solve a context-loading problem by pasting the entire project history into every prompt.

Test the hooks from a clean checkout

Clone the repository into a clean directory and run the migrated hooks or scripts. A developer machine can hide missing dependencies, stale generated files and local environment variables. The clean checkout exposes those gaps.

Run the success path first. Then run the failure path: a protected path, an invalid configuration or a missing credential. The script should fail with a useful message and a nonzero exit code. The Claude Code false-success analysis explains why a command that prints an error but exits successfully can create a false pass.

The Claude Code harness security boundary is the reference for the permission portion of the drill. Confirm that the destination can perform the intended action and is blocked from the forbidden one. A migration that broadens access to make a hook work has traded one problem for another.

Repeat one real task end to end

Pick a task that resembles ordinary work, not a showcase. A good candidate has a clear requirement, a real dependency and a verifiable side effect. Run it through the destination using the migrated context and hooks. Save the proof packet.

The packet should contain the changed files, exact commands, relevant output and the external-state check. The Claude Code proof-of-work packet provides the format. Compare it with a run through the old workflow on the same starting commit.

Differences are not automatically defects. The destination may choose a different implementation. The acceptance question is whether it meets the requirement with acceptable review effort. The Claude Code cost per verified change keeps that comparison focused on accepted work.

Test a resumed task

Start a task, stop it, then resume in a fresh session. The destination should recover the goal, the constraints, the completed work and the next action from the persisted files. This tests whether the migration preserved task state or only project documentation.

The Claude Code compaction retention test provides a useful scorecard: facts, decisions and constraints. Use the same categories for the migration drill. If a critical item disappears, store it in a more durable place and change the resume procedure.

A resumed task should also preserve the verification standard. Do not let a fresh session treat an earlier unverified summary as proof. Require it to rerun the decisive check or inspect the saved artifact.

Record the gaps before the decision

The drill will produce gaps. Write them down with an owner and a proposed fix. Some gaps block cutover, such as a missing security boundary. Others can be accepted temporarily, such as a convenience hook that still has a manual replacement.

The Claude Code third-party harness rules are part of the decision when the destination changes the client or credential route. Official: the guidance prohibits tools that misrepresent identity or route traffic against subscription limits. A technically successful drill does not override that boundary.

The final parity record should be short: task set, client and model versions, context files used, hooks run, acceptance results, review time, cost and open gaps. That record turns the migration from a one-time event into a repeatable engineering change.

Migration verdict requiring preserved context, tested parity and a deliberate switch.
Explanatory verdict diagram for the migration method in this article. It does not promise a frictionless move. The caveat is that parity is established on the tested task set, not for every possible workflow.

Honest losses and evidence gaps

Migration has a real cost. The old client may handle a lifecycle event, permission prompt or context convention better than the destination. A portable setup can be more explicit and less convenient. The team may need to maintain two workflows during the parallel period.

The evidence also cannot promise a painless move. Unknown: the fact pack contains no measured migration failure rate, no universal hook-portability matrix and no controlled comparison of context retention across clients. The inventory and cutover plan are engineering controls, not guarantees.

A future update should include a completed before-and-after migration with parity tests, review time and unresolved gaps. Until then, the honest position is that context portability reduces loss but does not eliminate it.

Practical response: move to the active OpenAI-format lane

Preserve the project knowledge first, then test the destination on real tasks. One AI API Key offers 46 live free model IDs for OpenAI-format agents. Use https://api.oneaiapikey.com/v1, one key and a selected free ID. The free lane allows 100 requests and 5,000,000 tokens per day per account, shared across the free IDs, and resets at 05:30 IST.

The Claude Code route is documented but unavailable: all four Claude IDs were marked unavailable on 2026-11-27. Free IDs do not work inside Claude Code’s Anthropic-format route. Start with the 46 live free model IDs, follow the OpenAI-format quickstart, and review the per-key controls. Use the cost calculator during the parallel run. The goal is to move the knowledge and verification workflow, not merely the credential.

FAQ

What is the first step in a Claude Code migration?

Inventory prompts, hooks, context files, permissions, test commands and credentials. Assign an owner and a parity test to each item before changing the client.

Can I reuse Claude Code context files directly?

You can preserve their knowledge, but the destination may use a different format or instruction precedence. Move the rules into plain documents, load them through the new client and test a fresh session.

Are all hooks portable?

No. Some hooks depend on client-specific lifecycle events. Move the underlying behavior into repository scripts and decide how the destination invokes them.

Do the 46 free model IDs work in Claude Code?

No. They are OpenAI-format only. Claude Code uses the Anthropic Messages route, and the gateway’s four Claude IDs were unavailable on 2026-11-27.

What should trigger rollback?

Define triggers before cutover: quality drop, tool failure, cost spike, permission gap, context loss or external-state mismatch. Test the rollback path while both routes are available.

Sources

More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
  • 100requests
    per day
  • 3Mtokens
    per day
  • 47free
    models
  • $0per
    token
  • No card
  • No end date
Claim $10 credit →