[BUG] Intermittent EISDIR error when spawning subagents via Task tool

Resolved 💬 3 comments Opened Jan 8, 2026 by wayum999 Closed Jan 12, 2026

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

  1. Have a project with agents in nested directory structure (e.g., .claude/agents/core/idea/idea-manager.md)
  2. Use the Task tool to spawn a subagent:

``yaml
Task:
subagent_type: "idea-manager"
description: "Promote idea"
prompt: "Execute idea promotion..."
``

  1. 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:

  1. During agent discovery/loading, Claude Code iterates through directories
  2. At some point, a directory path is passed to fs.readFileSync() instead of a file path
  3. No path validation (file vs directory) is performed before the read
  4. 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)

View original on GitHub ↗

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