[BUG] ENAMETOOLONG when working in deeply nested directories (still reproducible in 2.0.76)
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?
Claude Code crashes with ENAMETOOLONG error when started from a deeply nested directory. The error occurs immediately during session initialization - before any conversation can take place.
This is a follow-up to #10849 which was closed as "not planned". The bug is still reproducible in the latest version (2.0.76).
What Should Happen?
Claude Code should start successfully regardless of the working directory path length. Project directory names should be bounded to stay within filesystem limits (255 bytes for a single path component on macOS).
Error Messages/Logs
node:fs:1325
const result = binding.mkdir(
^
Error: ENAMETOOLONG: name too long, mkdir '/Users/user/.claude/projects/-Users-user-Development-project-alpha-enterprise-v1-feature-backend-api-gateway-v2-module-authentication-authorization-service-tests-comprehensive-suite-integration-e2e-functional-fixtures-mocks-stubs-fakes-helpers-utilities-common-config-settings-options-params-documentation-examples-samples-resources-assets-templates'
at Module.mkdirSync (node:fs:1325:26)
at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:9:1826
at oI (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:8:8084)
at Object.mkdirSync (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:9:1782)
at I12.ensureCurrentSessionFile (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1109:199)
at I12.appendEntry (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1103:1163)
at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1103:960
at I12.trackWrite (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1101:4965)
at I12.insertQueueOperation (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1103:928)
at W12 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1109:1371) {
errno: -63,
code: 'ENAMETOOLONG',
syscall: 'mkdir',
path: '/Users/user/.claude/projects/-Users-user-Development-project-alpha-enterprise-v1-feature-backend-api-gateway-v2-module-authentication-authorization-service-tests-comprehensive-suite-integration-e2e-functional-fixtures-mocks-stubs-fakes-helpers-utilities-common-config-settings-options-params-documentation-examples-samples-resources-assets-templates'
}
Node.js v25.2.1
Steps to Reproduce
- Create a deeply nested directory (path must produce >255 chars when slashes are replaced with dashes):
mkdir -p ~/Development/project-alpha-enterprise-v1/feature-backend-api-gateway-v2/module-authentication-authorization-service/tests-comprehensive-suite/integration-e2e-functional/fixtures-mocks-stubs-fakes/helpers-utilities-common/config-settings-options-params/documentation-examples-samples/resources-assets-templates
- Navigate to that directory:
cd ~/Development/project-alpha-enterprise-v1/feature-backend-api-gateway-v2/module-authentication-authorization-service/tests-comprehensive-suite/integration-e2e-functional/fixtures-mocks-stubs-fakes/helpers-utilities-common/config-settings-options-params/documentation-examples-samples/resources-assets-templates
- Start Claude Code:
claude
- Result: Immediate crash with ENAMETOOLONG
Root Cause Analysis
Claude Code derives the project directory name by replacing / with - in the absolute working directory path:
/Users/user/Development/... → -Users-user-Development-...
When this derived name exceeds 255 bytes (macOS filesystem limit for a single path component), mkdirSync fails.
The path in the reproduction steps:
- Original path: 320 characters
- Derived name: 319 characters (exceeds 255 limit)
Suggested Fix
Use smart truncation with embedded hash — similar to how "a16z" represents "Andreessen Horowitz". Keep the beginning and end readable, replace the overflow middle with a short hash:
const crypto = require('crypto');
const MAX_LEN = 250; // Leave room for filesystem overhead
const HASH_LEN = 8;
function safeProjectName(workingDirectory) {
const name = workingDirectory.replace(/\//g, '-').replace(/^-/, '');
if (name.length <= MAX_LEN) {
return name;
}
// Hash the full path for uniqueness
const hash = crypto.createHash('sha256')
.update(workingDirectory)
.digest('hex')
.substring(0, HASH_LEN);
// Keep prefix and suffix readable, embed hash in middle
const available = MAX_LEN - HASH_LEN - 4; // 4 for "--" delimiters
const prefixLen = Math.floor(available * 0.6);
const suffixLen = available - prefixLen;
const prefix = name.substring(0, prefixLen);
const suffix = name.substring(name.length - suffixLen);
return `${prefix}--${hash}--${suffix}`;
}
Example output:
Before (319 chars, CRASHES):
-Users-user-Development-project-alpha-enterprise-v1-feature-backend-api-gateway-v2-module-authentication-authorization-service-tests-comprehensive-suite-integration-e2e-functional-fixtures-mocks-stubs-fakes-helpers-utilities-common-config-settings-options-params-documentation-examples-samples-resources-assets-templates
After (250 chars, recognizable):
-Users-user-Development-project-alpha-enterprise-v1-feature-backend-api-gateway-v2-module-authentication-authorization-service-tests-comprehensive-suite-integration--a1b2c3d4--config-settings-options-params-documentation-examples-samples-resources-assets-templates
Benefits:
- Still human-readable — you can identify the project from
ls ~/.claude/projects/ - Guaranteed unique via hash
- Never exceeds filesystem limits
- No separate mapping file needed
Claude Model
Sonnet (crashes before model selection matters)
Is this a regression?
No - this appears to have existed since project directory naming was introduced.
Claude Code Version
2.0.76 (Claude Code)
Platform
Anthropic Console (Direct API)
Operating System
macOS 15.2 (Darwin 25.1.0)
Terminal/Shell
Terminal.app / zsh
Additional Information
- Related issue: #10849 (closed as "not planned")
- Node.js version: v25.2.1
- Filesystem: APFS (255-byte component limit)
This bug makes Claude Code unusable in legitimate deeply-nested project structures (common in monorepos, Java projects with package hierarchies, or projects with verbose naming conventions).
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗