[KongchangAI]
· 3 min read· 1,640 words

Claude Code Project Memory Tutorial: Creating, Maintaining, and Verifying CLAUDE.md

Claude Code Project Memory Tutorial: Creating, Maintaining, and Verifying CLAUDE.md

CLAUDE.md is a project-root memory file that lets Claude Code remember coding rules across sessions.

This article explains how to use a CLAUDE.md file in the project root to give Claude Code long-term memory across sessions. Claude Code only keeps the current conversation by default and forgets everything after exit, while CLAUDE.md is read automatically in new sessions. It compares Windows vs WSL environments and notes that Linux reduces command translation. You can create the file with /init, which scans the project and generates English rules, or specify Chinese rules directly in natural language. For maintenance, use # plus space to quickly append rules and /memory selecting project to edit or delete them. Verification requires restarting the session; indentation, file extension, and swapped rule order experiments confirm the rules really work.

Claude Code's conversational memory only exists within the current session and is lost upon exit. To make it remember your coding habits and project rules long-term, you need a CLAUDE.md file in the project root directory. This article is based on a Bilibili tutorial and provides a complete breakdown of how to create, maintain, and verify this memory file.

Why You Need a Project Memory File

By default, Claude Code remembers what you said earlier in each conversation, but once you exit and re-enter, all previous requirements are lost. The tutorial demonstrates this with an intuitive comparison experiment: in the first conversation, it asks the AI to use four-space indentation when generating an HTML file, and the result indeed complies; after exiting Claude Code and re-entering, it asks the AI to generate a similar HTML file, and upon opening it, the indentation has reverted to two spaces—the agreement from the first conversation was not preserved.

This is exactly the problem CLAUDE.md solves. It is an ordinary Markdown text file placed in the project root directory, named CLAUDE.md in all caps, and Claude Code automatically reads it as project guidance in new sessions, saving you from having to re-explain the same set of requirements each time. The tutorial author states the learning goal directly: change the habit of starting to write projects right away and instead first create a memory file in the project root directory.

There are two prerequisites for this section: mastery of the basic Claude Code commands from Chapter 1 (being able to launch Claude Code in the terminal), and having a project directory available for practice.

Ask AI about environment differences

Claude Code is a command-line AI programming assistant launched by Anthropic that interacts with users on a per-terminal-session basis. Each launch is a fresh context window, and the model does not automatically retain any information from the previous session—this is both a design choice for privacy and state isolation and a technical reality of the fact that large model contexts cannot persist across processes. CLAUDE.md is precisely the official "context injection" mechanism: at session initialization, Claude Code prepends the contents of this file from the project root into the system prompt or the beginning of the context, so that the model can "see" these rules in every round of conversation. Similar mechanisms exist in other AI programming tools, such as Cursor's .cursorrules or GitHub Copilot's instruction files, and the core idea is the same: move project-level conventions from volatile conversational memory into a version-controllable text file.

Environment Choice: Windows or WSL

The tutorial author deployed an Ubuntu environment within Windows' WSL subsystem to run Claude Code rather than using it directly under Windows. He explains that this is not mandatory; all operations work on the same principles, and the difference mainly lies in the translation step when the AI executes commands.

Under a native Windows environment (especially PowerShell), path separators, quote escaping, and the like all require a translation/transpilation layer, which is prone to errors at this step; whereas when code is placed in a Linux directory, small file reads/writes and subprocess creation are faster. The AI answer he cites also mentions that modern AI companies mostly deploy large models on Linux systems, where instruction execution is more efficient—which is also why many people switch to Mac. However, the tutorial also emphasizes that if you are developing a native Windows project, it is not recommended to switch to a Linux environment, because that would introduce reverse conversion. Environment choice depends on your development project itself.

WSL (Windows Subsystem for Linux) is a Linux compatibility layer built into Windows 10/11 by Microsoft, allowing users to run distributions such as Ubuntu directly without dual-booting or a virtual machine, while accessing the same file system. For tools like Claude Code that need to frequently execute shell commands, create subprocesses, and read/write large numbers of small files, the value of WSL lies in the fact that it provides native Linux kernel interfaces (implemented through a lightweight virtual machine), uses forward slashes uniformly in paths, and requires no handling of drive letters or backslash escaping, so AI-generated commands can be executed directly with one less translation layer. In contrast, PowerShell's syntax, quoting rules, and path conventions differ from Bash, and Bash commands make up a higher proportion of model training data, making escaping errors more likely under PowerShell. This also explains why the tutorial recommends choosing the environment based on project type rather than blindly pursuing Linux.

Two Ways to Create a Memory File

Method 1: Automatic Generation with Slash Init

Enter /init in Claude Code, and it will scan all files in the current project and automatically generate a CLAUDE.md. The richer the project content, the more detailed the automatically configured rules. In the tutorial demonstration, the author had previously renamed a generated HTML file; the AI determined that the old file no longer existed, so it re-read the renamed file and generated rules based on it—this detail also shows that it is indeed analyzing project content in real time.

The automatically generated rules are in English by default because the model itself is a foreign product. The author opened a translation tool to check, and the content roughly said: this file provides code guidance for using Claude Code in this repository; it identified this as a Chinese standalone static web page project with Simplified Chinese as the language—this judgment came from the lang attribute in the HTML tag. The rules are written around the files the project actually contains and do not make things up.

Slash commands are built-in instructions in Claude Code that start with /, such as /init, /memory, and /help, used to trigger specific functions rather than being ordinary conversation sent to the model. The workflow of /init is roughly: traverse the project directory, read key file contents (such as README, package.json, the lang attribute of HTML, etc.), and then have the model summarize and generate a CLAUDE.md describing the project structure, language, tech stack, and coding conventions. Because the generation process relies on the model reading files in real time, if you run /init again after files are added, removed, or renamed, the output will change accordingly—the phenomenon in the tutorial where the rules updated after renaming the HTML file stems from this. Note that automatically generated content tends to be descriptive and may not cover your personal coding preferences, so manual supplementation is usually still needed.

Method 2: Specify Rules in Natural Language

Since only one CLAUDE.md is allowed in the root directory, you need to first delete the automatically generated one, then tell the AI in natural language what rules you want. The three rules given in the tutorial example are: always answer in Chinese, use four-space code indentation, and this is a practice project for learning. The resulting rules file will then be in Chinese and will not automatically analyze project files—it follows exactly what you specify.

It's better to make a distinction

Adding, Modifying, and Deleting Rules

Adding: Hash Plus Space

Type # plus a space in the dialog box, followed by the new rule, and Claude Code will append it to CLAUDE.md. The tutorial appends two rules in sequence: always use TypeScript instead of JavaScript, and use single quotes uniformly for strings. When appending, you can open the rules file and see the changes in real time.

Modifying and Deleting: Slash Memory

Enter /memory, select the option containing "project," and Claude Code will automatically open the CLAUDE.md file for you to edit—when integrated with VS Code it opens directly in the editor; on Apple computers it may open TextEdit, and on Windows it may open Notepad. Once open, you can directly change a rule or delete one, for example changing the TypeScript rule to JavaScript, or deleting it entirely.

Automatically open the rules file

Verifying Whether the Rules Actually Take Effect

There is a key prerequisite for verification: you must exit Claude Code and re-enter. This is because the conversation's own memory function interferes with judgment; only the behavior after a restart can show whether the rules file has been read.

The tutorial's verification steps are divided into three layers:

  1. Verify the indentation rule: Ask the AI to create a simple HTML file that only outputs hello world, then open it and check the indentation. In the lower right corner of VS Code, you can directly see the number of spaces in the current file; in the tutorial demonstration it shows four spaces, so the rule is in effect. The author also reminds that once you are familiar with it, you do not need to manually type spaces every time to verify—just look at the value in the lower right corner of the editor.
  2. Verify the language rule: Deliberately do not specify a file type, and only ask the AI to create a function named add. If the rule is in effect, it should produce a .js file. The result was indeed the creation of add.js.
  3. Verify the real-time nature of the rules: Swap the order of TypeScript and JavaScript in the rules, then ask the AI to create a multiplication function. This time the generated extension became .ts, showing that modifications to the rules file take effect in real time after a restart.

Practical Takeaways

  • CLAUDE.md is placed in the project root directory, named in all caps, in Markdown format;
  • /init is suitable for projects that already have some files, and the automatic output tends to be in English; the natural language method is suitable for customizing Chinese rules from scratch;
  • Use # plus space for quick appending, and /memory then select project to edit;
  • All verification must be done after restarting the session; otherwise the conclusions are unreliable.

Verification process screenshot

#Claude Code#CLAUDE.md#project memory#AI coding assistant#WSL#/init command#/memory command#coding rules
Share:

Related articles