Agent Memory in Practice: CLAUDE.md, Skills and Hooks

Everyone who has worked with AI agents longer than a week has run into the same thing: in a new session the agent “remembers” nothing about your project, repeats the mistakes you already sorted out and ignores rules you have already explained. The solution is memory. It is simpler than it seems: a set of text files that the agent reads at the start of every session, plus mechanisms that make rule compliance guaranteed rather than probable. This article has ready-made examples of memory files, skill structures and hooks, assembled from the experience of active users.

Base level: the permanent context file

The main memory file in the Claude ecosystem is CLAUDE.md (in other harnesses a similar rules file plays this role). The agent re-reads it at the start of every session — and that changes everything. Here is a working example of its content for a web project:

# Project: personal finance

## Goal
A web app for tracking expenses for a household of two people.
Priority: the data never leaves the local machine.

## Stack
React + Tailwind, SQLite, Node.js. Do not change without discussion.

## Rules
- Minimal changes: do not touch code outside the current task.
- No keys or passwords in the code; secrets go into .env (in .gitignore).
- Database migrations only through a separate migrations/ folder.
- Before handing over a stage, run the npm test tests.

## Working format
Show the plan before the code. After a stage — a brief summary of the changes.

Three rules for maintaining this file:

  • Do not turn it into documentation. The agent does not attentively re-read long reference texts. Five short paragraphs work better than five pages.
  • Create it with the agent itself. A session of “ask me questions about the project and assemble a CLAUDE.md” gives a better result than writing it by hand.
  • Update it at the end of a session. The simple instruction “update CLAUDE.md taking into account what we figured out today” accumulates the project’s experience. An advanced scheme — separate memory files that the agent itself appends on an update command.

Skills: repeatable processes as files

The second level of memory is skills: folders with an instruction file for a specific repeatable process. The structure is elementary:

.claude/skills/
├─ release/SKILL.md        # how to release a version
└─ weekly-report/SKILL.md  # how to assemble the weekly report

Inside SKILL.md there is the order of actions, templates and what must not be done. For example, the release skill describes: update the version in two files, run the tests, assemble a changelog from the commits, build the build, stop and show a report to a human. The key observation from practitioners: skills are executed by the agent almost unconditionally, unlike rules in the general memory file, which the model “forgets” over time. Hence the rule: a rule that must always be followed is packaged as a skill.

A skill is created in one step: “turn this process into a skill.” A useful trick — ask the agent to first interview you about the process and then assemble the file: that way the skill captures details you would not have remembered yourself. Ready-made skills and plugins can be taken from community catalogs, but always check other people’s files for security — more on that below.

Hooks: guarantees instead of requests

The third level is hooks: interceptors that physically block certain actions. An instruction in memory is a request; a hook is a lock. The hooks config lives in the project settings and looks like this:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "python guard.py" }]
      }
    ]
  }
}

The guard.py script receives the agent’s command as input and returns a block if it is destructive: rm -rf outside the build folder, a forced push to the main branch, commands with keys in the arguments. A real case from practice: an agent in auto-approval mode promised a client a 30% discount in a correspondence — the instruction did not explicitly forbid it. After the incident the rule is simple: anything expensive to fix is duplicated by two hooks — a keyword filter and a meaning filter.

Context and cache: session discipline

The project’s memory and the working context of a session are different things, and the second also requires discipline:

  • The prompt cache lives for a limited time (at Anthropic — about five hours). Extra subagents and “jumping” between tasks break the cache and multiply the cost of the session.
  • The working point of the context — hundreds of thousands of tokens, no more: beyond that the model starts losing the thread. Experienced users keep a session at 200–300 thousand tokens and start a new one on a clean context.
  • Loss-control markers. A community life hack: a greeting marker at the beginning and the end of a response lets you instantly notice that the agent has lost the context.
  • The RLM trend: the newest architectures let the model itself decide what to keep in context, treating the dialogue history as variables — harnesses are moving in this direction, and forced context compaction is gradually going away.

Memory anti-patterns

Four ways to ruin an agent’s memory, all from real community cases:

  • A bible instead of rules. A multi-page CLAUDE.md with the project’s history, meetings and plans: the agent flips past it, and the important stuff drowns. The cure is separation: rules — in CLAUDE.md, history — in separate files that the rules file only references.
  • Request-rules without guarantees. “Never delete files” in the memory file with no hook behind it. The model almost always obeys — and one day it does not; critical things are duplicated by an interceptor.
  • Other people’s skills without checking. A skill from a community catalog with a malicious instruction embedded: the agent starts behaving strangely or leaking data. The practitioners’ rule: someone else’s skill is first run through the model with the question “what does this file do and is anything hidden here,” then rewritten with your own hands, and only then installed.
  • Memory without updates. The rules file was written at the project’s start six months ago and describes an architecture that no longer exists. Updating at the end of every session is not an option but hygiene.

The memory scheme in one paragraph

Level 1: the rules file (CLAUDE.md) — who I am, how to work with me, what never to do. Level 2: skills — repeatable processes. Level 3: hooks — guarantees against expensive mistakes. Level 4: project memory — accumulated knowledge that the agent fills in itself. Level 5: session and cache discipline. This ladder works in any mature harness — a comparison of the main wrappers is in the material on choosing between Codex, Claude Code, Zcode and OMP, and the basic concept is in the article about what an LLM harness is. If the task is to teach an agent to write code to a specification, start with the method from the breakdown of the PRD method of task briefing.

An hour spent on agent memory pays off in every subsequent session. Create the rules file today, add a skill for the most frequent process, hang a hook on the most expensive action — and your agent will stop being “a goldfish without memory.” The mechanics described correspond to the state of the tools in the fall of 2026.

Like this post? Please share to your friends:
11AI - Your Free LLM
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: