Building long-term memory for Claude Code with Git repositories and hooks
The author ditched large Obsidian vaults and vector databases, splitting memory into three Git repositories: "how we work," "what happened," and "raw material." Combined with automated hooks, this setup enables precise context loading, error checking, and automatic write-backs.
Added 2026-11-05 · originally published 2026-11-04
Steps
- 1Create three independent Git repositories: Repository 1 stores working rules and preferences (broken down into small files by professional skill, including weights and rationale), Repository 2 stores project status and dated logs, and Repository 3 stores raw learning materials.
- 2Configure the Session Start hook: pull the repositories, inject core rules, personal identity, and the current project's short-term card (around 3k tokens), and re-trigger after context compaction.
- 3Configure the message routing hook: use a lightweight router to read user questions and instruct Claude to load the corresponding skill files.
- 4Configure the action interception hook: intercept before writing specific content or executing deployments if the matching skill is not loaded; trigger an "Ask Human" prompt before deploying to production.
- 5Configure the post-write validation hook: check for known errors after file writing and have Claude automatically fix them.
- 6Configure the On Stop hook: prompt the user to write missing logs if project files have changed without a recorded log.
- 7Configure the end-of-task write-back: have Claude append dated logs at the end of a task, update the status, and commit and push to the Git repository.
Ideas for Chinese platforms
This Git-based knowledge repository architecture—which separates working rules from project logs—can be adapted for SOP management in content creator matrices or multi-account operations: split platform publishing rules and historical viral hit review logs into separate repositories, using automated scripts to precisely pull rules at task startup and automatically archive data upon completion.
Please refer to the following structure to set up my long-term memory system: 1. Read specific skill files from [my working rules repository path] to guide the current task: [current task type]. 2. Check the README and logs in [project history repository path] to understand the current project status. 3. At the end of the task, automatically append today's progress, decisions, and rationale to the project log, update the final status and TODOs, and commit to Git.
Related use cases
Summarized by AI from the original source - refer to the original post for details. Copyright belongs to the original author.