claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] ENAMETOOLONG when saving conversation history with deeply nested working directories

Open Elijas opened this issue 5 months ago • 2 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When working in a deeply nested directory structure, Claude Code crashes with an ENAMETOOLONG error during conversation. The error occurs when Claude Code attempts to create the project directory for storing conversation transcripts.

The error shows: Error: ENAMETOOLONG: name too long, mkdir '/Users/user/.claude/projects/-Users-user-Development-project-alpha-v1-feature-backend-api-v2-module-auth-service-tests-unit-integration-e2e-fixtures-mocks-helpers-utils-config' at Module.mkdirSync (node:fs:1325:26) at Object.mkdirSync (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:9:1190) at _c2.appendEntry (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3593:2955) at _c2.insertMessageChain (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3593:2255)

The constructed path exceeds macOS filesystem limits (typically 255 characters for a path component).

What Should Happen?

Claude Code should handle long working directory paths gracefully by:

  1. Hashing or shortening the project directory name to stay within filesystem limits
  2. Maintaining a mapping file to resolve hashed names back to original paths
  3. Or truncating/encoding the path in a way that fits within OS limits

Similar to how git creates .git directories regardless of the repository path length.

Error Messages/Logs

Error: ENAMETOOLONG: name too long, mkdir '/Users/user/.claude/projects/-Users-user-Development-project-alpha-v1-feature-backend-api-v2-module-auth-service-tests-unit-integration-e2e-fixtures-mocks-helpers-utils-config'
      at Module.mkdirSync (node:fs:1325:26)
      at Object.mkdirSync
  (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:9:1190)
      at _c2.appendEntry
  (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3593:2955)
      at _c2.insertMessageChain
  (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3593:2255)
      at process.processTicksAndRejections (node:internal/process/task_queues:103:5)

Steps to Reproduce

  1. Create a deeply nested directory structure:
    mkdir -p ~/Development/project-alpha-v1/feature-backend-api-v2/module-auth-service/tests-unit/integr
    

ation-e2e/fixtures-mocks/helpers-utils/config-settings/docs-examples

  1. Navigate into the deeply nested directory: cd ~/Development/project-alpha-v1/feature-backend-api-v2/module-auth-service/tests-unit/integr ation-e2e/fixtures-mocks/helpers-utils/config-settings/docs-examples
  2. Start Claude Code and have a conversation: claude
  3. After any assistant response with tool usage, the error occurs as Claude tries to save the conversation transcript.

Note: The bug triggers when the constructed path ~/.claude/projects/{encoded-working-directory-path} exceeds filesystem limits. On macOS, this is typically 255 characters for a single path component.

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.0.31 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

This issue is related to but distinct from:

  • #7940 - Similar ENAMETOOLONG but during directory traversal (readdir), not conversation storage (mkdirSync)
  • #3411 - ENAMETOOLONG for CLI arguments, not file paths (already fixed)

Root Cause: Claude Code appears to derive the project directory name from the absolute working directory path, which can become extremely long with nested directory structures. The path component exceeds the 255-character limit on macOS.

Suggested Fix: Use a hash-based approach for project directory naming:

const crypto = require('crypto');
const projectHash = crypto.createHash('sha256')
  .update(workingDirectory)
  .digest('hex')
  .substring(0, 16);
const projectDir = `~/.claude/projects/${projectHash}`;

This would ensure project directory names never exceed filesystem limits while maintaining
uniqueness.

Elijas avatar Nov 02 '25 10:11 Elijas

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 10 '25 10:12 github-actions[bot]

i also experienced this

mk1337 avatar Dec 20 '25 15:12 mk1337