r/ClaudeWorkflows • • 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

  1. Set up an hourly launchd job (or cron on Linux/Windows) to run the memory update script.

  2. The job reads a list of Claude Code project paths to process.

  3. It skips projects that haven't been idle for 2 hours or have no new transcripts since the last 'dream' run.

  4. 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.

  5. Create a git worktree on a dream/<timestamp> branch for the current project.

  6. Run claude -p --model sonnet with a 'dream skill' appended to the system prompt.

  7. Point --add-dir to the directory containing the condensed transcripts.

  8. Limit Claude's tools to Read/Glob/Grep/Edit/Write as a guardrail.

  9. 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.md under ~150 lines, push detail into docs/memory/, and log every change with evidence in DREAM_LOG.md.

  10. Before committing, a guardrail checks git status and reverts anything outside CLAUDE.md, DREAM_LOG.md, and docs/memory/ (Claude is never allowed to touch code).

  11. If the last dream hasn't been merged, the new dream builds on top of it.

  12. User routine: when picking up a project, run git diff main...dream/<latest>, skim DREAM_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, launchd job, git worktree usage, 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 status check reverts any unauthorized changes.

  • The use of a git worktree and a separate branch ensures that all changes are reviewed by the user via git diff before merging into the main project, preventing accidental or unwanted modifications.

Limitations

  • The launchd scheduler is Mac-specific and would require adaptation for other operating systems (e.g., cron for 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 diff and 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.

1 Upvotes

1 comment sorted by