Explainer
Why AI coding agents lose context between machines
AI coding agents lose context across restarts and machines because language models are stateless — active working memory only exists inside the current context window — and harnesses save session transcripts (prompts, replies and tool calls) as local files on one machine in formats only that agent can read. Switch from your desktop to your laptop, start a fresh session, change agents, or let a retention window pass, and the next session starts without what the earlier one already learned.
curl --proto '=https' --tlsv1.2
-LsSf https://setup.atuin.sh | sh
TL;DR
Losing context with AI coding agents is rarely one bug. It comes from stateless models, local-only transcript files, incompatible harness formats, and the gap between static project rules and session history.
-
01
LLMs have no built-in memory across calls, and harnesses store prompts and tool calls on one machine's disk. Moving from desktop to laptop leaves every local transcript behind.
-
02
Each agent writes its own schema (JSONL or SQLite), so Codex cannot open a Claude Code session and vice versa.
-
03
Some harnesses expire local files automatically: Claude Code deletes transcripts after 30 days by default.
-
04
Even on the same machine, compaction drops earlier detail inside a long session, fresh sessions start empty, and
CLAUDE.mdorAGENTS.mdhold static rules rather than past session history.
Six ways AI coding agents lose context
Switching machines, restarting a session, and switching harnesses each break context in a different way. Knowing which failure mode you hit tells you what actually fixes it.
| Cause | What you see | Why it happens | Fix |
|---|---|---|---|
| Local-only files | Your prompts, tool calls and sessions vanish when you switch from desktop to laptop; --resume shows nothing. |
Agents write session transcripts to local disk (~/.claude, ~/.codex, local SQLite) with no built-in cross-machine sync. |
Sync captured transcripts between machines and restore them into the agent's native store before resuming. |
| Agent-specific formats | You hit a wall in Claude Code and open Codex or opencode, but the new agent cannot see the conversation or tool calls so far. | Every harness stores its own transcript schema, message roles, and tool-call structure. None read another agent's files. | Convert and write the session into the target agent's native format, mapping tool calls and outputs over. |
| Retention cleanup | An investigation from last month vanishes from the resume picker on the exact same machine. | Claude Code deletes local session transcripts after 30 days by default (cleanupPeriodDays). |
Raise cleanupPeriodDays in settings, or capture sessions into an independent store that does not expire them. |
| Context compaction | Mid-session, the agent forgets an earlier constraint, repeats a failed check, or loses exact error output. | Once a conversation approaches the model's context window limit, the agent compacts or truncates older turns into a shorter summary. | Keep sessions focused, fork before big detours, or let the agent query the full uncompacted transcript on demand. |
| Fresh session starts | Restarting or opening a new session in the same repo forces you to re-explain yesterday's debugging and ruled-out fixes. | Language models are stateless: new sessions start with an empty message history unless something feeds past work back into context. | Resume the prior session directly, or expose past sessions over MCP so the new session can search them when needed. |
| Rules vs. history | You wrote a thorough CLAUDE.md or AGENTS.md, yet the agent still repeats work from earlier sessions. |
Repo memory files store durable conventions and instructions, not a chronological log of prompts, tool calls, and debugging dead ends. | Keep conventions in repo memory files and store session history separately where agents can search or resume it. |
Four layers of coding-agent context
"Agent memory" is not one thing. Coding agents split context across four distinct layers with different lifetimes, storage limits, and portability across machines.
| Context layer | Where it lives | Survives restart? | Survives machine switch? | What it holds & limits |
|---|---|---|---|---|
| Active context window | In-memory prompt sent on each model turn | —No | —No | Live conversation, file reads and tool results; bounded by the model window and thinned by compaction. |
| Local session transcripts | Per-agent files on one machine (JSONL or SQLite) | ✓Same machine | —No | Full prompts, replies and tool calls; locked to one harness and subject to local cleanup (30 days by default in Claude Code). |
| Repo memory files | CLAUDE.md, AGENTS.md, .cursor/rules in git |
✓Yes | ✓Via git | Static project conventions, architecture rules and commands; not a record of past sessions or debugging dead ends. |
| Synced thread store | Atuin Threads: local SQLite + E2E encrypted sync | ✓Yes | ✓Yes | Prompts, replies and tool calls across 11 agents with no retention cap (~64 KiB cap per large tool payload). Free offline and free personal cloud sync, or self-hosted (MIT). |
Where each agent keeps its sessions
Local coding agents persist conversations in different directories, file formats, and retention policies. None of these local stores sync between machines by default, and no agent reads another agent's directory.
| Agent | Storage location | Format | Retention | Source |
|---|---|---|---|---|
| Claude Code | ~/.claude/projects/<project>/<session-id>.jsonl (respects $CLAUDE_CONFIG_DIR) |
JSONL (one file per session) | Deleted after 30 days by default (cleanupPeriodDays in settings.json) |
Claude Code settings docs |
| Codex | ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl (under $CODEX_HOME), indexed by state_5.sqlite |
Append-only JSONL rollouts + SQLite index | No automatic expiry; kept until deleted or moved to archived_sessions/ |
openai/codex |
| opencode | ~/.local/share/opencode/opencode.db (respects $XDG_DATA_HOME; older versions used JSON files under storage/) |
SQLite database (opencode.db) |
No automatic expiry; kept locally until deleted | anomalyco/opencode |
| Cursor |
globalStorage/state.vscdb and workspaceStorage/<hash>/state.vscdb under the Cursor User data folder
(macOS: ~/Library/Application Support/Cursor/User/; Linux: ~/.config/Cursor/User/; Windows:
%APPDATA%\Cursor\User\), plus ~/.cursor/projects/<slug>/agent-transcripts/
|
SQLite (state.vscdb) + JSONL agent transcripts |
No documented automatic expiry; workspace history is keyed to local folder paths | Cursor hooks docs |
Storage paths reflect current upstream documentation and source code. Path encoding also matters: moving or renaming a project folder can hide local sessions from an agent's picker even when the files are still on disk.
Workarounds people use, and where each falls short
Developers already work around local-only transcripts in a few common ways. Each solves part of the problem, and each hits a clear limit once you work across machines or agents.
-
01
SSH or tmux into one machine
Works well when you have a reliable connection and do all your work on one dev box or desktop. It breaks down offline (on a flight or train), adds latency on poor networks, and still leaves you stuck inside one agent and its retention policy.
-
02
Syncing session folders with rsync, Dropbox or iCloud
Fine for a one-off copy of a closed JSONL file, but fragile in daily use. Agents that store state in SQLite (
opencode.db, Codex'sstate_5.sqlite, Cursor'sstate.vscdb) can conflict or corrupt when two machines write at once, and hardcoded absolute paths differ between macOS and Linux. -
03
Pasting summaries into a new session
Quick for a planned handoff, and requires zero setup. You lose the exact tool outputs, diffs, and dead ends the first session hit, and it only works when you remember to ask for a summary before switching machines or closing the lid.
-
04
Checking in
CLAUDE.mdorAGENTS.mdEssential for repo conventions, build commands, and architecture rules — those belong in git. They are not a session log: stuffing in-flight debugging state into memory files bloats every future prompt and goes stale as soon as the branch merges.
The fix: capture, sync and restore with Atuin Threads
Atuin Threads separates session history from any single machine or harness. It captures prompts, replies, and tool calls from 11 coding agents into a local SQLite database with no retention cap (large individual tool payloads are clipped around 64 KiB). Local use and personal end-to-end encrypted sync on Atuin Cloud are free, or you can self-host the MIT-licensed sync server on your own infrastructure.
When you switch machines, atuin resume writes the native transcript back out before launching the agent, forks a session
without touching the original, or continues it in a different agent with tool calls mapped over. When you start a fresh session and only
need what an earlier one discovered, Atuin's MCP server lets the agent search past
sessions directly without resuming them.
-
01 Install or update Atuin
curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh -
02 Capture your agents' sessions
atuin setup --only --threads --daemon -
03 Sync them between machines
Or pass your own server's address instead of
cloud. Skip this to keep threads local.atuin setup --sync cloud -
04 Bring in sessions from before
Capture starts when you turn it on. This imports what your agents already have on this machine.
atuin threads import
For the full walk-through and the 11-agent capability matrix, read the resume agent sessions guide. You can also explore Atuin for agents or the Atuin Threads announcement post.
Frequently asked questions
Why do my AI coding agents lose context when I switch between machines?
Language models are stateless, and coding agents save conversation transcripts — including prompts and tool calls — to local disk on the machine where the session ran (for example under ~/.claude/projects/ for Claude Code or ~/.codex/sessions/ for Codex). Because those local files do not sync across machines, opening the agent on another device gives its resume picker nothing to load.
Why do coding agents lose context when I restart or start a new session?
Starting a new session begins with an empty context window unless you explicitly resume a prior transcript or give the agent a way to search past sessions. Within a long session, context compaction can also summarize away earlier tool outputs and constraints once the context window fills up.
What should I do when my AI coding agent loses context after I restart it on a different device?
First pull the latest git branch so the files on disk match where you left off. If you already run Atuin Threads with sync on both machines, run atuin resume to restore the native transcript on the new machine (or query it over MCP from a fresh session); otherwise turn on Threads capture and sync on both machines so future switches carry your prompts and tool calls automatically.
Why did my old Claude Code sessions disappear on the same machine?
Claude Code deletes local session transcripts after 30 days by default via the cleanupPeriodDays setting (documented in the Claude Code settings docs). Raising that setting keeps local files longer, or Atuin Threads captures sessions into its own SQLite store with no retention cap so atuin resume can restore them even after local cleanup.
Why don't CLAUDE.md or AGENTS.md prevent context loss?
Repo memory files are loaded as static instructions at the start of a session. They work well for coding standards, architecture notes, and commands, but they do not record what happened during yesterday's debugging session, which hypotheses failed, or what tool outputs came back.
Can I resume a session on another machine or continue it in a different agent?
Yes. With Atuin Threads capture and sync enabled on both machines, atuin resume restores the native transcript on the new machine, forks it, or continues it in another agent (such as handing a Claude Code session to Codex). See the resume agent sessions guide for supported agents and steps.