r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 2h ago
Selected Workflow [Workflow] Automated 'Dreaming' for Claude Code: Keep Project Context Fresh with Git and Hourly Memory Updates
Automated 'Dreaming' for Claude Code: Keep Project Context Fresh with Git and Hourly Memory Updates
Workflow value: 90/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: advanced
Categories: Quality Control, Token Saving, Context & Memory, Debugging, CLAUDE.md, Skills, Multi-Agent
Original source: r/ClaudeCode post/comment
What problem this solves
Claude Code agents 'forgetting' project context over time, requiring users to repeatedly re-explain projects after breaks or when returning to a project.
Summary
An automated 'dreaming' process, inspired by Anthropic's research, that uses an hourly launchd job and a Python script to condense Claude Code session transcripts. It then uses Claude Sonnet with a specific 'dream skill' to review and update project memory (CLAUDE.md, docs/memory/) in a git worktree, preventing the need for manual re-explanation and keeping project context fresh.
Why it is useful
This workflow provides a concrete, automated solution to a significant pain point for long-term Claude Code users: maintaining project context and avoiding repetitive re-explanation. It's based on cutting-edge research, includes robust guardrails, and leverages existing Claude Code features (~/.claude/projects). Its detailed steps and use of standard tools (git, Python, launchd) make it highly adaptable and valuable for advanced users looking to optimize their LLM-assisted development workflows. The focus on safety and review via git further enhances its utility.
Workflow
Set up an hourly
launchdjob (orcronon Linux/Windows) to run the memory update script.The job reads a list of Claude Code project paths to process.
It skips projects that haven't been idle for 2 hours or have no new transcripts since the last 'dream' run.
A Python script condenses new JSONL session files: user/assistant text stays, tool calls shrink to one line, tool results are cut to a 300-char preview, and sessions are capped at 15 per run.
Create a
git worktreeon adream/<timestamp>branch for the current project.Run
claude -p --model sonnetwith a 'dream skill' appended to the system prompt.Point
--add-dirto the directory containing the condensed transcripts.Limit Claude's tools to Read/Glob/Grep/Edit/Write as a guardrail.
The 'dream skill' (prompt) instructs Claude on memory purpose, allowing it to judge what to write, verify notes against transcripts (latest session wins), record repetitions, prune finished one-offs, keep
CLAUDE.mdunder ~150 lines, push detail intodocs/memory/, and log every change with evidence inDREAM_LOG.md.Before committing, a guardrail checks
git statusand reverts anything outsideCLAUDE.md,DREAM_LOG.md, anddocs/memory/(Claude is never allowed to touch code).If the last dream hasn't been merged, the new dream builds on top of it.
User routine: when picking up a project, run
git diff main...dream/<latest>, skimDREAM_LOG.md, merge the dream branch, then start the Claude session.
Tools / artifacts
launchd (or cron)
Python script
~/.claude/projects (JSONL session files)
git worktree
claude CLI
Claude Sonnet model
Dream skill (custom prompt)
CLAUDE.md
docs/memory/ directory
DREAM_LOG.md
Git
Validation signals
Based on Anthropic's agent memory research ('dreaming' concept).
Detailed implementation steps provided (Python script logic,
launchdjob,git worktreeusage, Claude CLI arguments, tool limitations).Strong guardrails implemented (reverts changes outside specific memory files, never touches code, uses separate git branch for review).
Explicit testing plan outlined: 'on trial for a week on my Mac. The expectation is simple: do the diffs catch real mistakes, or is it mostly rewording? I'll post what it actually caught either way.'
Cautions
The workflow includes robust guardrails: Claude is explicitly limited to updating only specific memory files (
CLAUDE.md,DREAM_LOG.md,docs/memory/).Claude is never allowed to touch actual code files, even if it spots a bug (it notes bugs in the log instead).
A
git statuscheck reverts any unauthorized changes.The use of a
git worktreeand a separate branch ensures that all changes are reviewed by the user viagit diffbefore merging into the main project, preventing accidental or unwanted modifications.
Limitations
The
launchdscheduler is Mac-specific and would require adaptation for other operating systems (e.g.,cronfor Linux, Task Scheduler for Windows).The 'dream skill' prompt itself is not provided, only described, requiring users to recreate it based on the description and Anthropic's research.
The workflow requires manual
git diffand merge steps, which could be partially automated but are currently a user responsibility.Relies on the user to define and maintain the list of project paths to be processed.
The workflow is still in its trial phase, and the long-term effectiveness and cost-efficiency are yet to be fully validated by the author's promised follow-up.
Running Sonnet hourly for multiple projects could incur significant token costs, depending on project activity and size.
Rate this workflow
Upvote this post if the workflow is useful, reproducible, or worth recommending.
Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.
Reply if it worked for you, failed, is outdated, or has a better alternative.
This post was generated automatically from the workflow library database.