anomalyco / anomalyco/opencode

Skill discovery crashes with ENAMETOOLONG on symlink cycles

Open
#45,961 1 comment 1 reaction 1 assignee View on GitHub

@rekram1-node is already working on this.

Since Aug 28, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Problem

When a skill discovery directory (e.g. ~/.agents/skills) resolves to a path inside a source skill collection, ln -s creates a self-referential symlink. OpenCode's skill scanner follows it recursively and crashes with ENAMETOOLONG.

This happens because scan() in packages/opencode/src/skill/index.ts passes symlink: true to glob (which maps to follow: true), and there is no cycle detection or depth limit.

Reproduction

# clone a skills repo
git clone git@github.com:example/skills.git && cd skills

# make the discovery dir point into the source collection
ln -s "$PWD/skills" ~/.agents/skills

# create a skill link -- ln follows the directory symlink and
# creates skills/foo/foo pointing at itself
ln -s "$PWD/skills/foo" ~/.agents/skills/foo

# start opencode -- glob follows the cycle until ENAMETOOLONG
opencode

Suggested fix

Any of these would work (in order of simplicity):

  1. Add maxDepth to the glob call. Skill bundles are shallow (skills/<name>/SKILL.md), so a depth of 3-4 prevents infinite traversal without changing behavior.
  2. Catch ENAMETOOLONG and ELOOP in the scan function and skip the path with a warning.
  3. Track visited realpaths before descending into each directory.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.