Repository navigation
fix(agents): Claude Code keeps its transcripts on an env clock set ahead of real time - #831
Merged
earakely-scale merged 2 commits intoNov 20, 2026
Conversation
…ead of real time The CLI deletes transcripts older than cleanupPeriodDays (default 30) by its own clock. On an env clock months ahead of the files' real times, it deleted the live session's transcript a few seconds into each run, so each resume saw only what the previous run wrote after that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…head The CLI refuses cleanupPeriodDays 0 and --no-session-persistence keeps no transcript, so the retention is every day a JavaScript date can be from 1970: the CLI's cutoff is never after 1970 on any clock. Checked on a clock 1,000 years ahead (36500 days lost the history, this kept it) and on a 1950 clock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
deleted the
edgararakelyan/fd-6368-hb5118-the-claude-code-agent-loses
branch
November 20, 2026 02:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
On an env clock set ahead of real time, agent-env's Claude Code agent forgets the conversation between turns.
The CLI has a retention cleanup that deletes transcripts older than
cleanupPeriodDays(default 30). It judges age byeach file's modification time against its own clock. Since #726 the CLI runs on the env's clock, while file times
stay real. So with a universe date more than 30 days after the real date, every transcript looks old, including the
live session's.
The cleanup runs a few seconds after each CLI run starts. By then the run has already loaded its history, but it
deletes the transcript and writes the rest of the turn to a fresh file. The next
--resumetherefore sees only whatthe previous run wrote after the deletion.
In the laptop task (psi-benchmark-tasks #19), where the clock is frozen 74 days ahead:
wake, then ordered a Windows 11 Home laptop two wakes later.
Now every CLI run takes
--settings '{"cleanupPeriodDays": 100000000}', which works alongside--setting-sources user.Why that value, and not turning the cleanup off:
cleanupPeriodDays: 0, and--no-session-persistencekeeps notranscript at all, so
--resumewould have nothing.CLI's clock minus that, so it's never after 1970 whatever date the clock shows.
then skips (
if(cutoff===null)return).What changes
claude_bridge.py:CLI_SETTINGSholds{"cleanupPeriodDays": 100_000_000}._commandpasses it as--settingson every run, new or resumed.test_env_clock_image.py: a test that every run carries the setting, at leastJS_DATE_RANGE_DAYS.How it was found and checked
containers every 15 s. Each transcript lost every record five times, e.g. 11.8 MB down to 238 KB. Every loss came
2–36 s after a CLI run started.
libfaketime. Four turns of about 40 s each:
cleanupPeriodDays--settings--settings--settings--settingstst/unit/agents/claude_codepasses, except two tests that fail on macOS onmainas well(
test_card_contractinstall,test_claude_bridge_cancelin-its-group). CI runs them on Linux.End to end
I ran the laptop task twice more on a test host: agent-env 0.9.1585 with only this change applied, and the same
frozen 2027 clock as the failing runs. Each run built the Claude Code image from the patched sources; the built image's
claude_bridge.pyhasCLI_SETTINGS. Both conversations were copied out of their containers every 15 s.One wake per run still gets smaller inside the wake: Claude Code compacted its context (at 170,844 and 158,940
tokens), as it does at any date. The next wake then starts where that one ended. Both runs completed and were scored
normally. They cost $3.44 and $2.26.
Not in this PR
assistant and a user sim that forget.
age-based cleanup, and should be checked.
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
Claude Code now receives a transcript retention period of 100,000,000 days on every run, protecting conversation history when the environment clock is far ahead of real time.
No new actionable issues found.
Reviews (5) · Last reviewed commit: "fix(agents): keep transcripts on any clo..." · Reviewed by Greptile