[BUG] Claude Code crashes when saving project memory with "File has not been read yet" error

Resolved 💬 3 comments Opened Jun 26, 2025 by zekaizer Closed Jul 20, 2025

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [x] Other: Claude CLI (Claude Code)
  • Claude CLI version: v1.0.35
  • Operating System: macOS (M4 MacBook Pro)
  • Terminal: <!-- Terminal used -->

Bug Description

Claude Code crashes with "Error: File has not been read yet. Read it first before writing to it." when using memory commands (starting with # ) in the terminal. The application terminates unexpectedly after displaying a stack trace.

Steps to Reproduce

  1. Open Claude Code in terminal
  2. Execute a memory command using the format # memory test crash!!!
  3. When prompted "Where should this memory be saved?", select either:
  • Option 1 (Project memory - ./CLAUDE.md) OR
  • Option 2 (Project memory (local) - ./CLAUDE.local.md)
  1. Wait for the "Saving project memory..." process to start
  2. Application crashes with the error stack trace

Note: Option 3 (User memory - ~/.claude/CLAUDE.md) works correctly without any issues.

Expected Behavior

The memory command should be processed successfully and project memory should be saved to the selected project memory file (./CLAUDE.md or ./CLAUDE.local.md) without crashing the application, similar to how user memory (Option 3) works correctly.

Actual Behavior

The application crashes with the following error:

Error: File has not been read yet. Read it first before writing to it.
    at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1920:1009
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async I (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:622:14088)

Node.js v24.2.0

Additional Context

  • Hardware: M4 MacBook Pro
  • Node.js version: v24.2.0
  • Claude Code version: v1.0.35
  • The crash occurs specifically when using memory commands (commands starting with #)
  • Issue is isolated to project-level memory options only:
  • ❌ Option 1: ./CLAUDE.md (Project memory) - CRASHES
  • ❌ Option 2: ./CLAUDE.local.md (Project memory local) - CRASHES
  • ✅ Option 3: ~/.claude/CLAUDE.md (User memory) - WORKS CORRECTLY
  • The error suggests a file I/O issue where the application attempts to write to project memory files that haven't been read first
  • The error occurs in the memory saving functionality (Saving project memory... was displayed before crash)
  • Stack trace indicates the issue is in the CLI tool's file handling logic at line 1920
  • This appears to be a systematic issue with project-level memory file handling, while user-level memory handling works correctly
  • The bug suggests different code paths are used for project vs user memory, with the project memory path having a file read/write order issue

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗