Skip to content

[BUG] apm compile for Claude includes broken dependency links #1047

@tillig

Description

@tillig

Describe the bug

apm compile --targets claude generates a # Dependencies section in the root CLAUDE.md that references @apm_modules/{owner}/{package}/CLAUDE.md for every package directory found in apm_modules/ — regardless of whether a CLAUDE.md file actually exists in that directory. Many installed packages won't have one (e.g., skill collections, single-file packages, or packages that only target Copilot/AGENTS.md).

To Reproduce

  1. Create an apm.yml with at least one dependency that doesn't ship a CLAUDE.md (e.g., a skill collection or a package that only provides AGENTS.md)
  2. Run apm install
  3. Run apm compile --targets claude
  4. Inspect the generated root CLAUDE.md — the # Dependencies section lists @apm_modules/{owner}/{package}/CLAUDE.md paths that don't exist on disk

Expected behavior

The Dependencies section should only list @import paths for CLAUDE.md files that actually exist in apm_modules/. Packages without a CLAUDE.md should be omitted from the list.

Environment (please complete the following information):

  • OS: macOS
  • Python Version: 3.12
  • APM Version: 0.10.0

Additional context

The root cause is in _collect_dependencies(). The method iterates apm_modules/{owner}/{package}/ directories and constructs import paths without checking whether the target file exists:

for package_dir in owner_dir.iterdir():
    if not package_dir.is_dir() or package_dir.name.startswith('.'):
        continue

    # Build the @import path
    import_path = f"@apm_modules/{owner_dir.name}/{package_dir.name}/CLAUDE.md"
    dependencies.append(import_path)

The comment on line 223 says "Scan for CLAUDE.md files" — the intent was to find existing files, but the existence check is missing. A fix would be adding if (package_dir / "CLAUDE.md").exists() before appending.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething does not work as documented.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions