Why AI Coding Assistants Keep Forgetting You: A Practical Guide to Building a Context Memory System
If you have ever spent ten minutes re-explaining your project, codebase structure, and current progress to an AI coding assistant like Claude Code every time you start a new conversation, this article is for you. It breaks down why large language models are stateless by design, why coding tasks face additional context challenges, and how to solve the problem with a four-layer memory architecture. The article walks through the complete implementation: a file-system-based directory structure, session summary templates, task and progress tracking, decision logs, prompt designs for summary generation, layered context injection, memory maintenance rules, and Git-based version control. It also shares three real-world scenarios showing how persistent memory changes daily workflows, along with a two-week evaluation of results and generalizable best practices that work with any AI coding tool supporting file read/write access.
Why AI Coding Assistants Keep Forgetting You? Let’s Talk About Building a Context Memory System
As a heavy user of AI coding tools (Claude Code), I have always been troubled by the fact that they have no memory.
Every time I start a new conversation, I have to tell it again: who I am, which project I am working on, what the current progress is, and what the codebase structure looks like. Getting the background clear often takes ten minutes. By the time the AI finally “understands” the context and starts outputting useful suggestions, the conversation is nearly over. Open a new one the next day, and everything resets.
Even worse are long-cycle projects. A single feature spans three days, and every time I open a new conversation, the AI acts like it is meeting me for the first time. It does not know which technical approach we discussed yesterday, which design we rejected the day before, or what architecture principles we agreed on last week. All I can do is repeat myself over and over, like a broken record.
So I started thinking: Can I add a memory system to AI coding tools so they can maintain context across sessions?
I referenced some memory architecture design ideas from the industry and spent over two weeks building one for my most-used coding tools. The results were surprisingly good — it can now remember my projects, my decision-making habits, and even my daily progress. Today I want to share the design approach and implementation details of this system.
1. Why Do AI Coding Tools “Have No Memory”?
To solve a problem, you need to understand its root cause first.
Large language models are inherently stateless. Each conversation only processes the context window passed in for that turn. Once the window fills up, old information gets truncated. This is determined by the architecture, not a flaw in any particular product.
For AI coding tools, there are three additional layers of challenges:
- Massive codebase context. A medium-sized project easily exceeds 100,000 lines of code, far beyond any model’s context window. Tools can only selectively feed content to the model via retrieval or summarization.
- Task context is fleeting. You ask the AI to fix a bug, and once it is fixed, the conversation ends. The next time you start a new conversation, it has no idea what you changed.
- Decision context is scattered. Architecture decisions, coding standards, and priority rankings you settle on after discussing with the AI are scattered across individual conversations with no centralized storage.
So, solving the “memory” problem fundamentally means: How to structure and persist information scattered across conversations, then precisely re-inject it into new ones.
2. The Overall Architecture of a Memory System
I designed a four-layer memory system, where each layer has a different responsibility and a different storage medium.
┌─────────────────────────────────────┐│ Memory System Architecture │├─────────────────────────────────────┤│ Layer 4: Decision Memory ││ (Architecture principles, tech ││ stack choices, coding standards) │├─────────────────────────────────────┤│ Layer 3: Progress Memory ││ (Task lists, current status, ││ to-do items) │├─────────────────────────────────────┤│ Layer 2: Session Summary Layer ││ (Structured summary of each ││ conversation) │├─────────────────────────────────────┤│ Layer 1: Raw Context Layer ││ (Full conversation logs, code ││ change logs) │└─────────────────────────────────────┘
Each layer provides summaries downward and details upward. When a new conversation starts, the system injects context from the top layer downward, prioritizing decision memory and current progress over the full conversation history.
Layer 1: Raw Context Layer
This layer stores complete conversation logs and code changes. It is not fed directly to the AI; instead, it serves as the “source of truth” for the summaries and retrievals performed by the upper layers.
For implementation, I used a simple file-system structure:
memory/├── sessions/│ ├── 2024-01-15-session-001.md│ ├── 2024-01-15-session-002.md│ └── ...├── decisions/│ ├── architecture-principles.md│ └── tech-stack-choices.md├── progress/│ ├── current-tasks.md│ └── completed-history.md└── summaries/└── daily-summary-2024-01-15.md
Each session file records the conversation’s time, topic, and key conclusions. This is the lowest-level “log.”
Layer 2: Session Summary Layer
At the end of each conversation, I have the AI automatically generate a structured summary and write it to the summaries/ directory. The summary template is as follows:
# Session Summary - 2024-01-15## TopicRefactor the user authentication module## Key Decisions- Decided to use JWT instead of the session-cookie approach- Unified authentication middleware in the gateway layer## Unfinished Items- [ ] Add expiration logic for refresh tokens- [ ] Write unit tests for the authentication module## Code Changes- Added auth/middleware.go- Modified gateway/routes.go (+120 -45)
This summary gets injected into the context at the start of the next conversation. The AI does not need to read the entire conversation to quickly recover context.
Layer 3: Progress Memory Layer
This layer answers the question, “What should I work on today?”
I maintain a current-tasks.md file with a minimal format:
# Current Task List## In Progress- [ ] Refactor the user authentication module (expected to finish today)- [x] Design the JWT approach- [x] Implement basic middleware- [ ] Add refresh expiration logic- [ ] Unit tests## Not Started- [ ] Performance optimization: reduce home page load time from 3s to under 1s- [ ] Tech debt: decouple payment logic in orderService## Blocked- Waiting for product confirmation on payment flow edge cases
At the end of each conversation, I ask the AI to update this file: check off completed tasks, append new tasks, and annotate blocked tasks with reasons.
The next morning, when I start a new conversation, my first line is simply, “What are we doing today?” The AI reads this file and tells me the progress directly. I do not need to recall what I did yesterday.
Layer 4: Decision Memory Layer
This is the most valuable layer, addressing the problem of “what happens when the direction goes off track.”
I record all principles, standards, and decisions made after discussions with the AI under the decisions/ directory. For example:
# Architecture Principles## P1: Single ResponsibilityEach service handles only one business domain; cross-domain calls go through an event bus.## P2: Tests Before CodeNew features must have tests written first, then the implementation. Urgent hotfixes are exempt but must be followed up with tests.## P3: No Unassessed DependenciesBefore adding a third-party library, you must evaluate its maintenance activity, community size, and license compatibility.## P4: Impact FirstWhen deciding whether to do something, the core criterion is whether it feeds back into your current primary impact path.
The last one, P4, was a principle I settled on with the AI over the weekend. It saved me later.
3. Three Real-World Scenarios: How a Memory System Changes the Workflow
Scenario 1: Task Assistant — It Knows Better Than I Do What to Do Today
In the past, every morning I had to spend 10-15 minutes recalling: Where did I get to yesterday? What is still unfinished? How should I prioritize today?
Now, I open my laptop, start a new conversation, and simply ask: “What are we doing today?”
The AI reads current-tasks.md and tells me:
Yesterday you finished the basic JWT middleware. Two things remain: adding refresh token expiration logic and writing unit tests for the authentication module. Also, the orderService decoupling has not started, but it is not blocking, so you can wrap up what is on your plate first. You should be able to clear all authentication module to-dos today.
I do not need to recall anything — it remembers better than I do. Sometimes I forget that something is still unfinished, and it proactively reminds me.
This logic applies not only to daily work but also to writing code. The AI keeps an eye on the tech debt list and reminds me: “The coupling of payment logic in orderService has been hanging for five days. I suggest handling it this week.”
In the past, I had to spend time every day thinking about “what should I do today.” Now that step is gone entirely.
Scenario 2: Retrospective Review — With Memory, an AI’s Feedback Cuts Deeper
With structured daily summaries, I asked the AI to review my recent work status from its perspective.
It sent me this:
Over the past two weeks, you completed 12 tasks, 8 of which were urgent insertions and only 4 were planned. Your planned task completion rate is 33%. You start an average of 3.2 new conversations per day, indicating frequent task switching. You spent 5 days on “refactoring the authentication module,” but the first 3 days were spent repeatedly revising the approach, with only 2 days of actual coding. Suggestion: reduce the insertion of ad-hoc tasks and leave uninterrupted blocks of time for deep work.
That hit me hard. It seems my execution ability has quite a bit of room for improvement.
Without these records, I would probably still think I was working hard. But the data does not lie — a 33% planned task completion rate is indeed not good.
And I could not even argue back, because it was speaking with my own data.
Scenario 3: Decision Reminder — It Pulls You Back When You Drift Off Course
This was the most striking experience for me.
Last weekend, the AI and I discussed and settled on a decision principle (the P4 mentioned above): When deciding whether to do something, the core criterion is whether it feeds back into your current primary impact path.
This principle was recorded by the AI in decisions/architecture-principles.md.
This week, seeing that everyone was making overseas products, I ran over to the AI excitedly and asked: “Should we work on an overseas product to give it a try?”
It directly rejected me:
According to our architecture principle P4: When deciding whether to do something, the core criterion is whether it feeds back into your current primary impact path. Overseas products have low relevance to your current impact path (developer tools), and it is not recommended to invest effort. If you really want to do it, I suggest discussing how to create synergy with your existing path first.
I was stunned for a moment. I had forgotten that I had even set this rule with it last week.
People are easily led astray by new opportunities. But having a partner with a good memory by your side will pull you back to your original path when you start to drift.
4. Implementation Details and Best Practices for the Memory System
4.1 Prompt Design for Summary Generation
Summary generation at the end of a session is the key to the entire system. The prompt template I use is:
Please generate a structured summary based on the following conversation content, including:1. The topic of this conversation (one sentence)2. Key decisions (list all confirmed decisions, each no more than 50 words)3. Unfinished items (checkbox format)4. Code change overview (file path + change volume)5. Items needing special attention in the next conversationOutput in markdown format, ready to be written directly to a file.
The key is to make the AI distinguish between “ideas under discussion” and “confirmed decisions.” I will explicitly say during the conversation, “This is confirmed, note it down,” and the AI will categorize it under decisions.
4.2 Memory Injection Strategy
At the start of a new conversation, you do not stuff all memory into it at once; instead, inject it in layers:
def build_context(memory_dir):context = []# 1. Inject decision memory (highest priority)for f in glob(f"{memory_dir}/decisions/*.md"):context.append(read_file(f))# 2. Inject current progresscontext.append(read_file(f"{memory_dir}/progress/current-tasks.md"))# 3. Inject session summaries from the last 3 daysrecent = sorted(glob(f"{memory_dir}/summaries/*.md"))[-3:]for f in recent:context.append(read_file(f))return "\n\n---\n\n".join(context)
The context injected this way is typically within 3,000-5,000 tokens, which will not overflow the window while still covering the most critical information.
4.3 Memory Update and Cleanup
Memory is not append-only. I set three rules:
- Weekly cleanup: Completed tasks are moved from
current-tasks.mdtocompleted-history.mdto keep the current file lean. - Decision merging: If a new decision conflicts with an old one, the old decision is marked as “deprecated” with the reason stated, rather than being deleted outright. The evolution history is preserved.
- Summary compression: Session summaries older than 30 days are merged into weekly-level reports to reduce the number of files.
4.4 Integration with Version Control
I put the memory/ directory under Git management, but in a separate repository. The benefits are:
- When switching computers, a single clone restores all memory.
- Memory changes also have a commit history, allowing you to trace “when a particular rule was established.”
- You can write a script to automatically commit once before leaving work each day.
5. Evaluating the Results: What Changed After Two Weeks of Use
After using it for over two weeks, the most tangible changes are:
| Metric | Before Use | After Use |
|---|---|---|
| Daily “context recall” time | 10-15 minutes | <1 minute |
| Planned task completion rate | ~40% (estimated) | ~65% |
| Forgotten tech debt | Frequently missed | Automatically reminded weekly |
| Direction drift incidents | Frequent | Significantly reduced |
But more important than the numbers is the shift in mindset.
In the past, I treated the AI as a tool, using it and leaving. Now it feels more like a partner — one that knows what I am working on, knows my principles, and knows where I tend to make mistakes.
This feeling of “being remembered” has taken collaboration efficiency to a new level.
6. Generalizable Advice: Any AI Coding Tool Can Use This
The core idea of this system does not depend on any specific product and applies to any AI coding tool that supports file read/write:
- External storage: Do not rely on the model’s context window; use the file system for persistence.
- Layered summarization: Raw data -> session summaries -> decision principles, abstracting level by level.
- Proactive injection: At the start of a new conversation, proactively feed memory to the AI rather than waiting for it to ask.
- Regular maintenance: Maintain memory like you maintain code — clean up outdated information and merge duplicate entries.
If you are also troubled by “AI has no memory,” take an afternoon to build a similar system. The upfront investment is modest, but the long-term payoff is significant.
After all, who does not want a partner that understands you better the more you use it?
