Give the working state one file in the repo and every session a lifetime. Then stop watching the percentage.
By Manuel Salvatore Martone
Published: 2026-10-28
URL: https://shipwithai.substack.com/p/your-agent-session-is-rotting-while
Manuel had a routine, and he was a little proud of it.
A long session with the coding agent, real work, hours of it. Every so often he glanced at the context gauge. Somewhere past the middle, he stopped the work and typed: write an end-of-session note, everything a fresh session needs to continue. He copied the note somewhere safe, closed the session, opened a new one, pasted a start-of-session prompt, pasted the note, and waited for the agent to catch up. Then he did it again two hours later.
It works. It is also a job: watching a gauge, deciding when, writing the request, carrying text from one window to the next. All of it done by the most expensive part of the system, the person, who was supposed to be thinking about the product.
And while he babysat the session, it was already getting worse. Quality doesn't drop when the window is full. It drops as the window fills.
This week is procedure. One file in the repo, one rule for the agent, two hooks, and a lifetime for every session. You can set the first two parts up in ten minutes, before you finish this post.
What you get today:
-
The 10-minute version: one file, one rule for your agent. Works in any harness. Steps 1–2 below.
-
The kit: both hooks, the limits and the installer, for Claude Code, Codex, omp and Pi. Verified end to end on omp.
Yesterday, posting about your work meant a blank LinkedIn box on Sunday night and a promise to "be more consistent".
Today, you hand ShipPost the links to what you shipped, and a week's worth of posts arrives on Telegram, one at a time, when it's time to post.
It does not publish for you. On purpose: you read every post, you press the button.
The first batch is free.
Why the babysitting happens
Three things, and none of them is laziness.
The session rots before it fills. Old instructions lose weight against hours of code, diffs and tool output. The agent that followed your constraints at 10% context ignores one of them at 70%. The library name for this is context rot, and every harness has it.
Compaction summarises summaries. When the harness compacts, it writes a summary and keeps going. The next compaction summarises a context that already contains that summary. After three rounds, you are working with a copy of a copy, and you can't read any of them.
The working state lives in the chat. Where the task is, what's next, what failed: all of it exists only in the conversation. When the conversation goes, so does the state. So you copy it out by hand, because nothing else will.
The fix for all three is the same. Move the working state out of the chat and into the repo, then let the harness do the moving.
The recipe: one file, two hooks, a lifetime
We call it Context Relay. Six steps, in the order you'd adopt them.
Step 1: give the working state a home
Create .relay/HANDOFF.md in the repo. One file, overwritten, never appended. A snapshot, not a log.
Give it a fixed shape so a cold reader can use it:
-
Goal, with the check that says it's done
-
Done, each item with its evidence (commit, test, command)
-
In progress, and the state it's left in
-
Next, in order
-
Decisions, with the reason
-
Dead ends, so nobody retries them
-
Open questions, and who answers them
-
Verify, the command that proves the current state
Under 150 lines. If a stranger with no chat history can't continue from it, it isn't done.
Step 2: make the agent write it
You don't want to ask for the note. You want the agent to keep it current, just as a good engineer updates a ticket. So put the rule where every harness reads it, in AGENTS.md or CLAUDE.md:
Working state lives in .relay/HANDOFF.md. Update it at every milestone: a task finished, the plan changed, a dead end found, before a long or risky operation. Overwrite it. When it is injected at session start, treat it as a lead: check it against git and the tests before acting.
That last sentence matters. A handoff is a claim about the repo, and the repo can disagree.
On our first test, the agent wrote a decision into the file without being asked. Which is what step 2 is for.
Step 3: read it back automatically
This is the step that removes the paste. Every serious harness can run a command when a session starts, and put the output in front of the model.
In Claude Code, a SessionStart hook in .claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"matcher": "startup|clear|compact",
"hooks": [{ "type": "command", "command": "cat \"$CLAUDE_PROJECT_DIR/.relay/HANDOFF.md\"" }]
}
]
}
}
The compact matcher is the quiet win: after every compaction, the file comes back into context next to the summary. Codex has the same hook ([[hooks.SessionStart]] in config.toml, with features.hooks = true). In omp and Pi it's a small extension.
Now a fresh session, a session after compaction, a colleague's session, and a session on your other laptop all start from the same page.
Step 4: roll over early
Defaults are compact near the limit, which is exactly where quality is at its worst. Move it to about 60%.
-
Claude Code: CLAUDECODEAUTOCOMPACTWINDOW (or --autocompact)
-
Codex: modelautocompacttokenlimit in config.toml
-
omp: compaction.thresholdPercent: 60, and put handoff first in compaction.methodOrder, so the summary is a document you can read
On omp and Pi there's a bonus: the extension copies that handoff document into HANDOFF.md at the moment of compaction, so the file is never older than the last rollover.
Step 5: give every session a lifetime
Most handoff tools we looked at stop at a reminder, or wait for you to type a command. We wanted the session to end itself.
Because compaction summarises summaries, a session should not live forever. After three compactions, or eight hours, it ends. The agent finishes its current step, saves the handoff, and stops. A fresh session starts from the file alone, with a clean context and a fresh read of your rules.
-
omp: the extension pre-fills /relay restart. You press Enter.
-
Claude Code / Codex: the hook tells the agent to wrap up, and tells you to run /clear or /new. The new session rehydrates on its own.
-
Unattended: a small loop runs a fresh claude -p or codex exec after each run, until the file says Status: done, or nothing changed for two runs.
Both limits live in one config file. Set them to 0 if you disagree with us.
Step 6: plug into what you already use
If a framework already keeps state (GSD's STATE.md and .continue-here.md, a plan file, an issue), don't fight it. List its files as sources, and the session-start hook injects them before HANDOFF.md. The framework keeps owning its files. The relay only reads them, and only keeps the working state the framework doesn't track.
What a day looks like
Morning: open the harness in the repo, type "continue". The first answer says where things stand. If it's stale, you fix it in one line.
Mid-morning: nothing. The agent updates the file at milestones; around 60% the harness compacts and carries on.
Before the scary migration: /handoff, or "update the handoff". One checkpoint on demand.
Mid-afternoon: third compaction. The agent wraps up. You press Enter (or type /clear). Work continues in a fresh session.
Evening: "wrap up", then commit HANDOFF.md with your work. Next morning, on any machine, in any harness you've set up: git pull, "continue".
You stopped watching the gauge. That's all that changed, and it's most of the day.
The receipt
We don't trust recipes we haven't run, so we ran this one on omp in throwaway repos.
We put a codeword in HANDOFF.md and asked a fresh session for it, no tools allowed. It answered with the codeword. With the extension removed, the same question got NONE. We forced a compaction with a tiny threshold: the handoff file was rewritten by the harness and the old one archived, and the codeword plus a decision we'd mentioned survived three sessions. The end-of-life limit fired once, at the limit. /relay restart Opened a new session that knew where it was.
What we haven't proven yet: we tested the Claude Code and Codex hook script with simulated input, not inside those harnesses. And on Claude Code and Codex nothing can write the file at the exact moment of compaction (their pre-compaction hook can't talk to the model), so step 2 carries the weight there. That's why step 2 comes before step 3.
Four ways to get this wrong
Appending instead of overwriting. A growing log is a second chat transcript. The file is a snapshot; git keeps the history.
Trusting the file blindly. It's a lead. The agent checks it against git log, git status and the tests first. A stale handoff followed confidently is worse than no handoff.
Keeping decisions only in the handoff. It gets overwritten. Decisions that will matter next month go to the decision log or an ADR. Ten minutes on Friday.
Installing a memory server for this. Memory tools remember facts about you and the project. This is a different problem: where the task is right now. A file in the repo travels with git pull, to another machine, another harness and another person. A memory server on your laptop doesn't.
The one thing to do today
Steps 1 and 2 work in every harness and take ten minutes. Create .relay/HANDOFF.md with the eight headings from step 1, paste the rule from step 2 into AGENTS.md, and tell your agent to fill the file in now, for whatever you're working on.
Tomorrow morning, open a new session and type "continue, starting from .relay/HANDOFF.md". You'll see in one answer whether it was worth it.
The artifact: the Context Relay kit
We packaged all six steps into a kit: three shell scripts, one extension for omp and Pi, config for Claude Code and Codex, and an installer that never overwrites your existing settings. It needs bash and git and nothing else. It runs no server or database and makes no extra model calls.
git clone https://github.com/Ship-With-AI/context-relay
context-relay/install.sh --harness claude /path/to/project # or omp, codex, pi; comma-separated
context-relay/install.sh --flavor gsd --harness omp /path/to/project
The session is disposable. The working state is not. Keep the second in the repo, and you can throw the first away whenever it starts to rot.
— Ale & Manuel
PS. Reply with the first answer your agent gives the morning after you set this up. If it got something wrong, tell us what: that's usually a heading missing from the file, and we'll add it to the template.
When you're ready, two more ways we can help:
1. AI Side-Project Clarity Scorecard. Find what's blocking you from shipping.
2. StackMap. 450+ open-source AI repos, each with a human note on when to use it and when not.
