Does Claude Code remember between sessions?
Partly. Every Claude Code session starts with a fresh context window, so a new session doesn’t start with your earlier conversations. Two things carry over by default: CLAUDE.md files, instructions you write that load at the start of every session, and auto memory, short notes Claude writes for itself in a folder on your machine. To pick up an earlier conversation itself, resume it with claude --continue or claude --resume.
If you keep re-explaining your project, write a CLAUDE.md and leave auto memory on. If you keep re-explaining yourself in every new repo, put it in ~/.claude/CLAUDE.md: carrying your preferences into every project goes layer by layer. If you’re looking for an old conversation, finding and keeping past sessions covers where they’re stored, how to keep them past 30 days, and a script that searches them by what was said. If Claude lost a rule or the task after compaction, what compaction keeps has the list, a test and a hook. If you want Claude to remember you and your work together, across sessions and projects, add Counterparts, the memory we make.
This is a research summary of Anthropic’s documentation, read on 31 October and 2 November 2026 and checked again on 18 November, when the section on past sessions was added; the docs on compaction, hooks and memory were read again on 21 November, when the section on compaction was added. An AI drafted this page from the sources below and another AI checked it. No person has run these steps. An AI ran the two plugin install commands in an empty test folder on 31 October; on 2 November it ran counterparts scope . --off and the rules symlink in a test folder; on 18 and 19 November it ran the session search script on made-up transcripts; on 21 November it checked the compaction hooks’ settings and ran their commands on made-up input, outside Claude Code. The npm install and the rest the AIs only read. Counterparts is ours: Mike LaPeter makes it.
How to keep Claude Code’s memory across sessions
Built in, that’s CLAUDE.md and auto memory, plus resume for one whole conversation. For a memory of you across sessions and projects, add Counterparts.
Write down what Claude should always know, in CLAUDE.md. Run
/initin your project to draft one. Put your own preferences for every project in~/.claude/CLAUDE.md. Both load at the start of every session on your machine; an edit made mid-session arrives at the next/clear,/compactor restart.Leave auto memory on, and tell it what to keep. It’s on by default in local sessions. Say “remember that the API tests need a local Redis” and Claude saves a note for that repository.
/memoryopens the notes’ folder and turns auto memory on or off.Resume when you want the conversation itself.
claude --continuereopens the most recent conversation in the folder, andclaude --resumelets you choose one. Sessions are deleted after 30 days by default: finding and keeping past sessions has how to keep them longer and find an old one.For a memory of you that carries across sessions and projects, add Counterparts, the memory we make. It’s an MCP server of memory tools plus hooks: at the end of a session Claude writes down what it learned, in its own words, and after the first few sessions, each one opens with where you left off. It runs beside CLAUDE.md and auto memory and doesn’t change either. With Node 22.15 or newer, run
npm install -g counterparts@latestin a terminal, thencounterparts, which asks your name and connects Claude Code, and restart Claude Code (the Quickstart helps if the command isn’t found). It’s free, with its source on GitHub and no API key. More on it below; for other memory MCP servers, see how to set one up.
The ladder: CLAUDE.md, auto memory, Counterparts
Each rung carries something the one below doesn’t.
CLAUDE.md, for what you’d otherwise re-explain. Build commands, conventions, “always do X” rules. Anthropic’s test: add a line when Claude makes the same mistake a second time, or you type a correction you typed last session.
/initdrafts one. A committed CLAUDE.md is the place for rules your whole team shares through git, and for instructions Claude must read word for word every session.Auto memory, for what Claude picks up in one project. It’s already on in local sessions, and holds your preferences, your corrections and decisions the code doesn’t show, for that repository. Say “remember that ...” when you want a note kept.
Counterparts, for Claude’s own memory of you, across every project. The memory we make. One memory reaches every folder. Each session opens with where you left off, in a briefing Claude wrote itself. Related memories come up as you talk. Memories fade unless they come up again, so what Claude knows about you stays current instead of going stale. How to add it.
Two needs aren’t rungs. For something that must happen every time, like a check before each commit, Anthropic points to hooks, since memory is context Claude tries to follow. To carry on yesterday’s conversation, resume it.
What Claude Code remembers out of the box
Claude Code has two kinds of memory, and both are plain markdown files on your machine. “On your machine” describes the store: whatever a session reads goes to Anthropic or the cloud provider you set.
1. CLAUDE.md: instructions you write
Claude reads a CLAUDE.md at the start of every session. You can put one in four places:
| Scope | Where | Who gets it |
|---|---|---|
| Organization |
| Everyone on that machine |
| You |
| Just you, in every project |
| Project |
| Your team, through git |
| You, in this project |
| Just you, in this project |
Claude Code loads every CLAUDE.md from the folder you start in and every folder above it. A CLAUDE.md in a subfolder loads once Claude reads, writes or edits a file there, which includes viewing one with
catorheadin the shell.Your project-root CLAUDE.md and
~/.claude/CLAUDE.mdare read once, at session start. If you edit one during a session, Claude keeps the old version until the next/clear,/compactor restart.A CLAUDE.md can pull in other files with
@path/to/fileimports. Imported files load together with the CLAUDE.md that imports them, so they help you organize but don’t save space.For bigger projects, files in
.claude/rules/can be scoped to paths likesrc/api/**/*.ts, so they load only when Claude works on matching files. A multi-step procedure belongs in a skill, which loads when needed.Run
/initand Claude writes a starting CLAUDE.md from your codebase, or suggests improvements if you have one. Anthropic suggests keeping each file under 200 lines: longer files use more context and reduce adherence./doctor prompt-audit(v2.1.283 or later) reports outdated or conflicting instructions and changes nothing until you ask.If your repository has an
AGENTS.mdand no CLAUDE.md orCLAUDE.local.mdin your folder or above it, Claude Code v2.1.277 and later read the AGENTS.md instead. Adding aCLAUDE.local.mdstops that, unless you change the Project instructions setting in/config.
2. Auto memory: notes Claude writes for itself
Auto memory is on by default in local sessions. As it works, Claude decides what would be useful next time and saves it as a short note. There are four kinds: who you are and how you like to work, corrections you gave it and approaches you confirmed, ongoing project work and decisions it can’t see in the code, and where to find things outside the project (an issue tracker, a dashboard). It skips anything it can derive from the code, “such as architecture, file paths, or debugging fixes”, and anything your CLAUDE.md already says.
The notes live in
~/.claude/projects/<project>/memory/: aMEMORY.mdindex plus one file per note. All worktrees and subfolders of a git repository share one folder.At the start of every session Claude Code loads the first 200 lines or 25KB of MEMORY.md, whichever comes first. The notes themselves aren’t loaded; Claude opens them when it needs them.
When you see “Saved 2 memories” or “Recalled 2 memories”, that’s this folder being written or read.
One r/ClaudeCode user opened the folder after six months on one project and found 65 notes, 28 of them the feedback kind: “The feedback ones do almost all the work.” Their warning: “Memories go stale and stay confident.” That’s one person’s report, read from an archived copy, and we haven’t checked it.
What loads when a session starts
Before you type, Claude Code loads your CLAUDE.md files in a set order, broadest first: the organization’s, then ~/.claude/CLAUDE.md, then each folder’s CLAUDE.md and CLAUDE.local.md, from the top folder down to the one you started in. Rules files without a paths field load at launch too, ~/.claude/rules/ for every project and a project’s .claude/rules/ with the same priority as its .claude/CLAUDE.md. They’re added together, so the most specific is read last. The first 200 lines or 25KB of MEMORY.md load at the start too, and so does any text a plugin’s start-of-session hook adds: with Counterparts, the short briefing Claude wrote itself. The docs give the order within CLAUDE.md files, not between these three. As Claude works, subfolder CLAUDE.md files and path-scoped rules load with matching files, and Counterparts brings up related memories as you talk.
/memory: see and edit all of it
Type /memory in a session to list your CLAUDE.md files, open any of them in your editor, open the auto memory folder, or switch auto memory on or off. Everything is plain markdown you can read, edit or delete.
To check what loaded at launch, run /context and look under Memory files. The FAQ has the rest.
Resuming a conversation
Claude Code saves conversations as you go, so you can come back to one. claude --continue reopens the most recent conversation in the current folder; claude --resume opens a list to pick from; /resume switches conversations from inside a session. A resumed session gets back the messages, tool calls and results. If the conversation was compacted, it picks up from the last summary and what came after; the messages that summary replaced aren’t loaded again.
On Pro, Max and Ultra plans, resuming a long conversation after a long break can bring up a “Resume this conversation?” dialog estimating the share of your 5-hour limit it would use. If you start a new conversation there and the option says Claude can look up the old one, you can still refer to earlier work.
The conversations are saved as files in ~/.claude/projects/ and deleted after 30 days by default, without a message. Finding and keeping past sessions, below, covers where they live, how to keep them longer and how to search them.
What survives /compact
When a long session fills up, Claude Code summarizes the conversation. Your project-root CLAUDE.md and auto memory come back from disk; something you said only in the chat may not. What compaction keeps, below, has the full list, a test you can run and a hook example.
CLAUDE.md vs auto memory
CLAUDE.md is what you tell Claude; auto memory is what Claude tells itself. Anthropic’s comparison comes down to this:
| Question | CLAUDE.md | Auto memory |
|---|---|---|
| Who writes it | You | Claude |
| Scope | Organization, you, or a project | One repository, shared across its worktrees |
| Loaded | Every session | Every session (first 200 lines or 25KB of the index) |
| Good for | Coding standards, workflows, project layout | Preferences, corrections, context the code doesn’t show |
Neither is enforced. CLAUDE.md arrives as a user message after the system prompt, Claude treats both as context and tries to follow them, and vague or conflicting instructions get followed less reliably.
Carrying your preferences into every project
Auto memory keeps one folder per repository, so what Claude learned about you in one repo isn’t there in the next. What reaches every project on your machine is what lives in ~/.claude in your home folder, plus a memory that follows you.
| Layer | What it carries | Where it reaches | To keep it out of one project |
|---|---|---|---|
~/.claude/CLAUDE.md | Instructions you write | Every project on this machine |
|
~/.claude/rules/ | The same, one file per topic, some only for matching files | Every project on this machine | The same, with the rule’s path |
autoMemoryDirectory in your user settings | Claude’s own notes, in one folder you choose | Every project that doesn’t set its own | Give the project its own |
| Counterparts (ours) | Claude’s memory of you and your work together | Every folder: notes about you everywhere, notes about a project’s work in that project | Tell Claude “not here” in that folder |
The examples below are illustrations, not anyone’s real files. The steps come from Anthropic’s docs, read on 2 November 2026, and no person has run them.
1. ~/.claude/CLAUDE.md: what’s true of you everywhere
Anthropic’s docs call it user instructions: “Personal preferences for all projects”, seen only by you. It loads at the start of every session, before the project’s own CLAUDE.md. For example:
# How I work
- Ask before adding a new dependency.
- Show the diff first, then one line on why.
- I'm on macOS: write shell examples for zsh.Keep it to what holds in every project. A project’s CLAUDE.md doesn’t override yours: the files are concatenated rather than overriding each other, with the project’s read later. So a line that’s wrong for one project still loads there, next to the project’s file that contradicts it.
Move a line like that into the projects it fits (see “For some projects” below). To leave your user file out of one project altogether, the claudeMdExcludes setting takes absolute paths and, per the settings reference, applies to user files as well as project ones. Add "claudeMdExcludes": ["/Users/you/.claude/CLAUDE.md"], with your own home folder’s path, to that project’s .claude/settings.local.json (if you create this file yourself, add it to .gitignore); the docs’ examples are monorepos, and nobody here has tried it on the user file.
2. ~/.claude/rules/: the same, by topic
Each .md file in ~/.claude/rules/ applies to every project on your machine and loads before the project’s rules. One file per topic keeps each easy to find and fix:
~/.claude/rules/
├── commits.md # imperative subject line, under 72 characters
└── python.md # only when Claude works on Python filesA user rule can carry a paths field, matched from the folder the session started in. This python.md loads only when Claude reads, writes or edits a Python file, in any project:
---
paths:
- "**/*.py"
---
- Type hints on public functions.
- Use pytest for new tests.If a user rule and a project rule conflict, Anthropic’s docs say Claude “may follow either one”, so keep the two consistent or move the rule into the projects where it holds. claudeMdExcludes takes a rule’s path too, such as /Users/you/.claude/rules/python.md.
For some projects, not all. Keep the shared file outside the projects and bring it into the ones that need it, by one of two routes.
Import it. A line such as
@~/.claude/shared/client-a.mdin each project’sCLAUDE.local.mdimports it. AddCLAUDE.local.mdto.gitignoreso it isn’t committed. In a repository that has anAGENTS.mdand no CLAUDE.md, adding aCLAUDE.local.mdstops Claude Code reading the AGENTS.md; there, set Project instructions in/configto read both, add@AGENTS.mdto the sameCLAUDE.local.md, or use the symlink.Symlink it. A symlink puts it in the project’s rules:
mkdir -p .claude/rules && ln -s ~/shared-claude-rules .claude/rules/shared. In a shared repository, add.claude/rules/sharedto.gitignoreso the link isn’t committed. A symlinked rule with apathsfield doesn’t load from outside the project.
Either way Claude Code asks once per project before loading files from outside it. Say yes: if you decline, they stay off and it doesn’t ask again.
The rest of your setup. Hooks in ~/.claude/settings.json run in all your projects, and skills in ~/.claude/skills/ and subagents in ~/.claude/agents/ are there in every project too. All of it stays on this machine. To take a setup to another computer or to teammates, a plugin packages skills, subagents, hooks and MCP servers as one install, but not a CLAUDE.md or rules: Claude Code doesn’t load a CLAUDE.md from a plugin.
To take your ~/.claude/CLAUDE.md and ~/.claude/rules/ to another computer, keep them in a git repository and link them in. On the first machine, copy both into the repository, say into ~/dotfiles/claude/, and rename the originals rather than deleting them until the links work. Then, on each machine: mkdir -p ~/.claude && ln -s ~/dotfiles/claude/CLAUDE.md ~/.claude/CLAUDE.md && ln -s ~/dotfiles/claude/rules ~/.claude/rules. If a machine already has either one, move it aside first, or the link fails or lands inside the folder. Cowork sessions on the desktop skip linked user files.
3. autoMemoryDirectory: one folder for Claude’s notes
The autoMemoryDirectory setting stores auto memory “in a directory of your choice instead of the per-project default”. The memory docs say it’s read from any settings scope, user settings included, so this in ~/.claude/settings.json applies wherever no project sets its own:
{
"autoMemoryDirectory": "~/claude-notes"
}This moves where Claude keeps notes. It doesn’t move the notes. What Claude already saved in each project stays in ~/.claude/projects/<project>/memory/ and stops loading. Don’t copy several projects’ folders into the new one: each has its own MEMORY.md and note names can repeat, so copying overwrites. Start the new folder empty and ask Claude to read the old folders and save what holds everywhere; the old folders stay untouched. Delete the line to go back.
The value is one folder: an absolute path or one starting with
~/.It doesn’t layer. A project’s or local setting outranks your user setting, so a project that names its own folder uses only that one. A request to load both, the way CLAUDE.md files stack, is open as #81808. Its author’s workaround is a SessionStart hook that reads a shared notes folder into every session; Claude reads those notes but doesn’t write to them.
The user setting above puts every project’s notes in that one folder. The docs say the setting works at user level but not what one shared folder does, and nobody here has tried it. Read plainly, all projects share one
MEMORY.md, one 200-line or 25KB limit, and a note about one repo’s work can turn up in the others.A repository’s settings can set it too. Claude Code honors it there under the same trust rule as hooks. With
blockReadsOutsideWorkingDirectorieson, it ignores a folder that a repository’s settings choose.
To keep one project out, set "autoMemoryEnabled": false in its .claude/settings.local.json (in .claude/settings.json it’s off for everyone who uses the repo), or give it an autoMemoryDirectory of its own there.
4. A memory that follows you: Counterparts
The layers above are files you write, and notes Claude keeps per repository or in the one folder you name. Counterparts is Claude’s own memory of you and your work together, and what it knows about you reaches every folder (more below).
For example, say you tell Claude in one repo that you want the diff before the explanation. Claude would keep that as a note about you, so it can come up when you work in another repo. A decision about that first repo’s database schema is a note about the work, and it shows up in that repo.
Rules your team shares, like code conventions, stay in a committed CLAUDE.md.
In a folder where you don’t want it, tell Claude “not here”: nothing is kept or recalled there. If you installed it from npm (npm install -g counterparts@latest), counterparts scope . --off in that folder turns it off there from a terminal, subfolders included. How to add it.
Finding and keeping past sessions
Claude Code keeps each session as a file on your machine and, by default, deletes it once you haven’t used it for 30 days, without a message. To find a session, start with the picker and widen it; to find one by what was said in it, search the files with the script below. To keep sessions longer, raise cleanupPeriodDays; to keep one conversation as text, run /export in it.
Where sessions live, and for how long
One file per session:
~/.claude/projects/<project>/<session-id>.jsonl. The<project>name is the full path of the folder you started in, with every character that isn’t a letter or digit turned into-, so/Users/you/shop-apibecomes-Users-you-shop-api(very long paths are cut to 200 characters plus a hash). WithCLAUDE_CONFIG_DIRset, the files are under that folder instead.More than the conversation: the file also holds tool results, file contents, command output, the system prompt, tool definitions and the CLAUDE.md files that loaded. It’s plain text and isn’t encrypted, so a password a command printed is in it.
Deleted after 30 days: a background sweep after a session starts deletes transcripts older than
cleanupPeriodDays, “without showing a message”, and the session leaves the picker. The sweep leaves auto memory notes alone, and by default, on v2.1.248 or later, keeps sessions you started or last continued in Claude Desktop or Cowork at any age.Your typed prompts last longer:
~/.claude/history.jsonlkeeps what you typed, with the time and folder, until you delete it (unless your organization uses Anthropic’s HIPAA configuration).Ctrl+Rsearches it across all projects (in fullscreen, pressCtrl+Suntil the scope is all projects), so you can find what you asked after a session’s file is gone, though not Claude’s replies, and the session itself can’t be resumed from it.A renamed or moved folder: the new path gives a new
<project>name, so its picker doesn’t list sessions from before. They’re still on disk under the old name. An open report on GitHub, #86713, describes this in the VS Code extension. PressCtrl+Ain the picker, or runclaude --resume <session-id>, to reach them.
Keeping sessions longer
On v2.1.310 or later (claude --version shows yours; claude update upgrades), set cleanupPeriodDays in ~/.claude/settings.json to the number of days to keep them. Add the line to the object already in the file; if the file doesn’t exist, this is the whole file:
{
"cleanupPeriodDays": 3650
}Before you rely on it:
There’s no “never.” The minimum is 1, and
0fails validation. Anthropic’s docs suggest a large value such as 3650 (ten years).A project or managed setting wins. Your user file is the lowest in the order: a project’s settings or your organization’s managed settings outrank it. When managed settings set
cleanupPeriodDays, Desktop and Cowork sessions follow that value too.Check
/statusafter you edit. If a settings file can’t be read or parsed, Claude Code pauses the sweep rather than guess, and/statusshows a warning until you fix it.It has failed before. Version 2.1.101 fixed cleanup ignoring the setting when Claude Code ran with
--setting-sourcesthat left out user settings, which deleted history older than 30 days; 2.1.310 fixed it deleting some recent files when the value was very large. An open report, #41458, collects people who lost sessions with the setting raised, some after the 2.1.101 fix. On a related report, a collaborator on the Claude Code repository tested it on v2.1.233: a transcript backdated 40 days was deleted under the default and kept with3650.Longer means more in plain text. Anthropic’s advice for reducing exposure runs the other way: a shorter period, and permission rules that deny reads of credential files.
It doesn’t bring anything back. It applies to files still on disk. A backup of your home folder that you already make should include
~/.claude/projects(check that it keeps hidden folders); point the search script’s--dirat the backup’s copy of that folder.
To keep one conversation as readable text, run /export inside it: it saves the conversation as a plain-text file, or copies it to your clipboard. Look it over before you share it.
What the picker shows, and what it doesn’t
claude --resume, or /resume inside a session, opens the picker. Each row shows the session’s name, or its generated title, summary or first prompt, with the time since it was last active, the git branch and the file size.
| To see | Do this |
|---|---|
Sessions in this folder, and ones that added it with /add-dir | Nothing: that’s the default |
| All worktrees of this repository |
|
| Every project on this machine |
|
| Only the current git branch |
|
| What a session says |
|
| Matches for a word | Press |
Some sessions aren’t listed: ones whose first prompt was /loop, and ones created with claude -p or the Agent SDK, which claude --resume <session-id> still opens. Pick a session from another project and Claude Code copies a cd and resume command to your clipboard. claude --resume <session-id> finds a session from any folder: it looks in this project first, then every other project on the machine. The docs don’t say which folder a session found that way works in, so run it from the session’s own folder, as the picker’s copied command does.
Desktop and Claude Code on the web keep their own session lists, and the VS Code extension shares the terminal’s (Anthropic’s sessions page lists VS Code’s as separate; its VS Code page says they share one history):
| Where the session ran | Where to find it | Moving between it and the terminal |
|---|---|---|
| Claude Desktop (Code tab) | Desktop’s session list, grouped, sorted and filtered from the sidebar |
|
| Cowork | Cowork, in Claude Desktop | Its transcripts are kept at any age by default. The docs we read don’t describe opening one from the terminal |
| Claude Code on the web (cloud) | Its session list on claude.ai/code |
|
| VS Code extension | The Session history button: search by keyword, or browse by time | The same history as the terminal: |
Search past sessions by what was said
The picker lists sessions by name or title, and Ctrl+R finds a prompt you typed. To find a session by something either of you said, search the files. This script reads every session under ~/.claude/projects (or CLAUDE_CONFIG_DIR), and lists the ones where all your words appear, newest first, each with its project folder, session ID, file and the matching words. It only reads: it never changes, moves or deletes a file. It needs Python 3 and nothing else; on Windows the command may be py or python instead of python3, which we haven’t tried.
Save it as find-session.py and run it with the words you remember:
python3 find-session.py redis timeout#!/usr/bin/env python3
"""Find a past Claude Code session by what was said in it. Read-only.
python3 find-session.py redis timeout sessions where both words were said
python3 find-session.py --everything redis also tool calls, file contents, loaded files
python3 find-session.py --dir ~/other-folder redis another folder of project folders, instead of ~/.claude/projects
"""
import argparse, json, os, pathlib, sys, time, unicodedata
ap = argparse.ArgumentParser()
ap.add_argument("words", nargs="+")
ap.add_argument("--dir", help="folder of project folders (default: ~/.claude/projects)")
ap.add_argument("--everything", action="store_true", help="search every field, not just the messages")
args = ap.parse_args()
try: sys.stdout.reconfigure(errors="replace") # odd characters in a transcript must not stop the printing
except Exception: pass
norm = lambda s: unicodedata.normalize("NFC", s).lower()
words = [norm(w) for w in args.words]
config = os.path.expanduser(os.environ.get("CLAUDE_CONFIG_DIR") or "~/.claude") # ~ expanded once
root = pathlib.Path(os.path.expanduser(args.dir or os.path.join(config, "projects")))
if not root.is_dir(): sys.exit(f"No such folder: {root}")
print(f"Searching {root}\n")
def strings(v): # every string inside a parsed line
stack = [v]
while stack:
v = stack.pop()
if isinstance(v, str): yield v
elif isinstance(v, dict): stack.extend(v.values())
elif isinstance(v, list): stack.extend(v)
def said(rec): # the words of a user or assistant message, if the line looks like one
msg = rec.get("message")
if rec.get("type") not in ("user", "assistant") or not isinstance(msg, dict): return None
c = msg.get("content")
if isinstance(c, str): return [c]
if not isinstance(c, list): return []
return [b["text"] for b in c if isinstance(b, dict) and isinstance(b.get("text"), str)]
def files(): # one file per session; subagents/ folders aren't searched
try: projects = sorted(root.iterdir())
except OSError as e: sys.exit(f"Could not list {root}: {e}")
for d in projects:
try:
if not d.is_dir(): continue
for f in sorted(d.iterdir()):
if f.name.endswith(".jsonl") or ".jsonl.superseded-" in f.name:
yield f
except OSError as e:
print(" skipped", d, "-", e)
found = []
for f in files():
try:
if not f.is_file(): continue
texts, other, first, cwd, known = [], [], None, None, False
with open(f, encoding="utf-8", errors="replace") as fh: # opened for reading only
for line in fh:
try: rec = json.loads(line)
except (ValueError, RecursionError): texts.append(line); continue # a cut-off line is still searched, as raw text
if not isinstance(rec, dict): other.extend(strings(rec)); continue
if isinstance(rec.get("cwd"), str): cwd = rec["cwd"]
s = said(rec)
if s is None: other.extend(strings(rec)); continue
known = True; texts.extend(s); other.extend(strings(rec)) # tool calls and results too, for --everything
if first is None and rec.get("type") == "user" and s: first = s[0]
mtime = f.stat().st_mtime
except OSError as e:
print(" skipped", f, "-", e); continue
pool = texts + other if (args.everything or not known) else texts
text = unicodedata.normalize("NFC", "\n".join(pool))
if all(w in text.lower() for w in words):
i = text.lower().find(words[0])
found.append((mtime, f, cwd, first, " ".join(text[max(0, i - 60):i + 100].split()), known))
clean = lambda s: "".join(ch if ch.isprintable() else "?" for ch in str(s)) # no terminal escape codes from a transcript
for mtime, f, cwd, first, snip, known in sorted(found, key=lambda x: x[0], reverse=True):
sid = f.name.split(".")[0]
print(time.strftime("%Y-%m-%d %H:%M", time.localtime(mtime)), clean(f.parent.name))
if cwd: print(" folder: ", clean(cwd))
if first: print(" started:", clean(" ".join(first.split())[:90]))
print(" match: ", "..." + clean(snip) + "...")
if not known: print(" (lines not in a shape this script knows; every field was searched)")
if f.name == sid + ".jsonl": print(" session:", clean(sid))
print(" file: ", clean(f))
live = f.name == sid + ".jsonl" and root.resolve() == pathlib.Path(config, "projects").resolve() # a transcript directly under projects/<project>/
if not live: print(" (not a live session: a file from another folder, or one Claude Code set aside; open the file to read it)")
print()
print(f"{len(found)} session(s) matched." if found else "No session matched. Try --everything to search tool output and loaded files too.")On a made-up session, the output looks like this. The date is when the file was last written, and the paths are written as for a home folder at /Users/you.
Searching /Users/you/.claude/projects
2026-10-26 01:33 -Users-you-shop-api
folder: /Users/you/shop-api
started: The checkout tests fail with a Redis timeout after 5 seconds.
match: ...The checkout tests fail with a Redis timeout after 5 seconds. The pool size is 2. I'll raise it and add a retry....
session: a1a1a1a1-0000-4000-8000-000000000001
file: /Users/you/.claude/projects/-Users-you-shop-api/a1a1a1a1-0000-4000-8000-000000000001.jsonl
1 session(s) matched.What to know about it:
The file format isn’t public. Anthropic’s docs say the format “is internal to Claude Code and changes between versions, so scripts that parse these files directly can break on any release”, and point to
/exportand the script interfaces instead. So the script guesses: it reads lines that look like a user or assistant message. When a file has none it recognizes, it searches every field and says so, and a cut-off last line is searched as raw text. A file it can’t open is named and skipped, and a record with an odd shape is passed over, so a word that sits only in one can be missed without a message; if nothing matches, it suggests--everything.By default it searches what was said, not what was loaded. Each transcript also records the CLAUDE.md files that loaded, so with
--everythinga word from your CLAUDE.md can match every session in a project.--everythingis for a file path, a command or an error message that only appeared in a tool’s output.It skips subagent transcripts (the
subagents/folders). It reads the old transcripts Claude Code set aside (.orphaned-files and.jsonl.superseded-files) and labels them.It prints the session ID and the file, not a command. To reopen a session, run
claude --resume <session-id>(Anthropic’s docs). Run it from the session’s own folder, the one on the script’sfolder:line: the docs say the ID is found from any folder, but not which folder the session then works in. If the match is the session you’re in now, don’t resume it from a second terminal. Anthropic’s docs say that if you resume the same session in two terminals at once, both write to one transcript and messages from one of them can be missing;--fork-sessioncontinues in a copy with a new ID instead.Some matches aren’t live sessions. A match in a set-aside file, or in a folder you pointed
--dirat, is labelled. The docs sayclaude --resumetakes a transcript’s path, but not what resuming one of these does to it, so read it instead. A session started in Desktop or Cowork is listed too (those transcripts are in~/.claude/projects); the docs say a Desktop-started session resumes in Desktop, and don’t describe opening a Cowork one from the terminal.It prints pieces of your transcripts to the terminal, and those can include anything a command printed. Characters that aren’t printable, such as terminal escape codes, are shown as
?.How it was tested: an AI ran it on 18 and 19 November 2026 on made-up transcripts in throwaway home folders, including damaged and unreadable files and another folder searched with
--dir. None stopped it with an error, and the files were unchanged afterwards. No person has run it.
If what you want back is where you left off rather than the transcript itself, Counterparts, the memory we make, does that: after the first few sessions, each one opens with where you left off, in a short briefing Claude wrote itself. It keeps Claude’s notes, not transcripts, and deletes conversation text about 3 days after writing it up, or about two weeks after the conversation goes quiet, so it isn’t a way to get an old session back. How to add it.
What compaction keeps, and what it doesn’t
When a session nears its context limit, Claude Code replaces the conversation with a summary and carries on; /compact does the same when you ask. Afterwards, some things are read again from disk, some come back only when Claude next touches a matching file, and whatever lived only in the conversation is there only as far as the summary kept it. That last group is where “it forgot my rule” and “it lost the task” come from.
This section was read against Anthropic’s table and hooks reference on 21 November 2026. No person has run the test or the hooks below.
| What | After compaction |
|---|---|
Project-root CLAUDE.md and rules without paths | Read again from disk |
~/.claude/CLAUDE.md | Read again: |
Auto memory (MEMORY.md) | Read again from disk |
| The plan from plan mode | Read again from disk |
The task list (Ctrl+T) | Kept, on models that have one: by default Opus 4.7, Sonnet 4.6, Haiku 4.5 and earlier. Other models keep no written list unless you opt in, for example by starting Claude Code with |
| Files Claude read or edited | Up to five read again, most recently modified first. A file over 5,000 tokens comes back as its path only |
| Skills used in the session | The first 5,000 tokens of each come back, 25,000 in all, oldest dropped first |
| Background commands and background subagents | Keep running, and Claude is reminded which are still going |
Subfolder CLAUDE.md files and rules with paths | Summarized away; they load again when Claude next works with a matching file |
| What you said only in chat, “from now on” rules included | Only what the summary kept |
| Text a hook added earlier | Only what the summary kept |
A SessionStart hook with the compact matcher | Runs after each compaction, and what it prints is added |
| System prompt, output style, skill descriptions | Still apply (skill descriptions are rebuilt, v2.1.304 or later) |
If something went missing
| What you see | Why | What to do |
|---|---|---|
| A rule you typed in chat (“always use pnpm”) stopped holding | It lived only in the conversation | Put it in the project-root CLAUDE.md. Say it again for this session |
A subfolder CLAUDE.md or a rule with paths stopped holding | Summarized away, and not back until Claude touches a matching file | If it must hold all session, drop the |
| Claude lost the task, or what it already changed | The task was in the conversation, and the summary shortened it | Before it fills, run |
| Claude stopped following a skill partway | Only the start of each skill comes back, and older ones can drop | Use the skill again, and put its key steps at the top of |
| Compaction itself failed, looped or hung | A different problem | |
| The same thing in a claude.ai chat | A different product, with its own limits |
Some people report that a rule still in the root CLAUDE.md gets followed less closely after compaction (#59309, closed as not planned). Repeating the one or two that slip from the hook below is what the docs offer beyond CLAUDE.md; nobody here has measured whether it helps.
A two-minute test in your own session
In an empty folder, using a few small requests on your plan, put four codewords in four kinds of place. On macOS, Linux or Git Bash, run this (on Windows without Git Bash, make the four files by hand with the text shown):
mkdir -p compact-test/.claude/rules compact-test/sub && cd compact-test && git init -q
echo "The root codeword is AMBER." > CLAUDE.md
printf -- '---\npaths:\n - "sub/**"\n---\nThe scoped codeword is BIRCH.\n' > .claude/rules/scoped.md
echo "The subfolder codeword is CEDAR." > sub/CLAUDE.md
echo "hello" > sub/notes.txtThen:
Save the settings file from the example below as
.claude/settings.local.jsoninsidecompact-test, then runclaudethere and accept the folder trust prompt. Send two messages, one at a time: “The chat codeword is DELTA.”, then “Read sub/notes.txt.” ItsInstructionsLoadedhook adds a line to.claude/loaded.logfor each instruction file that loads, so the log now has a line forCLAUDE.md(session_start), one forscoped.md(path_glob_match) and one forsub/CLAUDE.md(nested_traversal).Run
/compact, then ask “List every codeword you can see and where each came from.”
By the docs, the log gains a compact line for the root CLAUDE.md, and BIRCH and CEDAR load again only when Claude next reads a file in sub/. That can happen straight away, since sub/notes.txt may be one of the five files read again after compacting. DELTA is there only if the summary kept it, and in a conversation this short it probably will; in a long session it’s the kind of thing that goes. The log shows the difference: AMBER gets a compact line, DELTA never has a line at all. To bring back BIRCH and CEDAR for certain, say “Read sub/notes.txt” again.
Claude’s answer is its own report; the log is the record. Files read again after compacting have compact as their load_reason. Delete the folder when you’re done.
Hooks: steer the summary, then put things back
Two hook events do different jobs here. A PreCompact hook runs just before a compaction, and what it prints becomes instructions for the summary, up to 10,000 characters per hook. It can’t add to the context afterwards: a SessionStart hook with the compact matcher does that, and what it prints is added to the compacted context. PostCompact receives the summary and adds nothing, so it suits logging. Some guides say a PreCompact hook’s output is thrown away; the docs discard only its systemMessage and continue fields.
This .claude/settings.local.json in a project uses both, plus the optional logging hook for the test:
{
"hooks": {
"PreCompact": [
{
"hooks": [
{ "type": "command", "command": "cat \"$CLAUDE_PROJECT_DIR/.claude/compact-focus.md\" 2>/dev/null || true" }
]
}
],
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "cat \"$CLAUDE_PROJECT_DIR/.claude/after-compact.md\" 2>/dev/null || true" }
]
}
],
"InstructionsLoaded": [
{
"hooks": [
{ "type": "command", "command": "{ cat; echo; } >> \"$CLAUDE_PROJECT_DIR/.claude/loaded.log\"" }
]
}
]
}
}Then write the two files it reads. In .claude/compact-focus.md, what the summary must keep, for example “Keep the task in hand, the files changed so far, what’s left, and every rule I gave in chat, word for word.” A “Compact Instructions” section in CLAUDE.md does the same without a hook; the hook suits instructions you’d rather not commit, or ones that change with the task. In .claude/after-compact.md, the few lines that must be back straight after: the current task, and the one or two rules that slip. Ask Claude to update that file as the task moves; since it’s in .claude/, Claude Code asks before the write in the default and acceptEdits modes, and the prompt can allow it for the session. Keep both files short: before v2.1.314, very large PreCompact output could make compaction fail or repeat, and it’s now cut at 10,000 characters. after-compact.md has the same 10,000-character cap: past it, Claude gets only a file path and the first 2,000 characters.
The
InstructionsLoadedblock is only for the test: it appends toloaded.login every session, so leave it out otherwise. If you already have asettings.local.json, add these entries to itshookskey rather than replacing the file.The
PreCompactentry has no matcher, so it runs for/compact, for automatic compaction and for idle compaction. Use"matcher": "auto"or"manual"for one only.Each
catends in|| true, so a missing file prints nothing and the hook still exits 0. That matters for PreCompact: exit code 2 blocks compaction, and blocking one that was recovering from a full context makes the request fail.Don’t start either file with
{: Claude Code would try to read the output as JSON.In
.claude/settings.local.jsonthe hooks are yours alone (Claude Code adds it to.gitignorewhen it saves a setting there; if you made it by hand, check it’s ignored); in.claude/settings.jsonthey apply to everyone who uses the repo, and in~/.claude/settings.jsonto all your projects (where hooks go). Run/hooksto check they loaded.The commands are for macOS, Linux and Git Bash on Windows; without Git Bash, Windows runs hooks in PowerShell, where they’d need rewriting.
How it was checked: on 21 November 2026 an AI checked the settings file is valid JSON and ran the three commands with
shon made-up input, with and without the two files.
Compaction can also happen while you’re away: idle compaction applies to a long conversation left for about an hour, under conditions the docs list, and the same hooks run for it. The FAQ says how to turn it off.
Counterparts, the memory we make, uses these two hooks for its own memory. After a compaction, Counterparts puts your memory back: its SessionStart hook brings back the short “who I am, who you are, where we left off” briefing Claude wrote itself, and its PreCompact hook has already captured the conversation, so what was said before is still written up. Counterparts doesn’t restore your CLAUDE.md, rules or task list; Claude Code does that, as in the table above. How to add it.
What Claude Code doesn’t remember
Your earlier conversations, in a new session. By default, what a new session starts with from them is what’s in CLAUDE.md and auto memory. The conversation itself comes back if you resume it. The look-up option in the resume dialog, above, also lets a new conversation refer to earlier work.
What it can read from the code. That includes yesterday’s bug fix, which isn’t a note unless you ask for one.
Anything past the top of the index. Only the first 200 lines or 25KB of
MEMORY.mdload at the start, and Claude Code reminds Claude to keep the index short. When a write leaves the index over the limit, the error goes to Claude, not to you, so you may see it only in the transcript.The end of an oversized file that loads on demand. Since v2.1.309, a subfolder CLAUDE.md or path-scoped rule over its size limit (40,000 characters on a 200K context window) arrives cut short, with a note telling Claude to read the rest. A CLAUDE.md that loads at launch arrives whole, up to 4 MiB; a bigger one is skipped.
Your auto memory, in a subagent. The main conversation’s notes aren’t loaded into subagents, except a fork. A subagent can keep its own memory with the
memoryfield.Anything on another computer. Auto memory is machine-local: it isn’t shared across machines or with cloud sessions.
Notes also don’t fade on their own: they stay as written until you or Claude edit or delete them. Our guide to stale AI memory goes further.
Memory plugins and MCP servers for Claude Code
Claude Code can connect to outside tools through MCP servers (added with claude mcp add), and plugins can bundle skills, hooks and MCP servers (installed with /plugin install). Counterparts is one. People add other memory plugins for specific gaps, such as every past session written up; our guide to Claude Code memory plugins compares them, ours included, and the directory goes system by system. Two more guides go further: claude-mem, its CLAUDE.md files and where its data lives, and memory MCP servers for Claude Code and how to set one up.
Counterparts: the memory we make
Counterparts gives Claude its own memory of you and your work together: your preferences, what you decided, what’s in progress and where you left off. At the end of a session Claude writes down what it learned, in its own words: notes, not transcripts. It’s one memory across your projects, unless you choose “just this folder” when the first session asks: what Claude knows about you shows up in every folder, and notes about a project’s work show up in that project.
After the first few sessions, each one opens with a short “who I am, who you are, where we left off” that Claude wrote itself, and related memories come to mind as you talk. It keeps a journal of your time together, and what it believes about you changes only slowly, with the history of what it used to think kept. Memories fade unless they come up again, the way a person’s do: what matters sticks; the rest lets go.
It runs beside your CLAUDE.md and auto memory, and doesn’t read or change either. To add it, in a terminal with Node 22.15 or newer, run npm install -g counterparts@latest, then counterparts, which asks your name and connects Claude Code; then restart Claude Code. This works on macOS, Linux and Windows. Windows is new, so tell us how it goes; the Quickstart’s On Windows section has the details. On macOS or Linux you can install it as a Claude Code plugin instead: run these in Claude Code, then restart it.
/plugin marketplace add mlapeter/counterparts
/plugin install counterparts@counterpartsThere’s no API key and no account, and it’s free, with its source on GitHub. Mike has used it as his daily memory since September 2026. The Claude Code page covers the dashboard, pausing and removing it.
The memories live on your machine, in one SQLite database in ~/.counterparts that only your account can read; each computer keeps its own. Like anything a session reads, they go to Anthropic, or the cloud provider you set, when a session or the once-a-day background run reads them. That run uses your Claude plan; saying “no dreams” turns it off. Conversation text is deleted about 3 days after it’s written up, or about two weeks after the conversation goes quiet. A daily check asks npm for the newest version number and sends nothing about you. The Claude Code page’s “Everything stays on your computer” is about where memories are kept; what goes out is here.
Questions people ask
Does Claude Code remember previous conversations?
Not in a new session: each one starts with a fresh context window. What carries over by default is your CLAUDE.md files and Claude’s auto memory notes. To pick up an earlier conversation itself, run claude --continue to reopen the most recent one in the current directory, or claude --resume to choose one from a list (Anthropic’s sessions docs).
What’s the difference between claude --continue and claude --resume?
claude --continue reopens the most recent session in the current folder, with no list. claude --resume opens a picker of sessions to choose from, and claude --resume <name> or claude --resume <session-id> opens one directly; inside a session, /resume switches to another (Anthropic’s sessions docs). Name a session with claude -n <name> or /rename to make it easy to find. Both restore the conversation and its tool calls; flags such as --mcp-config and --add-dir have to be passed again.
Where does Claude Code store its memory?
On your machine, as plain files. Project instructions live in ./CLAUDE.md or ./.claude/CLAUDE.md, personal ones in ~/.claude/CLAUDE.md. Auto memory lives in ~/.claude/projects/<project>/memory/, with a MEMORY.md index and one file per note. Conversation transcripts are saved as ~/.claude/projects/<project>/<session-id>.jsonl. On Windows, ~/.claude means %USERPROFILE%\.claude (Anthropic’s guide to the .claude directory).
What’s the difference between CLAUDE.md and auto memory?
You write CLAUDE.md: instructions and rules, like build commands and coding standards, loaded at the start of every session. Claude writes auto memory: things it learned, like your preferences and corrections you gave it. The first 200 lines or 25KB of its MEMORY.md index load each session, and Claude opens the notes behind it when it needs them (Anthropic’s comparison).
How do I make Claude Code remember something?
Ask it. Saying something like “remember that the API tests need a local Redis” saves it to auto memory. For a rule you want written down as an instruction, ask Claude to add it to CLAUDE.md, or open the file yourself with /memory. The old # shortcut for this was removed in version 2.0.70.
How do I know if Claude Code actually saved a memory?
Look for a notice like “Saved 2 memories” in the session: that’s Claude writing to its memory folder (how auto memory works). To read what it saved, run /memory and open the auto memory folder. Each note is a markdown file, and a note with frontmatter records when it was last written in a modified field. If there’s no notice and no new file, nothing was saved: Claude decides what’s worth keeping and doesn’t save something every session. If nothing ever saves, check that auto memory is on in /memory.
How do I see, edit, or turn off Claude Code’s memory?
Run /memory in a session. It lists your CLAUDE.md files, opens the auto memory folder, and has a toggle for auto memory, which saves to your user settings. To turn it off for one project, set autoMemoryEnabled to false in that project’s settings; for one session, set the environment variable CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 (Anthropic’s docs). In the VS Code extension, type / and look under Customize: Memory turns auto memory on or off and lets you read, edit or delete notes, and Instructions opens your CLAUDE.md files (v2.1.275 or later).
What do I do about a memory that’s wrong?
Run /memory, open the auto memory folder and edit the note, or ask Claude to. Notes stay as written until you or Claude change them. To stop Claude using the notes without changing any, turn auto memory off: with it off, Claude doesn’t read from or write to that folder.
How do I check what Claude Code loaded at the start of a session?
Run /context and look under Memory files (Anthropic’s troubleshooting). It shows which CLAUDE.md, rules and auto memory files loaded at launch; if a file is missing there, Claude can’t see it. A CLAUDE.md in a subfolder isn’t listed, because it loads later, when Claude works with a file in that folder. When it loads, a Loaded line with its path appears in the terminal. An Instruction file not loaded notice means the file exists but a read restriction, such as a deny rule, kept it out.
Why did Claude Code forget something I told it?
Check these in order. You only said it in chat, and it was a new session, you ran /clear, or compaction summarized it away. It’s in a subfolder CLAUDE.md or a path-scoped rule that hasn’t loaded again, or that’s over its size limit, so only the start arrived. You edited your project-root CLAUDE.md or ~/.claude/CLAUDE.md during this session: the change arrives at the next /clear, /compact or restart. It sits past the first 200 lines or 25KB of MEMORY.md; when a write leaves the index over that limit, Claude Code tells Claude, not you, so you may see it only in the transcript. Claude never saved it, or a subagent was doing the work, which doesn’t get the main conversation’s auto memory. Auto memory is also off in some sessions, such as --bare runs, and by default in self-hosted environments. Anything that must stick belongs in CLAUDE.md (Anthropic’s troubleshooting; after a compaction, see what it keeps).
Why doesn’t Claude Code remember the bug it fixed yesterday?
By design. Anthropic’s docs say auto memory skips what Claude can derive from the codebase, “such as architecture, file paths, or debugging fixes”. The fix is in the code, and the conversation can be reopened with claude --resume for 30 days by default. If the bug taught a rule, say “remember that ...” or add it to CLAUDE.md.
Does Claude Code delete old sessions?
Yes. By default it deletes a session’s transcript once it’s older than 30 days, without a message, and the session drops out of claude --resume (cleanupPeriodDays). Auto memory notes aren’t deleted, and sessions started or last continued in Claude Desktop or Cowork are kept at any age by default. To keep sessions longer, on v2.1.310 or later, set "cleanupPeriodDays": 3650 in ~/.claude/settings.json (0 isn’t allowed), then check /status for a warning. People have reported losing sessions with the setting raised, so read the cautions first.
How do I search my past Claude Code sessions?
In claude --resume, press / and type to filter the list, Ctrl+A to include every project on the machine and Space to preview one (the session picker). At Claude Code’s prompt, not in the picker, Ctrl+R searches the prompts you typed; in fullscreen, press Ctrl+S until the scope is all projects (interactive mode). Neither is documented as searching everything said inside a session, so this guide has a short read-only script that searches the transcript files by words from either side of the conversation and prints each match’s session ID, project folder and file. An AI tested it on made-up transcripts only.
Why can’t I find a session in claude --resume?
The picker starts with sessions from the current folder. Press Ctrl+A for every project, or Ctrl+W for the repository’s other worktrees (where the picker looks). If you renamed or moved the folder, the old sessions are filed under the old path. Sessions started with claude -p, the Agent SDK or a first-prompt /loop aren’t listed but open with claude --resume <session-id>. Desktop and Claude Code on the web keep their own lists, and a cloud session comes to the terminal with claude --teleport; the VS Code extension shares the terminal’s history, so its conversations are in claude --resume. And a session you haven’t used for 30 days has been deleted, unless you raised cleanupPeriodDays.
Can I get back a Claude Code session that was deleted?
Not from Claude Code: the docs describe no undo for the 30-day sweep. What you typed is usually still in ~/.claude/history.jsonl, which the sweep doesn’t touch (kept until you delete them), and Ctrl+R searches it, but Claude’s replies were only in the transcript. If a backup of your home folder already has the file, you can read it there, and the search script can search it: point --dir at the backup’s copy of .claude/projects, for example python3 find-session.py --dir /path/to/backup/Users/you/.claude/projects redis. Claude Code’s docs say claude --resume also takes a transcript’s absolute path (the session commands), but not where a session resumed that way is saved or what happens to the old file, and nobody here has tried it on a restored one, so this guide doesn’t give a command for it: read the file instead. Don’t put an old file back under ~/.claude/projects: a file restored with its old date can be deleted by the sweep at the next session, and if the session’s file is still there too, the two copies make claude --resume <session-id> report it not found from other folders. To avoid needing any of this, raise cleanupPeriodDays (how), and run /export in a conversation you want to keep as text.
How do I export a Claude Code conversation?
Inside the session, run /export to copy the conversation or save it as a plain-text file, or /export <filename> to write it straight to a file (Anthropic’s docs). The raw transcript is the .jsonl file under ~/.claude/projects/, but its format is internal and changes between versions.
How do I find a Claude Code session’s ID?
Inside the session, /status shows it (Desktop docs). It’s also the transcript’s file name, ~/.claude/projects/<project>/<session-id>.jsonl, and the search script shows it for each match. claude --resume <session-id> finds a session from any folder; run it from the session’s own folder, since the docs don’t say which folder a session resumed from elsewhere works in. A session’s generated title or a name you gave it works too, but the short display name such as my-app-3f doesn’t.
Does auto memory follow git branches?
No. Its folder comes from the repository, so every branch and worktree of a repo shares one set of notes, and a note about one branch’s work shows up on the others. A request for branch-scoped memory (#36045) was closed as not planned. A project CLAUDE.md committed to git does change with the branch.
Can I keep auto memory in my repo or share it with my team?
Not by default: the folder sits under ~/.claude, outside the repo, and the sharing Anthropic’s memory docs describe is CLAUDE.md through source control. The autoMemoryDirectory setting stores the notes in a folder you choose, but takes an absolute path or one starting with ~/, and the docs don’t cover committing it. The notes are also about you, so read them before sharing. For what a team should know, commit a CLAUDE.md.
Does Claude Code remember things after compaction?
Partly. The project-root CLAUDE.md, ~/.claude/CLAUDE.md, rules without a paths field and auto memory come back from disk, with up to five of the files Claude read or edited (most recently modified first) and the start of each skill used. What can get lost: anything you only said in chat, including the task in hand, and subfolder CLAUDE.md files and path-scoped rules, until Claude next works with a matching file. To steer the summary, run /compact with a focus, like /compact focus on the auth bug fix. What compaction keeps has the full list, a two-minute test and a hook that puts your own text back.
Can a hook put my instructions back after compaction?
Yes, a SessionStart hook with the compact matcher: Claude Code adds what it prints to the compacted context. A PreCompact hook can’t add context, but what it prints becomes instructions for the summary, up to 10,000 characters. PostCompact adds nothing. The example uses both. For a rule that should hold in every session, the root CLAUDE.md is simpler.
Why did Claude Code compact my conversation while I was away?
That’s idle compaction. A long conversation left for about an hour can be compacted when it’s on the one-hour prompt cache and meets the other conditions. In the terminal you’ll see a line that starts Compacted while idle, before the prompt cache expired. CLAUDE.md and auto memory come back, as after any compaction. To turn it off, set idleCompaction to false in your settings.
Did Claude Code’s memory change in October 2026?
Not at its core. Across Anthropic’s memory docs of 2, 21 and 31 October, the files and the 200-line or 25KB limit on the index stayed the same. Around them, a subfolder CLAUDE.md or path-scoped rule now also loads on a write, an edit or a single-file cat, and arrives cut short if it’s over its size limit. Idle compaction arrived and reached VS Code and the desktop app. The resume dialog, which can offer a new conversation Claude can look the old one up from, arrived too. We found nothing in those docs or in the changelog for October asking you to move or convert memory files.
Does Claude Code’s memory work across projects?
Not by default: each git repository gets its own auto memory folder. What you write does: ~/.claude/CLAUDE.md and files in ~/.claude/rules/ apply to every project on your machine. Counterparts, the memory we make, reaches every project on its own. Carrying your preferences into every project goes layer by layer, and covers the autoMemoryDirectory setting that puts Claude’s notes in one folder.
Can Claude Code’s memory inherit global and project layers, like CLAUDE.md does?
CLAUDE.md does, and rules do: ~/.claude/CLAUDE.md and ~/.claude/rules/ load in every project, and the project’s own files load after them. Auto memory doesn’t. It’s one folder per repository, and autoMemoryDirectory swaps that folder for another instead of adding one, since a project’s setting outranks your user setting. A request to layer it (#81808) is open; its author’s workaround is a SessionStart hook that reads a shared folder into each session. A subagent can also keep its own notes across all projects: memory: user in its file keeps them in ~/.claude/agent-memory/<name>/ for every project; only that subagent reads them. Counterparts, the memory we make, already works in layers: what Claude knows about you shows up in every project, and notes about a project’s work show up in that project (how).
How do I copy my CLAUDE.md and hooks across repos?
On one machine, put them in your home folder instead of copying. ~/.claude/CLAUDE.md and ~/.claude/rules/ load in every project, hooks in ~/.claude/settings.json run in all your projects, and skills in ~/.claude/skills/ and subagents in ~/.claude/agents/ are there in every project too. For only some repos, see below. A plugin packages skills, subagents, hooks and MCP servers as one install, but not a CLAUDE.md or rules: Claude Code doesn’t load a CLAUDE.md from a plugin (instructions go in a plugin as a skill). For teammates, commit the CLAUDE.md to the project. For your own other computers, keep yours in a git repository and link it in (how).
Can I share Claude Code memory across some projects but not all?
For instructions, yes: keep a shared file outside the repos and import it from each one’s CLAUDE.local.md, or symlink it into .claude/rules/, in the ones that need it (one catch with AGENTS.md). Claude Code asks once per project before loading files from outside it. For auto memory, the docs offer one folder per repository or the one folder you name in autoMemoryDirectory. Setting the same folder in several projects’ .claude/settings.local.json gives them one set of notes and one index, by the docs’ plain reading; nobody here has tried it. A request for memory shared by a group of projects (#39195) is open.
Can I have Claude Code profiles with their own memory and settings?
Yes, with the CLAUDE_CONFIG_DIR environment variable. Claude Code then keeps everything it would put in ~/.claude in the folder you name: settings, your CLAUDE.md and rules, skills, subagents, hooks, plugins, transcripts and auto memory. An alias such as alias claude-writing='CLAUDE_CONFIG_DIR=~/.claude-writing claude' gives you a second profile (env-vars docs); the reply that closed the profiles request (#7075) suggested the same. Files committed in a repository load in either profile. A new profile starts empty: you sign in again and add your plugins and MCP servers there, Counterparts included. Counterparts keeps its memory in ~/.counterparts, not in ~/.claude, so both profiles share one Counterparts memory, and folder settings apply in both.
Why doesn’t Claude Code know me like claude.ai does?
They keep separate memories. Anthropic’s help article says claude.ai’s memory works on the web, in Claude Desktop, in the mobile apps and in Cowork when it runs in the cloud; Claude Code isn’t on that list. Claude Code reads its own CLAUDE.md files and auto memory, and a request to connect the two (#14228) is open. To bring over what matters, ask claude.ai to “Write out your memories of me verbatim” (export steps) and copy the parts you want into ~/.claude/CLAUDE.md. Skills do cross: signed in with your claude.ai account, Claude Code (v2.1.273 or later) downloads the skills enabled on it. Counterparts, the memory we make, gives Claude Code one memory of you across every project. On a Mac, the same memory can reach Claude Desktop’s chat too. Install it from npm (npm install -g counterparts@latest), quit Claude Desktop, run counterparts install --host claude-desktop, reopen Desktop, then set the counterparts tools to Always allow. It doesn’t read claude.ai’s memory. How claude.ai’s own memory works is in why Claude forgets between chats.
Does Claude Code’s memory sync across computers?
Auto memory doesn’t: it stays on the machine where it was written. A project CLAUDE.md that you commit to git travels with the repository, so everyone who clones it gets the same instructions. Some memory add-ons keep their notes in a cloud service, and others, including Counterparts (the memory we make), keep a separate memory on each computer.
Does memory carry into Claude Code cloud sessions?
Your local auto memory doesn’t, and neither does ~/.claude/CLAUDE.md: both stay on your machine. A cloud session starts from a fresh clone of your repository, so a CLAUDE.md and .claude/rules/ you’ve committed come with it. Claude Code’s Projects feature, in public beta on Pro, Max and Ultra plans and still rolling out, keeps a separate project memory that its cloud threads share, even though it also uses a MEMORY.md index.
How do I keep task state across Claude Code sessions?
If you’ll come back to the same work, claude --continue reopens the conversation. Auto memory can hold notes on ongoing work, but Claude decides what to keep. On models that have Claude’s task list (by default Opus 4.7, Sonnet 4.6, Haiku 4.5 and earlier), the list survives compaction, and CLAUDE_CODE_TASK_LIST_ID=my-project claude shares it across sessions. For state you control, have Claude write it to a file in the repo before you stop. Counterparts, the memory we make, carries what’s in progress and where you left off into the next session on its own.
Do CLAUDE.md and auto memory use up context?
Yes. A CLAUDE.md that loads at launch goes into the session whole, as a user message after the system prompt, along with what it imports. The first 200 lines or 25KB of MEMORY.md load too, and the notes behind that index only when Claude opens them. A plugin’s start-of-session text, such as Counterparts’ briefing, takes context as well. Run /context to see what each takes up.
Do I need a memory plugin or MCP server for Claude Code?
CLAUDE.md and auto memory cover project rules, conventions and per-repository notes. A plugin adds what they don’t. Counterparts, the memory we make, gives Claude one memory of you and your work across every project. It opens each session with where you left off and lets what no longer matters fade. Other plugins fill other gaps; Which memory plugin should you use with Claude Code? compares them.
Is Counterparts a replacement for CLAUDE.md?
No, it works alongside it. CLAUDE.md is your instruction file: rules you write, which Claude reads word for word every session and a team shares through git. Counterparts is Claude’s own memory of you and your work together: your preferences, decisions, what’s in progress and where you left off, keeping what matters. It doesn’t read or change CLAUDE.md or auto memory, so all three run side by side (Counterparts for Claude Code).
How do I add Counterparts to Claude Code?
In a terminal with Node 22.15 or newer, run npm install -g counterparts@latest, then counterparts, then restart Claude Code. That works on macOS, Linux and Windows. On macOS or Linux you can use the plugin instead: in Claude Code, /plugin marketplace add mlapeter/counterparts, then /plugin install counterparts@counterparts, then restart. Windows is new, so tell us how it goes (the Quickstart’s On Windows section). No API key or account; free, with its source on GitHub. The Claude Code page has the rest.
Questions? Ask in r/AIMemorySystems.
Sources
- How Claude remembers your project (Claude Code docs)
- Manage sessions
- Settings reference: cleanupPeriodDays and the .claude directory: plaintext storage
- Claude Desktop: coming from the CLI, Claude Code on the web: continue a cloud session in your terminal and VS Code: resume past conversations
- Interactive mode: reverse search with Ctrl+R
- Reports on GitHub: sessions deleted with cleanupPeriodDays raised, #41458; sessions hidden after renaming a folder, in VS Code, #86713; a collaborator’s test of cleanupPeriodDays, on #62476
- Explore the context window: what survives compaction and how Claude Code works: when context fills up
- Hooks reference: PreCompact, PostCompact, SessionStart, InstructionsLoaded and hooks guide: re-inject context after compaction
- Skills: skill content lifecycle and tools reference: task tool availability
- Manage costs: custom compaction instructions
- Report on GitHub: CLAUDE.md rules weakened after compaction, #59309
- Settings reference: idle compaction, cleanup period
- Explore the .claude directory: what’s cleaned up
- Error reference: memory index over its read limit, instruction file not loaded
- Cloud environments
- Projects: project memory
- VS Code extension
- Data usage
- Claude Code changelog
- Prompt caching: editing CLAUDE.md mid-session
- Interactive mode: task list
- Hooks guide
- Subagents: persistent memory
- Connect Claude Code to tools via MCP
- Install and manage plugins
- Settings files and precedence
- Settings reference: autoMemoryDirectory, claudeMdExcludes
- Skills: where skills load, skills synced from claude.ai
- Plugins
- Environment variables: CLAUDE_CONFIG_DIR
- Permissions: workspace trust
- Claude Help Center: chat search and memory and import and export your memory
- Branch-scoped memory request, #36045
- Requests on GitHub: layered memory, #81808; memory shared by some projects, #39195; profiles, #7075; claude.ai memory in Claude Code, #14228
- The memory systems directory
- Counterparts README, Counterparts for Claude Code and privacy page
Claude Code’s docs read on 31 October and 2 November 2026, and checked again on 18 November, when the section on past sessions and its FAQs were added. The docs on compaction, hooks and memory read again on 21 November, when the section on compaction was added. Claude Code changes often; if something here has gone stale, open an issue.