Pascal Freyer

Sleep Agent

A nightly agent that reads the day's work, checks what it learned against live sources and rewrites its own long-term memory.

Abstract

An AI assistant forgets everything when a session ends. The Sleep Agent is the fix I run on my own machine: every night it reads the day's sessions, pulls out what should last, checks each claim against live sources and writes the result into a long-term memory that the next session loads.

It runs without me. Edits that pass the evidence rules are applied on the spot, anything that would change the agent's own configuration stays a proposal, and every night can be undone with one command.

Technical overview

Schedule
A scheduled job on macOS at 02:25, running Claude Code without a window and under its own restricted permissions.
Edit rules
Edits touch memory folders only. No deletes, a replace needs one exact match, and every edit carries its evidence.
Memory
Two layers: plain Markdown notes as the source of truth, mirrored into a local SQLite index with semantic search.
Recall
A hook retrieves the best matching notes for every new prompt, so the right memory arrives before the answer.
Safety
A snapshot before each apply, one-command undo, and 67 self-tests on the apply and scheduling scripts.
Every night at 02:25 Gather signalsessions, notes, tasks Fact-checkagainst live sources Draft editsreport and edit list [evidence ok] Apply editssnapshot first Mirror to indexlocal semantic search [else] kept as a proposal
The nightly pass as an activity diagram.
SchedulerNight agentSourcesValidatorMemory notesSearch indexstart at 02:25read sessions, notesfact-check claimsreport and edit listevery edit needs evidence, no deletesapply editsmirror changesconfig ideas stay proposals
One night as a sequence diagram: the agent proposes, a separate validator applies.
Sessionsthe day's transcriptsNight agentextracts what lastsMarkdown notessource of truthLocal indexsemantic searchNext sessiontop hits per prompt
How a lesson travels from today's session into tomorrow's.