[BUG] Intermittent EISDIR error when spawning subagents via Task tool
Description
When using the Task tool to spawn subagents, Claude Code intermittently fails with an EISDIR (illegal operation on a directory, read) error. The error occurs during agent loading/discovery, not in user code.
Environment
- Platform: macOS (darwin) Darwin 25.2.0
- Claude Code Version: Latest (as of Jan 2026)
- Node Version: System default
Steps to Reproduce
- Have a project with agents in nested directory structure (e.g.,
.claude/agents/core/idea/idea-manager.md) - Use the Task tool to spawn a subagent:
``yaml``
Task:
subagent_type: "idea-manager"
description: "Promote idea"
prompt: "Execute idea promotion..."
- The error occurs intermittently - sometimes works, sometimes fails
Error Message
Error: EISDIR: illegal operation on a directory, read
at Module.readFileSync (node:fs:441:20)
at Object.readFileSync (file:///.../node_modules/@anthropic-ai/claude-code/cli.js:...)
Expected Behavior
Subagent should spawn successfully every time, or provide a clear error message if the agent cannot be found.
Actual Behavior
Intermittent EISDIR error that crashes the agent spawn. Retrying the same command often succeeds.
Analysis
This appears related to Issue #10890 (EISDIR on Windows). The root cause seems to be:
- During agent discovery/loading, Claude Code iterates through directories
- At some point, a directory path is passed to
fs.readFileSync()instead of a file path - No path validation (file vs directory) is performed before the read
- The error is not caught gracefully, causing the operation to fail
Suggested Fix
Add path validation before file reads:
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
// Skip or return error, don't attempt to read
return { error: `Path is a directory: ${filePath}` };
}
const content = fs.readFileSync(filePath, 'utf-8');
Workaround
Retry the command when the error occurs - it usually succeeds on subsequent attempts.
Related Issues
- #10890 - EISDIR error on Windows when Read tool used on directory
- #6363 - Sub-agent creation failure (closed as duplicate)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗