Aident AI

Claude Code Memory Missing in a Worktree? Diagnose It Safely
If Claude Code remembers a correction in your main checkout but forgets it in a Git worktree, first determine which kind of state is missing. Project CLAUDE.md instructions, CLAUDE.local.md, auto memory, and conversation history use different loading and storage rules. Anthropic documents auto memory as shared across worktrees in the same repository, but a fresh July 28 issue reports that some worktree sessions receive no auto-memory content at all.
Do not start by copying hidden project directories, merging session files, or symlinking .claude. Compare the two sessions with /context, /memory, and Git's repository-identity commands. Then put durable team instructions in the tracked project CLAUDE.md while you preserve a minimal reproduction for the open bug.
Quick Diagnosis
What is missing | What it usually means | First check |
|---|---|---|
A tracked project | The file did not load, was excluded, or is outside the loaded hierarchy | Run |
| The untracked local file was not copied into the fresh checkout | Compare the two worktree files without changing Git state |
Auto-memory notes in one worktree session | The session may have resolved or loaded the repository memory incorrectly | Open |
A previous conversation in | Session history is path-scoped separately from auto memory | Follow the session-history recovery guide instead |
All memory after switching machines or cloud environments | Auto memory is machine-local | Restore only from a trusted backup or rebuild the needed instructions |
The most important distinction is that a missing conversation is not proof that auto memory failed. Likewise, seeing the correct CLAUDE.md does not prove that the machine-local auto-memory index loaded.
Prerequisites
Before testing, save current work and record:
the Claude Code version and surface, such as CLI, desktop, or IDE;
the operating system;
whether the worktree came from
claude --worktreeorgit worktree add;the main checkout path and linked worktree path;
one harmless, non-secret sentence already present in auto memory that you can use as a probe.
Run this in each checkout:
Expected result: you know which binary and working directory each session uses, and neither checkout has uncommitted work that your diagnosis could accidentally disturb.
Do not paste private memory contents into a public issue. A sanitized yes-or-no result for one harmless probe is enough.
Step 1: Establish the Main Checkout Baseline
Start a fresh Claude Code session in the main checkout. Run:
Under Memory files, record which project and user instruction files loaded. Then run:
Record whether auto memory is enabled and which auto-memory folder Claude Code opens. Do not edit the folder yet.
Choose one harmless sentence that exists in the current auto-memory index but nowhere in the repository. Ask Claude to quote that exact sentence and explicitly allow it to answer that the line is unavailable.
Expected result: the main session lists the intended instruction files, points to one auto-memory folder, and can quote the probe without guessing.
Step 2: Repeat the Same Checks in a Worktree
Create an isolated test worktree only if you do not already have one:
Anthropic documents --worktree as creating a fresh checkout under .claude/worktrees/ on its own branch. A manually created linked worktree is also useful if that is where the problem occurs, but record which path you tested.
In the worktree session, run the same /context and /memory checks, then ask for the same harmless auto-memory sentence.
Expected behavior from the current documentation: worktrees in the same Git repository share one auto-memory directory. The project CLAUDE.md should also load when it is stored at the repository root or in ./.claude/CLAUDE.md.
A failure is reproducible when the main session can quote the probe but the worktree session cannot, or when /memory resolves the two sessions to different repository memory folders without an intentional autoMemoryDirectory setting.
Step 3: Confirm Both Checkouts Belong to One Git Repository
Run these read-only commands in the main checkout and the linked worktree:
Expected result:
--show-toplevelreturns a different checkout root in each worktree;--git-common-dirresolves to the same repository metadata directory;git worktree list --porcelainlists both paths and their branches.
This comparison matters because the documented memory scope is the Git repository, not merely the current folder name. Fresh issue reports suggest that some launch paths still key part of the session state to the worktree path even when Git identifies one shared repository.
Step 4: Classify the Missing State
Use the evidence rather than treating every reset as one bug.
Project CLAUDE.md is absent from /context
Confirm the file is at ./CLAUDE.md or ./.claude/CLAUDE.md in the worktree. If the file is tracked, compare it with the main checkout using Git. Also check whether claudeMdExcludes intentionally skips it.
Do not duplicate the same rules into several files. Fix the authoritative tracked file or its loading boundary, then start a fresh session and verify /context again.
CLAUDE.local.md exists only in the main checkout
This can be expected. A worktree is a fresh checkout, so an ignored local file is not automatically present. Keep team rules in tracked project instructions. If a personal rule truly applies to every repository, place it in user instructions rather than copying divergent local files by hand.
The correct auto-memory folder is listed, but the probe is missing
That matches the fresh inconsistent-loading report more closely than a file-location error. Record the session start time, version, worktree path class, and sanitized probe result. Do not force the answer by adding the same sentence to CLAUDE.md, because that would stop testing auto memory.
/resume cannot find the old conversation
Conversation history and auto memory are separate. Use the Claude Code session-history recovery workflow to locate the owning project path without rewriting JSONL files.
Step 5: Preserve Durable Instructions While the Bug Is Open
Auto memory is useful for machine-local learnings, but it should not be the only copy of a rule the team must follow. Put stable build commands, architecture facts, testing rules, and review conventions in one tracked project CLAUDE.md. Use the CLAUDE.md audit guide to keep those instructions concise and testable.
Keep current task state in a normal project handoff or issue that humans can review. Treat that as task continuity, not as a replacement auto-memory store.
For parallel work, follow the Git worktree isolation guide so branches and generated files do not collide. A clean worktree boundary makes a memory-loading reproduction much easier to trust.
Expected result: a new worktree can recover mandatory project rules from version control even if its optional auto-memory load is inconsistent.
Unsafe Fixes to Avoid
Avoid repairs that destroy evidence or mix unrelated state:
deleting
~/.claude/projects/before preserving a sanitized comparison;copying or merging session JSONL files to repair auto memory;
symlinking
.claudeor.claude/worktrees, which current worktree creation explicitly rejects;setting one global
autoMemoryDirectoryfor unrelated repositories;committing machine-local memory or secrets into the repository;
assuming a successful
/resumeproves auto memory loaded;disabling auto memory without confirming that it is the failing layer.
If you need a temporary test with auto memory disabled, use the documented /memory toggle or CLAUDE_CODE_DISABLE_AUTO_MEMORY=1, record the scope, and restore the previous setting after the comparison. Disabling the feature can isolate behavior, but it cannot repair a missing load.
Step 6: Report a Minimal Reproduction
If the main checkout succeeds and a fresh worktree fails, add the smallest sanitized reproduction to the matching Anthropic issue. Include:
Claude Code version, operating system, and surface;
built-in or manual worktree creation;
whether both paths share the same absolute Git common directory;
the Memory files difference from
/context;whether
/memorydisplayed the same folder;whether the harmless probe was available in each fresh session;
the UTC start times of the two sessions.
Do not include repository names, usernames, secrets, full transcripts, or the memory text itself. The result can be written as main: available; worktree: unavailable.
Why This Diagnosis Works
The checks separate four state layers before changing any of them. Git establishes repository identity. /context proves which instruction files entered the session. /memory shows the configured auto-memory surface. The harmless probe tests whether content actually loaded rather than whether a folder merely exists.
This follows the useful structure behind Aident's Ollama networking guide: use the exact symptom, change one boundary at a time, state the expected result, and explain what the result proves.
Verify One External Action With Aident Loadout
Once project instructions load consistently, verify one read-only external Action without storing a provider credential in auto memory or the repository.
Give Claude Code this instruction:
Then run:
Use Aident Loadout to inspect one live read-only Action schema. Measure success as one current schema inspected, zero provider secrets pasted, and zero repository files changed.
For a smaller tool context after setup, compare local and remote MCP servers.
Sources
How Claude remembers your project, Anthropic Claude Code documentation, accessed July 29, 2026
Worktrees, Anthropic Claude Code documentation, accessed July 29, 2026
Claude Code settings, Anthropic Claude Code documentation, accessed July 29, 2026
Auto-memory is inconsistently loaded in git-worktree sessions, Anthropic Claude Code issue, opened July 28, 2026
Worktrees should share the same project directory as the main repo, Anthropic Claude Code issue, opened March 14, 2026
Session state should persist across git worktrees, Anthropic Claude Code issue, opened December 30, 2025
Git worktrees resolve to the main worktree memory directory, Anthropic Claude Code issue, opened March 27, 2026
Git worktree documentation, Git project documentation, accessed July 29, 2026
This guide reflects the official documentation and open issue evidence available on July 29, 2026. Recheck the linked documentation and issue status before changing Claude Code's private state.


