Codex: How to Switch Codex Accounts Without Losing Your Session, Memory, or Context

Uncategorized

Absolutely. Here is a focused blog tutorial just for switching Codex accounts without losing memory, session, or context.

How to Switch Codex Accounts Without Losing Your Session, Memory, or Context

When you use Codex CLI for a long coding task, the session becomes valuable. It contains your prompts, Codex’s reasoning trail, file edits, decisions, approvals, and task history. So when one Codex account hits a usage limit, the obvious panic moment is:

“If I logout and login with another account, will I lose everything?”

Good news: usually, no. Codex stores your conversation transcripts locally, and you can reopen previous work with codex resume. OpenAI’s Codex CLI docs say resumed runs keep the original transcript, plan history, and approvals, so Codex can continue using the previous context after you resume. (OpenAI Developers)

This tutorial shows the safest workflow.


The idea in simple words

Codex has two different things:

Login/authentication
This is the account currently paying for or authorizing the Codex run.

Local session/context
This is the saved transcript and session history on your machine.

When you run:

codex logout

Codex removes saved authentication credentials. It does not mean your local session history is automatically deleted. The CLI reference says codex logout removes saved credentials, while codex resume continues a previous interactive session. (OpenAI Developers)

So the workflow is:

Save the session ID
Exit Codex
Logout
Login with another account
Resume the old session
Continue working

Tiny goblin rule: do not delete ~/.codex unless you intentionally want to remove local Codex state.


Recommended title for the blog

How to Switch Codex Accounts Without Losing Your Session or Context

Alternative titles:

  1. Codex Account Limit Hit? Here’s How to Switch Accounts Safely
  2. How to Resume Codex Work After Logging Into Another Account
  3. Switching Codex Accounts Without Losing Memory: Complete CLI Guide
  4. Codex Resume Explained: Continue Your Work After Logout/Login

Before switching: understand what Codex saves locally

Codex stores transcripts locally so you can continue previous sessions instead of re-explaining everything. The docs say codex resume lets you reopen earlier threads, and that session IDs can be copied from /status, the resume picker, or files under ~/.codex/sessions/. (OpenAI Developers)

Codex also stores memory files under your Codex home directory, which defaults to ~/.codex; memory files live under ~/.codex/memories/. (OpenAI Developers)

So the most important folder is:

~/.codex

It may contain things like:

~/.codex/sessions/
~/.codex/memories/
~/.codex/config.toml
~/.codex/auth.json

But be careful: auth.json contains credentials if file-based credential storage is used. OpenAI says cached login details may be stored in ~/.codex/auth.json or the OS credential store, and warns that auth.json should be treated like a password. (OpenAI Developers)


Step 1: Check your current Codex session

Inside the active Codex session, run:

/status

The /status command shows session state such as the active model, approval policy, writable roots, current token usage, and session information. (OpenAI Developers)

Copy the session ID if it is shown.

You can also later find sessions from:

~/.codex/sessions/

But /status is the cleanest option.


Step 2: Ask Codex to create a handoff file

Before switching accounts, ask Codex to summarize everything into a file inside your repo.

Inside Codex, type:

Create a file named CODEX_HANDOFF.md summarizing:
- current goal
- files changed
- important decisions made
- commands already run
- tests passed or failed
- remaining TODOs
- exact next command to continue

This gives you a human-readable backup.

Why this matters: even though codex resume should preserve context, a handoff file gives you a second safety net. It also helps if you accidentally resume the wrong session, switch machines, or need to continue manually.


Step 3: Save your Git state

In another terminal, from your project folder, run:

git status

Then save your current diff:

git diff > codex-wip.patch

If you have untracked files, list them:

git ls-files --others --exclude-standard

Optionally create a temporary branch:

git switch -c codex-account-switch-backup

Then commit the handoff file and current work if appropriate:

git add CODEX_HANDOFF.md
git commit -m "docs: add Codex handoff before account switch"

For unfinished code, you may prefer a stash instead:

git stash push -u -m "codex work before account switch"

This is not strictly required for Codex context, but it protects the actual code changes. Context without code is like a recipe without ingredients. Sad soup.


Step 4: Exit the current Codex session

Inside Codex, run:

/exit

The docs list /exit as the command to close the interactive session. (OpenAI Developers)

Do not use /clear.

/clear starts a fresh conversation in the same CLI session, while Ctrl+L only clears the terminal view. The docs specifically say /clear resets the visible transcript and starts a new conversation. (OpenAI Developers)

For account switching, use:

/exit

not:

/clear

Step 5: Logout from the current account

Now run:

codex logout

The CLI reference says codex logout removes saved credentials for API key and ChatGPT authentication. (OpenAI Developers)

Again, this is about authentication. Your saved sessions are separate local state.


Step 6: Login with the second account

Now login with the other account:

codex login

With no flags, codex login opens a browser for ChatGPT OAuth. It can also use device auth, API key, or access token flows. (OpenAI Developers)

If you are on a remote server or headless machine, use:

codex login --device-auth

OpenAI’s auth docs recommend device code authentication when browser login is difficult in remote or headless environments. (OpenAI Developers)

You can check whether login worked:

codex login status

The CLI reference says codex login status prints the active authentication mode and exits successfully when credentials are present. (OpenAI Developers)


Step 7: Resume your old Codex session

Now resume your previous session.

From the same project directory, run:

codex resume --last

This resumes the latest session for the current working directory. OpenAI’s docs say codex resume --last jumps to the most recent session from the current working directory. (OpenAI Developers)

If you are not in the same directory, use:

codex resume --all

The docs say codex resume --all shows sessions beyond the current working directory. (OpenAI Developers)

If you copied the exact session ID earlier:

codex resume <SESSION_ID>

Example:

codex resume 7f9f9a2e-1b3c-4c7a-9b0e-123456789abc

That is the most precise option.


Step 8: Confirm Codex still has the context

After resuming, ask Codex:

Please summarize the current task, what files were changed, what decisions were made, and what remains to do.

Then compare that with:

cat CODEX_HANDOFF.md

Also check the code state:

git status
git diff --stat

If the summary matches, you’re good.


Complete safe workflow

Here is the full flow from start to finish.

Inside Codex

/status

Copy the session ID.

Then ask Codex:

Create CODEX_HANDOFF.md with the current goal, changed files, decisions, commands run, test status, TODOs, and exact next step.

Exit:

/exit

In your terminal

git status
git diff > codex-wip.patch

Optional:

git stash push -u -m "codex work before account switch"

Then switch accounts:

codex logout
codex login
codex login status

Resume:

codex resume --last

Or, if needed:

codex resume --all

Or exact session:

codex resume <SESSION_ID>

What about Codex memory?

There are three things people often call “memory”:

1. Current session context

This is the active conversation/thread. Use:

codex resume --last

or:

codex resume <SESSION_ID>

This is the most important thing for continuing an unfinished task.

2. Codex memories

Codex memories are stored under ~/.codex/memories/ by default. OpenAI says memories include summaries, durable entries, recent inputs, and supporting evidence from prior threads. (OpenAI Developers)

Inside Codex, you can configure memory behavior with:

/memories

The slash command docs say /memories lets you choose whether Codex should use existing memories, generate new memories, or keep memory disabled. (OpenAI Developers)

3. Project guidance

This is usually AGENTS.md.

Codex docs describe AGENTS.md as durable project guidance that can include repo layout, test commands, conventions, constraints, and what “done” means. (OpenAI Developers)

For long-term reliability, add recurring instructions to:

AGENTS.md

or globally:

~/.codex/AGENTS.md

That way, even if you start a fresh session, Codex can still recover important project rules.


What not to do

Do not delete this folder:

~/.codex

That may remove sessions, memory files, config, or credentials depending on your setup.

Do not run:

rm -rf ~/.codex

unless you intentionally want a hard reset.

Do not use /clear before switching accounts, because it starts a fresh conversation. Use /exit.

Do not rely only on memory. Always save a handoff file and your Git diff before account switching.


Best practical recommendation

My recommended habit is:

Before account switch:
1. Run /status
2. Copy session ID
3. Create CODEX_HANDOFF.md
4. Save git diff
5. Exit
6. Logout/login
7. Resume exact session ID

The golden command is:

codex resume <SESSION_ID>

The lazy-but-usually-fine command is:

codex resume --last

The “I forgot where I was” command is:

codex resume --all

Final cheat sheet

# Inside Codex
/status
# Inside Codex
Create CODEX_HANDOFF.md summarizing current task, changed files, decisions, test status, TODOs, and next step.
/exit
# Terminal
git status
git diff > codex-wip.patch
codex logout
codex login
codex login status
codex resume --last
codex resume --all
codex resume <SESSION_ID>

Conclusion

Switching Codex accounts does not have to mean losing your work. Your account login and your local session history are different things. codex logout removes credentials, while codex resume reopens saved local sessions.

For the safest workflow, always capture the session ID with /status, create a CODEX_HANDOFF.md, save your Git diff, logout, login with the second account, and resume using codex resume <SESSION_ID>.

That gives you three layers of safety:

Codex session resume
Handoff summary file
Git diff or stash backup

And that is how you switch Codex accounts without nuking your context like a caffeinated raccoon in a terminal.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x