How to switch from Claude Code to Codex mid-task without losing context
Hit a Claude usage limit, or want a second opinion from Codex? Keep the context in the repo, not the chat: one AGENTS.md both agents read, a HANDOFF.md you regenerate on each switch, and git as the source of truth.
- CLI
- 0.2.15
- Preview ref
- b8d1c44
TL;DR
You can't move a live Claude Code conversation into Codex. The two tools keep separate session stores, and neither imports the other's chat history. What you can move is everything that matters, as long as it lives in the repo:
- One instruction file both agents read: put project rules in
AGENTS.md. Codex reads it natively, and current Claude Code reads it too (directly, or through an@AGENTS.mdimport inCLAUDE.md). - A handoff note you regenerate on every switch: ask the outgoing agent to write
HANDOFF.md(goal, what's done, what's next, what it tried that failed, open questions). - Git as the source of truth: commit or stash to a WIP branch before switching, so the arriving agent reads diffs, not your memory of them.
The switch then takes about two minutes, and the new agent starts from a written brief instead of a cold repo.
The problem
The usual way this happens: you're two hours into a refactor with Claude Code, the 5-hour limit hits, and Codex is sitting right there on a different plan. Or Claude has been going around in circles on one bug and you want a different model to look at it.
Opening Codex in the same folder works, but the first ten minutes go to re-explaining: what you're building, which approach you already rejected, why that test is skipped on purpose. And the arriving agent will happily redo the thing you just told the other one not to do.
The fix isn't a clever tool. It's deciding that context lives in files, not in a chat.
What I tried first
- Pasting the last chunk of the Claude transcript into Codex. It works once. It also drags in the noise (tool output, abandoned plans) and leaves out whatever scrolled off.
- Asking Codex to "look at git log and figure it out". Fine for finished work, useless for half-done work and decisions that never became code.
- Keeping two instruction files by hand.
CLAUDE.mdandAGENTS.mddrifted within a week.
Step 1: one instruction file for both agents
Codex reads AGENTS.md from the repo (and from directories above it). For Claude Code, as of 2026-10-11 Anthropic's memory docs say:
- If the repo has an
AGENTS.mdand noCLAUDE.mdorCLAUDE.local.mdin your working directory or above it, Claude Code readsAGENTS.mddirectly (needs Claude Code v2.1.277 or later). - If you do have a
CLAUDE.md, Claude reads onlyCLAUDE.mdby default. Watch out for this one: adding aCLAUDE.local.mdfor personal notes is enough to stop Claude reading yourAGENTS.md. - A
CLAUDE.mdcan import other files with@pathsyntax, and an importedAGENTS.mdis loaded alongside it.
The setup that works with both, including on older Claude Code versions:
<!-- CLAUDE.md -->
@AGENTS.md
## Claude-only notes
- (anything that genuinely only applies to Claude Code, e.g. hook or subagent notes)Then put everything shared in AGENTS.md: build and test commands, code style, "never touch migrations/ by hand", where the docs live. Keep it short. Anthropic suggests under 200 lines per file, and long instruction files get followed less reliably by both agents.
If you'd rather not keep a CLAUDE.md at all, you can delete it and let Claude read AGENTS.md directly. Run /config in Claude Code and check the Project instructions setting if you're not sure which files it's loading. At session start Claude prints a line such as AGENTS.md loaded: ... when it picks the file up.
Step 2: write a handoff note before you switch
Before the outgoing agent loses its context (or before the limit hits, if you can see it coming), ask it to write the note. A prompt I reuse:
Write HANDOFF.md at the repo root for another coding agent taking over this task.
Sections, in this order:
1. Goal (one paragraph, what "done" means)
2. Current state (what works, what's half-done, which files)
3. Next steps (numbered, smallest first)
4. Tried and rejected (approach + why it failed, so it isn't retried)
5. Gotchas (env vars, flaky tests, things that look wrong but are intentional)
6. Open questions for the human
Only facts you verified in this session. No code blocks longer than 10 lines; point to files instead.Two rules make this useful:
- Regenerate it on every switch rather than appending forever. A stale handoff note is worse than none.
- Decide whether to commit it. For a solo branch, committing
HANDOFF.mdon the WIP branch is handy. For shared repos, add it to.git/info/excludeso it never lands in a PR.
Step 3: put the work in git
git checkout -b wip/refactor-auth # if you aren't on a branch already
git add -A
git commit -m "WIP: auth refactor, handoff to codex" --no-verifyNow the arriving agent can run git log -p -1 or git diff main... and see exactly what changed, instead of trusting a summary. (Squash the WIP commits before you open the PR.)
Step 4: start Codex with a pointed first prompt
codexRead AGENTS.md and HANDOFF.md, then run `git diff main...` to see the work so far.
Summarize back to me in 5 bullets what you think the task is and what you'll do next.
Don't change any files until I confirm.The "summarize back first" step is cheap insurance: if the summary is wrong, fix HANDOFF.md, not the conversation, so the next switch benefits too.
Switching back later is the same loop in reverse: have Codex rewrite HANDOFF.md, commit, start Claude Code (claude --continue resumes the previous Claude conversation in that folder, if you want its old context too).
Where Happier fits: two paths for switching
I maintain Happier, an open-source companion app for running Claude Code, Codex and other agents from your phone, desktop or browser. When you're switching between agents, you have two paths:
Path 1: The repo-files method (Steps 1-4 above)
This is the universal method that works anywhere, with or without Happier:
- What it gives you: full control, portable across tools, and the context lives in git where your team can see it
- When to use it: switching between machines, team handoffs, or when you want the arriving agent to start fresh with a clear brief
The files (AGENTS.md, HANDOFF.md, WIP commit) do the real work. If you're using Happier, it just means you can trigger the new session from your phone instead of walking back to the laptop.
Path 2: In-place switching within Happier
As of Happier 0.2.x (verified with the maintainer, though docs.happier.dev still calls it unreleased), you can switch an existing Happier session from one agent to another in place:
- What it carries over: a bounded, text-only summary of recent conversation turns. Images, file contents, and tool output don't carry over.
- What to know: this is a conversation brief, not shared memory between providers. The arriving agent gets "here's what we were just discussing" context, but it won't have the full session history or the reasoning behind earlier decisions.
- When to use it: quick opinion switches ("what does Codex think?"), stuck on a bug, or when you want to continue the same line of thought with a different model
Combined approach: Even with in-place switching, Steps 1-3 still matter. AGENTS.md keeps instructions consistent, HANDOFF.md captures decisions that shouldn't be in conversation turns, and a WIP commit lets the arriving agent see exactly what changed.
Account pools (same agent, different account)
Separate from agent switching: if the reason you're switching is a usage limit, and you have a second account you own for the same agent (your personal and your work subscription, both yours, both signed in as you), Happier's account pools can switch the session to the other account and continue. Nothing switches until you build a pool on purpose, and pools don't raise any cap or shorten a reset.
Who this is for
- People with both a Claude and a ChatGPT plan who switch when one runs out
- Anyone using a second agent for review or a "fresh eyes" pass on a stuck bug
- Teams where different people prefer different agents on the same repo
Common mistakes
- Two hand-maintained instruction files. Import, don't copy.
- A
CLAUDE.local.mdthat silently disablesAGENTS.mdfor Claude (see Step 1). - Handoff notes full of pasted code. Point to files and line ranges. The arriving agent can read them.
- Switching mid-edit. Let the current turn finish, or you'll hand over a half-written file with no explanation.
- Trusting the summary over the diff. The note says what the agent thinks it did;
git diffsays what it did.
Troubleshooting
Claude Code ignores AGENTS.md
Check for a CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the folder or any parent. If one exists, Claude reads that instead by default. Add @AGENTS.md to it, or change Project instructions in /config.
Codex doesn't follow AGENTS.md rules
Confirm you launched Codex from inside the repo, so it finds the file. Very long files get followed less reliably, so trim it. Move one-off task details to HANDOFF.md.
The new agent redoes rejected work
Your "Tried and rejected" section is missing or vague. Name the approach and the reason in one line each.
FAQ
Can I import a Claude Code conversation into Codex?
Not as a conversation. They store sessions separately. Move the context through files (AGENTS.md, HANDOFF.md) and git.
Does Codex read CLAUDE.md?
Codex's convention is AGENTS.md. Don't rely on it reading CLAUDE.md; make AGENTS.md the shared file and have CLAUDE.md import it.
Should I commit HANDOFF.md?
On a personal WIP branch, it's fine and useful. On shared branches, exclude it locally with .git/info/exclude.
Does this work for OpenCode, Gemini CLI or others?
The pattern does: most agent CLIs now read AGENTS.md or let you point them at a file. Check each tool's docs for its exact file name.
Get Happier
Happier is an open-source, end-to-end encrypted companion to run and orchestrate AI coding agents from phone, desktop, and web.