← Back to library

Give Claude Code a git-backed memory it maintains itself

Reddit user u/tahayelkenci shared a Claude Code memory that has lasted months across three machines: one git repository of working rules, one of project history and one of raw reading notes, all plain markdown. Five hooks load the right rules, gate deploys and nudge Claude to log its work. We turn the structure into a copyable setup.

  • OutcomeKeep your working rules and your project history in separate git repositories of plain markdown, use Claude Code hooks to load a short slice of the right rules at the start of each session, block risky actions until the matching rules are loaded, and have the agent append dated notes and commit them at the end of each task.
  • SetupAn afternoon+
  • LevelAdvanced
  • Creditu/tahayelkenci on r/ClaudeCode
View original
Works with
Claude Code

Published Nov 5, 2026Updated Nov 5, 2026AI dry run on sample input: passed Nov 5, 2026Source verified Nov 5, 2026

When should you use it?

  • Claude Code keeps forgetting your preferences and project decisions between sessions
  • Your CLAUDE.md file has grown so long that sessions start slowly and rules get ignored
  • You work on the same projects from more than one computer or server

Not for: One-off scripts or short projects where a few notes are enough; People not comfortable editing hook scripts and git settings; Storing secrets; keep credentials out of every memory repository

What do you need, and what do you get?

You need

  • A private git host for the memory repositories
  • Your existing rules and preferences, ideally tied to past incidents
  • Claude Code with hooks enabled on each machine

You get

  • A rules repository with one small skill per kind of job
  • A project repository with a readme, a dated log and a decisions file per project
  • Session-start, routing, pre-action, post-write and stop hooks
  • A habit of dated write-backs committed at the end of every task

How does it work, step by step?

  1. Split how from whatCreate one repository for your working rules and another for project records; keep raw reading notes in a third if you want a source trail.
  2. Write rules with reasonsFor each rule give its strength (must, never or prefer), a one-line reason, and a date when it came from your own decision.
  3. Load a small sliceAdd a session-start hook that pulls both repositories and injects only your core rules and the current project's short card, and have it run again after context compaction.
  4. Guard risky actionsAdd a pre-action hook that refuses to deploy or publish until the matching rules are loaded, and asks you before production changes.
  5. Close the loopUse a stop hook to remind the agent to append a dated log entry, update the project status and commit when files changed.

The prompt

Our own prompt, inspired by u/tahayelkenci on r/ClaudeCode and written to work in Claude Code. Values in lime are placeholders.

Fill in the blanks (optional; the copied prompt uses your values)

Prompt4 variables
Help me set up long-term memory for you in plain markdown, kept in git.

1. Create {rules_repo} for how I work: one small file per kind of job ({job_types}). Each rule gets a strength (must, never, prefer), a short reason, and a date if it came from my decision.
2. Create {projects_repo} with one folder per project: a readme (summary, where things live, current status, tasks still pending), a log with dates and a decisions file.
3. Draft hook scripts that: load my core rules plus the current project's readme at session start and after compaction; refuse to deploy until the deploy rules are loaded and ask me first; remind you to log and commit when files changed.
4. Keep the start-of-session load under {token_budget} tokens and never store secrets.
Show me every file before you write it.

Inspired by u/tahayelkenci on r/ClaudeCode: Reddit post: my Claude Code memory is 3 git repos of markdown and 5 hooks. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.

What can go wrong?

  • Mixing rules and history in one file recreates the bloated CLAUDE.md problem. Keep them separate from day one.
  • Hooks that fail open give a false sense of safety. Test what happens when a hook script errors.
  • Logs grow without limit. Only load them on demand and trim the status block now and then.
  • A memory repository is easy to push to the wrong remote. Keep it private and secret-free.

Our take

This is one of the clearest descriptions we have seen of agent memory that a person can actually maintain. The key move is separating how you like work done from what has happened on each project. Rules stay short and stable, history grows in dated logs that are only opened when needed, and neither crowds the other out of the context window. Two ideas are worth copying even without the full setup. First, every rule carries a reason and a strength, which gives the agent something to reason with instead of a bare command. Second, hooks turn memory from a suggestion into a gate: a deploy simply does not run until the deploy rules are loaded. Our cautions are about maintenance and safety. Test how each hook behaves when it fails, keep the repositories private and free of credentials, and prune the status sections. In our dry run we described a fictional two-project consultancy to Claude Code with our prompt, and it produced the two repositories, a 40-line session-start card and a pre-deploy rule, and logged a dated decision when asked to change a preference.

Where the time goes back: Sessions start with the right rules and the latest project status already loaded, so you stop re-explaining preferences and decisions, and the guard hooks prevent the mistakes that cost the most time to undo.

FAQ

Why not a vector database or a memory plugin?
The poster tried those and a very long instruction file, and found plain markdown in git simpler to keep consistent across machines and easier to audit.
How much context does it use?
The poster reports session start fell from roughly 59 KB of readme files to about 3,000 tokens, because only the core rules and a short project card are injected.
Where do I start if hooks feel like too much?
The poster suggests starting with just two folders and a single habit: the agent reads them at the start and records what it did at the finish. Add hooks once that is routine.

Source and credit

Inspired by u/tahayelkenci on r/ClaudeCode. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.

Inspired by
Reddit post: my Claude Code memory is 3 git repos of markdown and 5 hooks
Creator
u/tahayelkenci on r/ClaudeCode
Published on
Reddit
Original date
Nov 4, 2026
License
Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
Originally for
Claude Code
AI dry run
Nov 5, 2026: passed. Dry-run tested by our AI test agent on sample input. Clear split of rules and history, reasons and strengths on rules, a small session-start load, a deploy gate and dated write-backs, all shown before writing.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Nov 5, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

Are you the creator? Claim or correct this page.

More in Operations & Admin

All 203 Operations & Admin playbooks →

Related playbooks

Operations & AdminPrompt✓ AI dry run

Give your agents office hours instead of constant pings

Have your lead agent list every agent and routine that messages you, sort each message type into urgent, decision or FYI, batch decisions into two daily briefings with a recommendation each, collect routine updates into a single evening summary, and set clear rules for the rare cases that may interrupt you.

Credit: Michael Fenech (@Michael_Fenech_)

Under an hour
Operations & AdminRoutine✓ AI dry run

Make key agent routines leave a receipt that gets checked

Pick the scheduled agent jobs you cannot afford to miss, have each one record a receipt with its run time, outcome and what it produced, let a separate checker compare expected runs against receipts on a schedule, and get alerted only for missing receipts, failures or odd results, after testing all four cases with harmless examples.

Credit: Michael Fenech (@Michael_Fenech_)

Under an hour
Operations & AdminWorkflow✓ AI dry run

Add a merge check for every way coding agents break code

Keep a running list of the specific ways coding agents have damaged your repository, from hollow tests and invented fake responses to deleted files and silenced type errors, and turn each one into an automated gate that blocks the merge, so the same mistake cannot slip through review twice.

Credit: u/alexmarquardt on r/ClaudeCode

An afternoon+
Operations & AdminWorkflow✓ AI dry run

Run a supervised pull request review inbox

Your review queue arrives pre-read, with draft comments you edit and send yourself.

Credit: u/jtompl on r/ClaudeCode

Under an hour