claude-code - 💡(How to fix) Fix [FEATURE] Cache CLAUDE.md between sessions — skip reload when file unchanged [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45029Fetched 2026-04-09 08:14:58
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2
  • The memory documentation recommends keeping files under 200 lines but provides no mechanism to avoid redundant loading
  • MEMORY.md already has a 200-line / 25KB truncation limit, showing context budget is a recognized concern
  • claudeMdExcludes exists for monorepos, showing precedent for controlling what gets loaded
  • /compact re-reads CLAUDE.md from disk, confirming the system already has a reload path

Root Cause

  • The memory documentation recommends keeping files under 200 lines but provides no mechanism to avoid redundant loading
  • MEMORY.md already has a 200-line / 25KB truncation limit, showing context budget is a recognized concern
  • claudeMdExcludes exists for monorepos, showing precedent for controlling what gets loaded
  • /compact re-reads CLAUDE.md from disk, confirming the system already has a reload path
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

Problem

Per the official documentation:

Each Claude Code session begins with a fresh context window. Two mechanisms carry knowledge across sessions:

  • CLAUDE.md files
  • Auto memory

Both are loaded at the start of every conversation.

This means the full contents of all discovered CLAUDE.md files are injected into context on every session start, regardless of whether the files have changed. For users who restart sessions frequently (context limits, breaks, task switching), identical tokens are consumed repeatedly with zero informational value.

The cost scales with:

  • Number of CLAUDE.md files in the hierarchy (ancestor directory walking)
  • Files imported via @ syntax (up to 5 hops)
  • .claude/rules/*.md files
  • Frequency of session restarts

Context

  • The memory documentation recommends keeping files under 200 lines but provides no mechanism to avoid redundant loading
  • MEMORY.md already has a 200-line / 25KB truncation limit, showing context budget is a recognized concern
  • claudeMdExcludes exists for monorepos, showing precedent for controlling what gets loaded
  • /compact re-reads CLAUDE.md from disk, confirming the system already has a reload path

Impact

Low-effort optimization (hash comparison is trivial) that saves tokens proportional to CLAUDE.md size x session restart frequency. Most beneficial for power users with structured project instructions who restart sessions often.

Proposed Solution

Option A — Full cache (best for unchanged files):

Cache a hash or mtime of each loaded CLAUDE.md file between sessions. On session start:

  1. Discover files as usual (directory walk, imports, rules)
  2. Compare hash/mtime against cached values
  3. If unchanged, reuse cached content without re-consuming tokens
  4. If changed, reload and update cache

Option B — Diff injection (best for small edits):

When a file has changed since last session, inject only the diff rather than the full file. For a one-line edit in a 200-line CLAUDE.md, this saves ~99% of the tokens that would otherwise be re-loaded. Full reload only when the diff exceeds a threshold (e.g. >50% of the file changed).

Both options are compatible and could be combined.

Written by Claude

Alternative Solutions

No response

Priority

Medium - Would be very helpful

Feature Category

Interactive mode (TUI)

Use Case Example

No response

Additional Context

No response

extent analysis

TL;DR

Implement a caching mechanism to store hashes or mtimes of loaded CLAUDE.md files, allowing for token-saving reuse of unchanged content between sessions.

Guidance

  • Identify the files that are being loaded at the start of every conversation, including those discovered through directory walking, imports, and rules.
  • Develop a caching system that stores hashes or mtimes of these files, enabling comparison against cached values on subsequent session starts.
  • Implement logic to reuse cached content when files are unchanged, and reload/update the cache when changes are detected.
  • Consider combining full cache and diff injection approaches for optimal token savings.

Example

// Pseudocode example of caching mechanism
const cachedFiles = {};

function loadClaudeMdFiles() {
  const files = discoverFiles(); // directory walk, imports, rules
  files.forEach((file) => {
    const hash = calculateHash(file);
    if (cachedFiles[file.path] && cachedFiles[file.path].hash === hash) {
      // Reuse cached content
    } else {
      // Reload and update cache
      cachedFiles[file.path] = { hash, content: file.content };
    }
  });
}

Notes

The proposed solution assumes that the system has access to file modification times or hashes, and that the caching mechanism can be efficiently implemented.

Recommendation

Apply workaround: Implement a caching mechanism to store hashes or mtimes of loaded CLAUDE.md files, as this approach is likely to yield significant token savings for power users with frequent session restarts.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING