Skip to content

fix(skill): circular symlinks in external skill dirs cause ENAMETOOLONG crash on Bun runtime #27638

@litown

Description

@litown

Bug Description

On Bun runtime, opencode crashes with ENAMETOOLONG error during skill scanning when external skill directories (e.g. ~/.claude/skills/, ~/.agents/skills/) contain circular or broken symlinks.

Root Cause

The skill discovery system uses glob with follow: true to scan external skill directories. When circular symlinks exist (e.g., skills/finishing-a-development-branch/finishing-a-development-branch → points to itself), glob enters an infinite recursion. On Bun runtime, this causes path strings to exceed PATH_MAX, triggering ENAMETOOLONG from readdir which crashes the process. Node.js handles this gracefully, but Bun does not.

Additionally, broken symlinks (target deleted) cause unnecessary I/O errors during scanning.

Reproduction

  1. Install a Claude Code plugin that creates skill symlinks (e.g., omc)
  2. Some skills may leave behind circular or broken symlinks in ~/.claude/skills/
  3. Run opencode with Bun runtime
  4. Process crashes with ENAMETOOLONG during skill discovery

Environment

  • Runtime: Bun 1.3+
  • OS: macOS (confirmed), likely affects Linux too
  • Affected directories: ~/.claude/skills/, ~/.agents/skills/

Proposed Fix

Pre-scan directories for circular and broken symlinks before glob traversal, and pass detected paths as ignore patterns to glob. Key changes:

  1. packages/core/src/util/glob.ts: Expose ignore option in Glob.Options
  2. packages/opencode/src/skill/index.ts: Add findBrokenSymlinks() that recursively detects circular symlinks (via readlink + path resolution + realpath visited set) and broken symlinks (via stat ENOENT/ELOOP), then passes results as glob ignore patterns

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions