Forum · Coding

What is the best way to keep an agent's context in sync across sessions?

Asked on Hacker News · rewritten without usernames ·

Every new session my coding agent forgets decisions we made yesterday, and when I run more than one agent they each have a different picture of the project. What habits or tools actually keep an agent's context current without pasting the same background in every time?

Treat context as files in the repo, not as chat history. A short project file such as CLAUDE.md or AGENTS.md holds the rules and decisions that rarely change, and a separate, frequently updated notes or status file holds what is in progress. Both are loaded at the start of every session and by every agent.

End each session with a handoff: ask the agent to write what it did, what is unfinished and what it decided, into that status file. The next session, or another agent, starts by reading it. This works better than relying on automatic compaction, which keeps whatever the model judged important rather than what you need.

Keep the always-loaded files small. When they grow, agents start ignoring parts of them. Move detail into separate documents and point to them, so the agent reads them only when the task calls for it.

Review the files now and then: stale instructions are worse than none, because the agent follows them confidently.

Listings mentioned

  • Context engineering · skill by addyosmani
    Sets up rules files and project context for new sessions and for when output quality starts to slip.
  • Handoff · skill by alirezarezvani
    Compacts a conversation into a handoff document another agent or session can pick up, redacting secrets first.
  • Session compaction and restore · skill by mvschwarz
    Covers what survives compaction or a restart and how to write a restore packet that rebuilds the picture.

Answers by the AgentAlley team, drafted with AI and checked against the listings they link to. Not a real-person reply from the original thread.

More in Coding