How to transfer a session between console AI agents without losing context
Guide: we take a live session from local logs and pass it to another agent with a single command. Without retellings and extra tokens.
What you will need
- Two console agents. For example, Claude Code and Codex. Or Pi, Hermes, Antigravity CLI (agy).
- Access to local session logs. For most agents they are stored in the home directory.
- The
batonutility (the command for transferring a session). If it is not there — install it from the repository. Look for the link in the article on Habr; there is no data about the package. - A basic understanding of where the agent stores history. Without this, the steps below will not work.
The Habr article dated October 30, 2026 describes the approach: do not ask the model to retell, but take the raw log and feed it to the new agent. Below is how to do this manually.
Step 1. Find the session file of the current agent
Each agent has its own format and path. Check the typical locations:
# Claude Code
ls ~/.claude/projects/
# Codex
ls ~/.codex/sessions/
# Pi, Hermes, agy — look in ~/.config/<agent-name>/
Inside — files with the .jsonl or .json extension. One file — one session. The name usually contains the date and identifier.
If you are not sure which file is fresh, sort by time:
ls -lt ~/.claude/projects/*/*.jsonl | head
Step 2. Make sure the log contains the full context
Open the last lines of the file:
tail -n 20 path/to/session.jsonl
You should see user messages, agent responses, and tool calls. If the log contains only metadata (for example, {"type":"summary"}), then the full history is stored elsewhere. Look for a larger file.

Important: the log is written while the agent is running. Before copying, stop the agent or wait until it finishes the current step.
Step 3. Pass the log to the new agent via baton
baton reads the session file and generates a prompt for another agent. The command looks like this:
baton transfer \
--from ~/.claude/projects/project/session.jsonl \
--to codex \
--output handoff.txt
Flags:
--from— path to the source log.--to— target agent (codex,agy,pi,hermes).--output— the file where baton will write the ready prompt.
If baton is not installed, check whether it is in PATH:
which baton
If empty — install it according to the instructions from the repository. There is no data about the package manager.
Step 4. Launch the target agent with the file passed
Pass handoff.txt to the new agent as the first prompt. For example, for Codex:
codex < handoff.txt
Or open an interactive session and paste the file contents manually:
cat handoff.txt | codex
The agent will receive the entire dialogue, including tool calls and results. The context is not retold — it is passed as is.

Step 5. Check that the context was not lost
Ask the new agent about details that were only in the source session. For example, the name of a variable or the last error. If the agent answers correctly — the transfer succeeded.
If the agent gets confused, go back to step 2. Most likely, the log is incomplete or truncated.
Step 6. Continue working
Then work in the new agent as usual. The old log can be saved in case of rollback. baton does not delete the source files.
Typical mistakes
Mistake 1. You use HANDOFF.md instead of the log.
The agent writes a summary in its own words and loses details. It is easy to tell: the new agent asks questions that have already been resolved. The solution is to take the raw log, not a retelling.
Mistake 2. You copy the log while the agent is running.
The file may be unfinished. A sign: the last lines break off in the middle of JSON. Stop the agent and copy again.
Mistake 3. You pass the wrong file.
The directory contains logs of different projects. Check that the log contains the needed messages: grep "variable_name" session.jsonl. If empty — the file is wrong.
Mistake 4. The target agent does not understand the format.
Some agents expect the prompt in a different form. baton converts, but if you copy manually, check that you did not paste raw JSONL. A sign: the agent replies "cannot parse". Use the output of baton, not the source file.
Mistake 5. Limits have run out for everyone.
Transfer does not create quota. If all accounts are exhausted, wait for the reset or connect open agents (Pi, Hermes) with DeepSeek, GLM, Grok models. There is no data that transfer bypasses limits.
Mistake 6. The server prompt cache is reset.
When changing the Claude Code account, the standard --resume will pick up the session from disk, but the prompt cache on the server will be reset. Re-pumping a long history will eat a chunk of the new quota. This is not a transfer error, but a feature of changing the account. Take it into account when planning.
In the end
Transfer via a local log preserves context more accurately than a retelling. One baton transfer command and launching the target agent with the file — that is all you need. If the log is complete and the agent accepted it, the task continues from the same place.