Setting up a project in Claude Code: CLAUDE.md, memory and turning every mistake into a rule

•0•0Comment iconComment iconComment iconComment icon

How to organize your project folder, write persistent instructions in CLAUDE.md, use memory and craft effective prompts—and how every corrected mistake becomes a written rule, with a date and a reason

Writer image

Translated byEditorial

Edit Article

At https://lecursos.com/pt-br/articles/como-funciona-um-modelo-de-linguagem-tokens-contexto-alucinacao-e-o-custo-de-conversar you saw that a language model remembers nothing from one session to the next: it sees only what is in the context window, its “workbench.” You also saw that when the workbench fills up, the conversation is summarized and details are lost. The conclusion was a habit: anything that needs to last cannot live only in the conversation.

In this lesson, we will build the place where things last: the project. You will learn how to organize the folder, write CLAUDE.md (the permanent instructions the agent reads in every session), use memory, make clear requests and, most importantly, turn every corrected mistake into a written rule, with a date and a reason. At the end, you will be introduced to git, the project’s history. This is where AI stops being an assistant that forgets and becomes an intern that learns.

1. The project folder

1.1 One project, one folder

In https://lecursos.com/pt-br/articles/o-que-e-ia-e-o-que-nao-e-do-chat-ao-agente-e-por-que-usar-so-o-claude-code you created the “ia-gestao” folder and opened Claude Code inside it. That is not a technical detail. The folder defines what the agent can see and where it works: it reads and writes files there, runs programs there and, when you open the agent in the same folder again, it finds everything as it left it.

Think of the folder as a department’s room in a company. Each department has its own files, procedures and rules. Mixing everything in one room creates confusion; separating things too much, with every document in its own room, does too. The practical rule is: one piece of work with one goal, one folder.

1.2 What belongs in the folder

In a well-organized project, the folder contains four types of things:

Instructions. CLAUDE.md, explaining what the project is and what the rules are. It is the procedures manual.

Data. Spreadsheets, PDFs, photos and downloaded series. This is the raw material.

Code. Programs the agent has written that repeat the task without spending tokens, as we saw in https://lecursos.com/pt-br/articles/como-funciona-um-modelo-de-linguagem-tokens-contexto-alucinacao-e-o-custo-de-conversar.

Outputs. Reports, charts, presentations and videos. This is the finished product.

My Le Cursos channel project follows this structure. There is one folder for lesson slides, one for video editing, one for branding and one for social media campaigns. Each has its own programs. At the root, there is a CLAUDE.md explaining all of this, so that any new agent session (or any person) understands where everything is.

2. CLAUDE.md: the manual the agent reads every time

2.1 What it is

CLAUDE.md is a text file at the root of the project. Claude Code reads it at the beginning of every session, before your first request. Everything in it is automatically added to the agent’s workbench. That is why it is where instructions that always apply belong.

You already created one in https://lecursos.com/pt-br/articles/o-que-e-ia-e-o-que-nao-e-do-chat-ao-agente-e-por-que-usar-so-o-claude-code, using the /init command: the agent examines the folder and writes a first draft. That draft is a starting point. A good CLAUDE.md is built gradually through experience.

2.2 What to write

A useful CLAUDE.md answers three questions.

What is this project? In a few lines: its goal, who it is for and where things are located. Mine begins by saying that the project is for content, not the website’s code, and lists the folders and what each one contains.

How is it done? The commands used to run the work. For example, how to generate a slide deck or check a video before rendering it. That way, the agent does not have to rediscover the process every time (and you do not pay tokens for that rediscovery).

What are the rules? Decisions that have already been made and should not be revisited. And here is the detail that makes the difference: every rule needs a date and a reason. Two real lines from Le Cursos’ CLAUDE.md:

“Always check audio sync (Leon’s request, 22/11/2026): OBS recorded the camera 0,43 s behind on O03.”

“Since 17/11/2026 the bot does NOT respond to comments anymore (Leon’s request) [...] Do not turn it back on.”

The date says when the rule took effect. The reason explains why it exists, making it possible to assess cases the rule did not anticipate. A rule without a reason becomes superstition: no one knows whether it still applies, so no one has the confidence either to change it or to follow it intelligently.

2.3 What not to write

Passwords, access tokens or personal data. CLAUDE.md goes into the project history and may be shared. Credentials do not belong in an instruction file (we will return to this in https://lecursos.com/pt-br/articles/riscos-e-governanca-da-ia-lgpd-permissoes-do-agente-e-regulacao).

The obvious. “Be polite” and “do a good job” change nothing and take up space on the workbench.

Novels. The file is read in every session, so every line costs tokens every time. Keep it short, use bullet points and point to other files when the subject is lengthy (“the video step-by-step guide is in video/README.md”).

Which of these lines is the best rule for a CLAUDE.md?

Loading icon

Answer: “Reports in thousands of reais, with one decimal place (requested by management on 10/03...)” It is concrete, verifiable, and has a date and a reason. The first is vague, the third is a security risk and the fourth asks the agent to do something it cannot do: the conversation does not last.

3. Memory

3.1 What it is

In addition to CLAUDE.md, Claude Code has memory: notes the agent keeps between sessions about you and the work, such as preferences, corrections and decisions. You can explicitly ask it to save something (“make a note of this”), or the agent may suggest saving something it has learned.

In my own use, each memory follows a format: the rule, the reason (the “why”) and how to apply it. Across all my projects, there are about 124 memory files in 26 projects (including indexes). They were not written all at once: they emerged one correction at a time over the course of months.

3.2 CLAUDE.md or memory?

The practical difference is scope. CLAUDE.md belongs to the project: it stays in the folder, goes into the history and applies to anyone working there. Memory belongs to the relationship between you and the agent: style preferences, ways of working and things that apply to you.

A rule that defines the product (“only 1 or 2 Shorts per video”) should be written in the project, where everyone can see it. A personal preference (“answer me in short bullet points”) can stay in memory. When in doubt, prefer CLAUDE.md: it is more visible and easier to audit.

3.3 Recording even what is unknown

One detail I consider good management practice is that my memories also record what is missing. When I turned off the bot that responded to YouTube comments, the memory recorded the decision and added, word for word, that the reason had not been asked. In another case, involving a cough detector in videos, it stated that the threshold “has not yet been validated on a real cough.”

This may seem minor, but it prevents a serious problem: someone (or the agent itself) later inventing a plausible explanation for a decision. Remember https://lecursos.com/pt-br/articles/como-funciona-um-modelo-de-linguagem-tokens-contexto-alucinacao-e-o-custo-de-conversar: the model fills gaps with the most likely text. Writing “I don’t know” is protection against hallucination.

4. Making clear requests: AI as an intern that learns

4.1 The four parts of a good request

Imagine that you hired a very fast intern who has read a lot but started today and does not know the company. How would you delegate a task to them? A request to the agent follows the same logic and has four parts:

Context. What the work is for and who it is for. “This report is for the sales management team, which reads it on a phone before Monday’s meeting.”

Example. A model of what good looks like. “Follow the format of the October report, which is in relatorios/2026-10.pdf.”

Format. What the deliverable should look like. “One page, three numbers at the top, one chart and no more than five bullet points.”

Definition of done. How you will know it is finished. “It is ready when the totals match the finance spreadsheet and the file opens on a phone.”

Compare “write a sales report” with the request containing all four parts. The first forces the agent to guess, and a language model guesses with the most likely text, which is a generic report. The second leaves little room for guesswork.

4.2 When in doubt, ask about scope

A case from my own work on 23/11/2026 shows the other side of making a request. In a related project, the Cards Realm channel, there was a “no politics” instruction that applied to comment responses. The agent applied it where it should not have: it cut 13,5 minutes from a video because the segment discussed politics. The owner’s response was blunt: “the video is the video, period.”

The mistake was not solely the agent’s. An ambiguous request (“no politics” where?) leaves room for interpretation. The rule that emerged applies to both sides: when unsure about the scope of a request, the agent asks before acting. And when you make a request, say where it applies.

You ask the agent to “improve the report.” Which part of a good request is most seriously missing?

Loading icon

Answer: the definition of done: what “better” means and how to know it is finished. Without it, the agent decides for itself what improvement means, and you only find out at the end whether you agreed. Context and format are also missing, but the definition of done is what makes the result checkable.

5. Every mistake becomes a rule

5.1 The anatomy of a rule born from a mistake

This is the heart of the course. Every time the agent makes a mistake and you correct it, there are two possible outcomes. The lazy one is to make the correction and move on: the mistake returns next week because the correction lived only in the conversation. The management approach is to turn the correction into a procedure: what happened, the rule, the date, the reason and where it was written down.

Some real examples from my projects, all recorded this way:

“Always check audio sync” (22/11/2026). An opinion video, O03, was released with the camera 0,43 seconds behind the voice, and I only noticed it in the finished video. That same day, a program was created to measure the sync of every recording, a line was added to CLAUDE.md and a mandatory step was introduced before editing. The rule was copied to the Cards Realm related project.

Remove breathing sounds (9/11/2026). The sound of breathing near the microphone was distracting. I said, “make a note of this and always remove that audio.” It became the editing program’s default. The rule continued to be enforced: in a later Cards Realm video, the measurement showed that 168 of 217 breaths had still slipped through, and the detector was rebuilt.

“Always test it first” (26/10/2026). The comment bot publicly posted, in my name, a spreadsheet formula that had not been tested. The rule: any formula or calculation used in a public response must be tested first.

Only 1 or 2 Shorts per video (17/11/2026). Before that, there had been 3 or 4 vertical clips. I asked for only the best moments: “from now on, generate only 1-2 shorts per video.”

“Never label egg cartons” (20/08/2026). In Conta Ovos, when Claude marked eggs in photos, 32% of the cartons were false positives and 38% of the eggs were missed. The rule: AI measures, a human decides what counts as an egg.

“Do not git push without the owner’s request” (15/09/2026). On the Cards Realm website, sending the code to the server publishes the site immediately. After deployments were made without a request, it was written down that publishing is the owner’s decision.

Notice the pattern: a short sentence, a date and a concrete reason. Anyone who opens the project understands the rule and can judge whether it still makes sense.

5.2 Public feedback also becomes code

The rules do not come just from me. On the Cards Realm channel, which uses the same editing process as my videos, one viewer said it was "crazy how the editing keeps moving" the presenter around the frame. Others described the editing as frantic. Measurements showed a shot change roughly every 11 seconds.

The lesson was recorded in an editing lessons file, then turned into code: a pacing mode called ritmo="calmo", with shot changes every 25 to 40 seconds. When a lesson becomes code, its entry gets the marker [applied: where], identifying where in the program it was implemented. That makes it auditable: a lesson recorded but not implemented is still pending; an implemented lesson has a location you can check.

5.3 A written rule is not an automatic safeguard

One important caveat: CLAUDE.md is a request to the agent, and the agent may fail to follow it. For genuinely dangerous actions, there is another layer: Claude Code permissions, configured in a settings file, that automatically block certain commands. One phrase from my daily review sums up the idea: "a prompt is a request; deny is a locked door". We will cover this in https://lecursos.com/pt-br/articles/agentes-e-automacao-com-humano-no-circuito-a-ronda-diaria-e-o-robo-que-foi-desligado and https://lecursos.com/pt-br/articles/riscos-e-governanca-da-ia-lgpd-permissoes-do-agente-e-regulacao.

A viewer complains that the editing is frantic, so you adjust the program and record the lesson. What does the [applied: where] marker add?

Loading icon

Answer: it identifies where in the code the lesson became a rule, making it auditable. A lesson without the marker is still pending; one with the marker has a location you can check. It does not guarantee that mistakes will never happen: it simply makes the changes visible.

6. Git: the project's history

6.1 A commit is a snapshot of the project

git is a program that tracks a folder's history. Whenever you make a commit, it takes a "snapshot" of all the files at that moment, with a date and a message explaining what changed. You can then compare two snapshots, return to an earlier version and find out when a rule was added to CLAUDE.md.

For a manager, git answers the audit questions: what changed? When? Why? Who requested it? In an AI project, where the agent edits many files, this matters even more. If an agent's change breaks something, you can go back to the previous snapshot.

You do not need to memorize commands. Ask the agent: "initialize git in this folder", "commit today's changes with a message explaining what was done", "show what has changed since the last commit".

6.2 The agent commits only when you ask

In Claude Code, the default practice is for the agent not to make commits on its own: it commits when you ask. This is deliberate. A commit is the point at which you say, "I approve this version". If the agent committed every change automatically, the history would record what it did, not what you approved.

Sending that history to a server, known as a push, is even more sensitive, because in many projects it publishes the work. Remember the rule for the Cards Realm website: push only when the owner asks.

6.3 An honest caveat

In https://lecursos.com/pt-br/articles/o-que-e-ia-e-o-que-nao-e-do-chat-ao-agente-e-por-que-usar-so-o-claude-code, I promised not to pretend that this happens automatically. My Le Cursos project has just 6 commits, all from October 2026. Since the last one, 172 files have been modified or added without a single snapshot. The work is recorded in the files, in CLAUDE.md and in memory, but the formal history is out of date because I did not request the commits.

There is another discrepancy: the video editing manual still says "3 or 4 vertical cuts", although the rule changed to 1 or 2 on 17/11/2026. The new rule is in CLAUDE.md and in memory; the manual has not caught up.

The lesson is about management, not technology: the tool makes recordkeeping easier, but keeping records up to date takes a routine, just like reconciling the cash accounts. A good practice is to end each working day by asking the agent: "update the documentation with today's changes and make a commit".

Why is it good practice for the agent to commit only when you ask?

Loading icon

Answer: because a commit marks a version you have approved, not just something the agent has done. The agent knows how to use git very well; the question is who decides what goes into the history. Commits do not delete anything: they save snapshots.

7. Common mistakes

"The agent will remember; I told it yesterday." It does not remember yesterday's conversation. If an instruction needs to last, it belongs in CLAUDE.md or in memory.

"The more I put in CLAUDE.md, the better." The file is loaded into every session. Vague rules and long passages consume tokens and dilute what matters. Keep it brief and refer to other files.

"A rule is a rule; it does not need a reason." Without a reason, no one knows whether the rule still applies or how to use it in a new situation. A date and a reason turn a rule into an auditable decision.

"With git, the project documents itself." Git saves what you tell it to save. My project, with 172 uncommitted changes, shows that without a routine, the history falls behind.

8. Putting it all together

The project is the folder. Instructions, data, code and outputs all in one place, so every new agent session, and every person, can pick up where things left off.

CLAUDE.md is the procedures manual, read at the start of every session: what the project is, how the work is done and what the rules are, each with a date and a reason.

Memory stores what belongs to your working relationship with the agent, as well as what is not known, so no one makes it up later.

A good request is good delegation: context, an example, a format and a definition of done. When the scope is unclear, ask.

Every mistake becomes a rule, and git stores the approved versions. The tool makes it easier; the discipline of keeping the record up to date is yours.

In the next lesson, we put the project to work with real data: researching and analyzing public data, with sources and consistent criterialink outside website.

Claude Code activity (20 minutes)

1. Open Claude Code in the "ia-gestao" folder and ask: "Read the current CLAUDE.md and rewrite it with three sections: what this project is (my project for the course on AI applied to management), how the work is done (the commands and programs we already have) and rules (each with a date and a reason). Show me before saving."

2. Read the proposed version and check: is it brief? Does every rule have a date and a reason? Ask for adjustments until you agree with it.

3. Deliberately provoke a mistake. Ask: "Write a paragraph introducing this project to a colleague." The tone or length will almost certainly not be what you wanted. Correct it in the conversation ("shorter, no adjectives, in the third person").

4. Now turn the correction into a rule. Ask: "Add a rule to CLAUDE.md based on the correction I just made, with today's date and the reason." Check the line it writes.

5. Close the agent, reopen it in the same folder and repeat the request from step 3. Did the rule work?

6. Ask: "Initialize git in this folder and make the first commit with everything we have, with a message explaining what the project is." Before approving, read what it plans to run. Then ask: "show the commit history".

Class discussion exercise

Think of a procedure at your company or internship that exists because "we have always done it this way", without anyone knowing exactly why. Discuss: (a) what would this procedure look like as a CLAUDE.md rule, with a date and a reason? (b) If no one knows the reason, what would be the most honest thing to write? (c) Who should have the authority to change this rule, and how would the change be recorded?

Exercises

1) A project's CLAUDE.md file in Claude Code:

A) is read only when the user types its name.

B) stores the project's passwords securely.

C) is read at the start of every session and stores the project's standing instructions.

D) replaces git as the version history.

E) can be written only by the agent, never by the user.

2) Which of the following is the best example of a well-written request to the agent?

A) "Create a 5-slide presentation for Thursday's meeting with the regional managers, using the September presentation in the folder as the template, with one figure per slide; it is ready when all the figures match the sales spreadsheet."

B) "Make a good presentation."

C) "Do it like last time."

D) "Do your best; this is important."

E) "Be creative, with no limits."

3) The rule "Always check audio sync" in the Le Cursos project was introduced because:

A) the audience asked for longer videos.

B) the agent accidentally deleted a recording.

C) the channel changed its name.

D) the comment bot gave an incorrect reply.

E) a video had the camera footage lagging 0,43 seconds behind the voice, and the problem was noticed only in the finished video.

4) At Cards Realm, a request for "no politics" that applied to comment replies resulted in 13,5 minutes being cut from a video. The rule introduced after this incident was:

A) never discuss politics in videos.

B) when the scope of a request is unclear, ask before acting.

C) shut down the agent permanently.

D) always cut long sections.

E) ban comments on the channel.

5) (True or false) "If a rule is written in CLAUDE.md, it is impossible for the agent to fail to follow it, so there is no need to configure permissions to block dangerous commands."

( ) True ( ) False

6) (True or false) "A commit is a snapshot of the project at a particular moment, with a date and a message; the recommended practice is for the agent to commit when the user asks, so that the history records approved versions."

( ) True ( ) False

Answer key

1) C — CLAUDE.md is loaded into the agent's workspace in every session. Passwords do not belong there, it does not replace git, and you can (and should) edit it.

2) A — It provides context (a meeting with regional managers), an example (the September presentation), a format (5 slides, one figure per slide) and a definition of done (matching the spreadsheet).

3) E — In O03, OBS recorded the camera footage with a 0,43 s delay; that same day, a program to measure sync was created, a rule was added to CLAUDE.md and a mandatory pre-editing check was introduced.

4) B — The mistake came from an ambiguous scope. The response was "the video is the video, end of story", and the rule requires the agent to ask about the scope of a request whenever it is unclear.

5) False — CLAUDE.md is a request, and the agent can fail. For dangerous actions, permissions provide an automatic block: "a prompt is a request; deny is a locked door".

6) True — A commit marks a version; when the user requests it, the history records what was approved, not just what the agent did.

What did you think of this article?

0%
User score (0)

Share this article!