Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

Replace Karpathy's Agent Memory Automation with This 30-Line /close-day Hook
AI ResearchScore: 89

Replace Karpathy's Agent Memory Automation with This 30-Line /close-day Hook

Background automation fails on laptops; use a simple /close-day skill and date tags in MEMORY.md instead.

GAla Smith & AI Research Desk·3h ago·4 min read·6 views·AI-Generated
Share:
Source: dev.tovia devto_claudecodeCorroborated
Replace Karpathy's Agent Memory Automation with This 30-Line /close-day Hook

Andrej Karpathy's agent memory architecture—where conversations flow into daily logs, logs compile into a wiki, and the wiki injects into future sessions—has 53K GitHub stars for good reason. It's a beautiful concept. But when one developer tried to implement it with full automation in Claude Code, half their sessions lost context within three weeks.

What Went Wrong with Automation

The original architecture assumes server-side execution with reliable background processes and clean transcript access. Claude Code runs on your laptop. Close the lid, background processes die. Long sessions choke transcript parsers. Logs fail silently.

Their initial setup looked sophisticated:

# session-end.sh (the old, broken version)
# Extracts last 100 turns from transcript
# Spawns flush.py in background
# flush.py calls claude -p Opus to summarize
# flush.py checks if it's after 6pm
# If yes, spawns compile.py (also background)
# compile.py calls claude -p Sonnet to build wiki articles
# CLAUDE_INVOKED_BY guard prevents infinite recursion
# SHA-256 hash comparison skips unchanged logs

Results after three weeks across seven projects: auto-flush hooks fired on every session end, but background processes timed out, failed to parse transcripts, or exited silently 50% of the time. The after-6pm auto-compile never triggered once.

Three Fixes That Actually Work

Fix 1: One Manual Command Instead of Background Automation

Claude Memory Kit — The OS layer for Claude Code

Replace the entire automation pipeline with a single skill: /close-day. Type it when you're done working.

Why this works: When the background process ran, it had no project context—just raw transcript JSON. When you call /close-day inside your session, the agent still has the full picture of what you worked on, decisions made, and pending tasks.

Here's the new session-end.sh (30 lines):

#!/usr/bin/env bash
set -euo pipefail
if [[ -n "${CLAUDE_INVOKED_BY:-}" ]]; then exit 0; fi
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}"
mkdir -p "$PROJECT_DIR/.claude/state"
HOOK_INPUT=$(cat)
SESSION_ID=$(echo "$HOOK_INPUT" | python3 -c \
  "import sys,json; print(json.load(sys.stdin).get('session_id','unknown'))" \
  2>/dev/null || echo "unknown")
echo "$(date '+%Y-%m-%d %H:%M:%S') SessionEnd: $SESSION_ID" \
  >> "$PROJECT_DIR/.claude/state/flush.log"
exit 0

It logs a timestamp. Done. Knowledge capture happens when you deliberately ask for it.

Fix 2: Date Tags on Everything

Every entry in MEMORY.md now carries a [YYYY-MM-DD] tag. Every backlog update, every session handoff note. When /close-day runs, the agent greps for today's date across all structured files and knows exactly what changed.

This handles long days with 10-15 sessions. The old system tried to parse each transcript separately. The new system doesn't care about individual sessions—it looks at the end state of every file and asks: what has today's date?

## Proven Patterns

| Pattern | Evidence |
|---------|----------|
| Flush deprecated, /close-day replaces [2026-04-17] | ~50% failure rate |
| README sells simplicity [2026-04-17] | Marketer ICP test |
| NSP self-cleaning rule [2026-04-17] | 455 lines trimmed to 161 |

No transcript parsing. No background merge logic. Just dates and grep.

Fix 3: Move Knowledge Base Out of .claude/

Claude Code treats everything under .claude/ as sensitive. Write operations get silently blocked or require special permissions that background subprocesses don't have.

Moving knowledge/ from .claude/memory/knowledge/ to the project root fixed it instantly:

# Before (broken)
.claude/memory/knowledge/concepts/
.claude/memory/knowledge/connections/

# After (works)
knowledge/concepts/
knowledge/connections/

The Simplified Workflow

  1. Open a session – Context loads automatically from a Python hook that injects the wiki index and recent daily logs
  2. Work normally – Safety hooks checkpoint progress every 50 exchanges and before context compression
  3. Type /close-day when done – Agent synthesizes today's changes into a daily article

That's the whole system. Tomorrow's session picks up where today left off.

After a few weeks, the knowledge base has real substance: cross-referenced wiki articles about project patterns, architectural decisions, debugging lessons—all searchable, structured, and built from actual work rather than raw transcript scraping.

The Takeaway

Karpathy's second principle for working with LLM agents is "Simplicity First. Minimum code that solves the problem." The developer took his agent memory concept, built a 300-line automation pipeline on top of it, then replaced all of it with one 30-line script and a manual command.

The architecture was Karpathy's. The over-engineering was theirs. The simplified version—claude-memory-kit—takes about five minutes to set up with no external dependencies.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

**Stop trying to fully automate memory in Claude Code.** Background processes on laptops are inherently unreliable. Instead, implement a manual `/close-day` skill that runs while your session context is still active. This gives Claude the full picture of what you accomplished, not just raw transcript data. **Add date tags `[YYYY-MM-DD]` to every entry in your structured files** like `MEMORY.md` and project backlogs. This creates a simple, grep-able audit trail. When you run `/close-day`, Claude can quickly identify everything changed today without parsing individual session transcripts. **Move your knowledge base out of `.claude/`** to avoid silent write permission issues. Place `knowledge/concepts/` and `knowledge/connections/` in your project root instead. This simple directory change fixes what could take weeks to debug. These three changes preserve Karpathy's two-layer memory architecture (hot cache + wiki) while making it actually work in the real-world constraints of Claude Code running on your laptop.

Mentioned in this article

Enjoyed this article?
Share:

Related Articles

More in AI Research

View all