[BUG] ENAMETOOLONG when saving conversation history with deeply nested working directories
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:
- Hashing or shortening the project directory name to stay within filesystem limits
- Maintaining a mapping file to resolve hashed names back to original paths
- 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
- 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
- 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
- Start Claude Code and have a conversation: claude
- 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.
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.
i also experienced this