While drafting this article, my coding agent opened one of its own saved memories

It said my blog images should look like lavender sticky notes. I had saved it 65 days earlier

But I had attached another reference, grey machines on white. So my agent followed this newer one. Later I changed my mind again and asked for line diagrams

It had to decide which piece of state still counted. Agents make some version of this call all day

TL;DR

  • Models keep no memory between API calls. Everything stored around them is state
  • I count eight layers: context, instructions, working state, memory, environment, identity, side effects and record
  • Each layer has its own lifespan and breaks in its own way
  • Attackers move from one layer into another, so each crossing needs one check

Eight layers of state

1. Context

Whatever Claude, GPT or Gemini can read on its current turn

Longer sessions get summarized to make room, and details can go missing. One line saying "leave this table alone" may look minor to whichever model writes my summary. One hour later it matters plenty

Check: exact values live in files, where agents can reopen them

Red flag: one important rule exists only in chat

2. Instructions

System prompts, CLAUDE.md, AGENTS.md, hooks and skills

Two rules can disagree. We tested this on three coding agents. Claude Code and Codex followed chat over their agent file. Antigravity followed its file over chat in 12 of 12 runs

Check: each rule lives in one place, and edits go through code review

Red flag: agents changing their own rule files

3. Working state

Plans, finished steps and half-edited files for one job

Anthropic's long-running agent setup starts each session by reading git logs, one progress file and one feature list. They built it after later sessions looked around, saw progress and declared victory early

Subagents add another gap. Their parent sees only their summary, and "tests pass" reads nothing like "tests pass, six skipped"

Check: compare each report with its diff

Red flag: one plan says done and git says otherwise

4. Memory

Whatever survives once sessions end

My setup is plain: small markdown files with one fact each, plus one index my agent loads at start

Memories go stale. They can also be planted. Researchers behind MINJA put bad records into shared agent memory through ordinary queries, with 98.2% average injection success in their lab. One later study found these attacks far less effective once memory held legitimate entries

Check: every entry has its date and reason

Red flag: web page text saved as memory without review

5. Environment

Git branches, running processes, database rows, browser tabs

Other people change these while agents think. Resumed agents hold yesterday's picture

Check: run git status before each commit

Red flag: agents resuming on one branch while their notes describe another

6. Identity

API keys, OAuth grants and signed-in browsers

Say someone issues one database token for Tuesday's migration. Unless it expires, any process able to read it can still use it on Friday

Check: short-lived keys with narrow scopes, and real values kept out of context

Red flag: one key outliving its task

7. Side effects

Emails sent, cards charged, code pushed

Crashes make these worse. Some worker finishes its job, then dies before reporting back. Its system retries, and one customer may pay twice

LangGraph has its own version. Paused nodes restart from their first line on resume, so any email sent before pausing can go out again

Check: idempotency keys where services support them, and human approval where there is no undo

Red flag: retries with no check for existing results

8. Record

Transcripts and audit logs

Incident reviewers depend on them. So does any agent resuming old work

Check: logs show if someone edited them later

Red flag: one printed secret sitting in some transcript for months

Save, resume, fork

Save, resume, fork

  • Save after each step, since crashes skip end-of-session cleanup
  • Resume by rechecking branch, files and permissions first
  • Fork into separate worktrees when both copies will edit code
  • Hand off goal, finished work, open work and evidence
  • Expire stale memories and old tokens

Expiry is easy to put off. Old tokens cause no visible trouble until someone misuses one

How attackers read this

Picture one poisoned web page

Web page to context to memory to credentials to email and push, with one check at each crossing

My agent reads it, so its text enters context. If my agent saves it as one of its notes, it returns tomorrow looking like something I wrote. From there it can steer whatever credentials my agent holds, and send email or push code

Four checks, one per crossing:

  1. Treat web pages and tool results as data, with no authority to give orders
  2. Review writes to memory and rule files as carefully as code
  3. Keep secret values out of context
  4. Check risky tool calls in code before they run

Try it on one agent

Pick one agent in production. For each layer, write down where it is stored, who can write to it and when it gets deleted

I'd start with memory and identity, since those two carry most risk from one session into another

We build Prismor for these checks, and it is open source

pip install prismor

prismor.dev