Skip to content

Let authors target native context files (root or nested CLAUDE.md/AGENTS.md), not just .claude/rules #1807

Closed

Description

Is your feature request related to a problem? Please describe.

A package author cannot choose where compiled guidance lands on the destination axis: the harness's native context file (CLAUDE.md / AGENTS.md, root or nested in a subdirectory) versus a path-scoped rule file (.claude/rules/). Every instructions primitive compiles to a rule file. For Claude that is .claude/rules/<name>.md, with applyTo: translated to paths:, and the instructions section is then deduplicated out of CLAUDE.md. So for Claude, instruction content can only ever become a path-scoped rule.

These placements behave differently, and both native forms are useful:

  • .claude/rules/<name>.md with paths: is path-scoped and lazily loaded. Claude pulls it in only when it touches a matching file.
  • A root CLAUDE.md / AGENTS.md is always-on. It stays in context on every turn, and Claude re-injects it after /compact.
  • A nested CLAUDE.md / AGENTS.md (placed in a subdirectory) is the agent-native directory-scoping mechanism. Every major agent loads it when working anywhere in that subtree, and it survives the same way the root file does. This is directory scoping, distinct from the glob and extension scoping of a paths: rule.

Three use cases are blocked:

  1. Root, always-on. Short cross-cutting rules an agent benefits from on every turn (tool-selection conventions, repo-wide layout, "use the gh CLI for GitHub operations"). applyTo: "**/*" does not help: it still compiles to a rule file and is still deduplicated out of the root file.
  2. Nested, directory-scoped. Guidance that should hold across a whole subtree (a service or package directory) and load whenever the agent works anywhere under it. The agent-native nested context file fits this exactly, but APM never targets it for Claude. The content is forced into a paths:-globbed rule instead.
  3. Troubleshooting and diagnostic sessions, no file editing. A support-engineer agent diagnosing live infrastructure (database health, operator state, cluster logs) never opens a source file, so a paths:-globbed rule in .claude/rules/ never fires and the skill trigger it carries is never seen. The guidance and its skill triggers must be always-on in CLAUDE.md / AGENTS.md to be reachable at all. APM can ship the troubleshooting skills, but it cannot place their triggers where a non-editing session will load them. See IldarMinaev/engineer-workspace, which deploys PostgreSQL, Patroni, and Kubernetes diagnostic skills through APM for read-only support work of this kind.

Describe the solution you'd like

A primitive distinct from instructions, provisionally agentsmd (or context-file), whose contract is "this content belongs in the harness's native context file," with an author-declared destination directory.

  • The author declares a preferred folder (for example dir: "." for the root file, or dir: "services/payments" for a nested one), and APM writes the content into that directory's CLAUDE.md / AGENTS.md.
  • On Claude the content lands in the chosen CLAUDE.md and is exempt from the .claude/rules/ deduplication. It is meant to live in the context file, so the dedup pass must leave it there.
  • On harnesses that already fold instructions into a context file (AGENTS.md for Codex and OpenCode, GEMINI.md), the primitive maps onto the existing context-file path; nested directories use that harness's nested-AGENTS.md convention.
  • The difference from instructions is the destination (a native context file, root or nested), not the scoping strategy. --single-agents collapses nested files into the root, as it does today.

Describe alternatives you've considered

  • apm compile --no-dedup / --force-instructions. This keeps the instructions section in CLAUDE.md, but it is a consumer-side, all-or-nothing flag rather than a per-primitive author declaration, and it duplicates content into both .claude/rules/ and the context file. That is the opposite of choosing a single destination.
  • applyTo: distributed placement. APM already places nested AGENTS.md for fold-into-root targets via applyTo:, but for Claude the matching content is deduplicated out of the nested CLAUDE.md and only the rule file survives. The nested-context-file path is reachable for Codex, Gemini, and OpenCode, but not for Claude. That is exactly the gap.
  • Spec Kit constitution. The constitution block is always written to the top of CLAUDE.md / AGENTS.md, so it covers always-on root content. But it is a single project-level block tied to memory/constitution.md, not a reusable primitive an upstream package can ship through apm dependencies, and it has no nested form.
  • Path-scoped rules alone. Glob scoping is correct for "true when editing X." It is the wrong tool for always-on rules and for whole-subtree rules, and it is not re-injected after /compact the way a context file is.

Additional context

The motivating case is a large monorepo consuming platform conventions through apm dependencies. A few cross-cutting rules belong always-on in the root file, per-service conventions belong in that service's nested CLAUDE.md / AGENTS.md, and stack-specific how-tos stay in path-scoped rules and skills. Today only the last is expressible for Claude.

Path scoping also assumes the agent reaches a matching file. Read-only sessions such as incident triage, infrastructure diagnostics, and support work break that assumption: there is no file event to trigger a paths: rule, so any guidance gated behind one stays unreachable. That guidance has to live in the always-on context file.

Relevant current behaviour:

Activity

  1. github-actions commented on Jun 16, 2026

    @github-actions

    Triage decision

    needs-design

    Proposed labels

    theme/portability
    area/multi-target
    area/package-authoring
    type/feature
    status/needs-design
    status/triaged
    

    Note: area/docs-site was considered (Doc Writer activated) but dropped to stay within the 6-label cap. The implementing PR should carry it. The 2 reactions (+1 x2) on this issue signal real external demand from distinct users.

    Milestone

    null -- needs-design issues receive no milestone per rubric.

    Suggested next action

    Draft a design doc covering: (1) schema definition for the new primitive in apm.yml, (2) the cross-target compatibility matrix (Claude dedup-exempt path, Codex/Gemini/OpenCode native-context path, --single-agents collapse semantics), (3) deduplication exemption rule, and (4) path safety validation for the dir: field. Link it back here.

    Suggested issue comment

    Thank you for this exceptionally detailed report -- the three blocked use cases, the alternatives considered, and the real-world deployment reference (IldarMinaev/engineer-workspace) make the gap very concrete.
    
    The direction is sound: package authors need a way to target native context files (root and nested) as a distinct primitive from path-scoped rules. APM's current compilation model conflates these, and the read-only session use case is a legitimate gap that path-scoped rules cannot cover. A read-only diagnostic agent that never opens a source file will never trigger a `.claude/rules/` entry -- the guidance must live in the always-on context file to be reachable at all.
    
    This is triaged as **needs-design**. Before code can land safely, the following design questions must be settled:
    
    1. **Schema:** What does the new primitive look like in `apm.yml`? (Name -- `agentsmd` or `context-file` -- fields, `dir:` semantics, relationship to `instructions`.)
    2. **Compatibility matrix:** How does `dir:` map to each target's native context file path convention? (Claude: CLAUDE.md with dedup-exempt treatment; Codex, Gemini, OpenCode: AGENTS.md / GEMINI.md equivalents; nested-file conventions per harness.)
    3. **Deduplication exemption:** The Claude compiler currently deduplicates instructions content out of CLAUDE.md. The new primitive must be explicitly exempted from this pass -- the exemption rule needs to be specified and tested.
    4. **`--single-agents` interaction:** How does the `dir:` field behave when `--single-agents` is set? (Collapse nested into root? Warn? Error?)
    
    A design doc covering these four points, linked back here, would let this move to `status/accepted` and into an implementation PR. Given the detail and quality of this report, your participation in that design doc would be very welcome.

    Per-lens notes (collapsed)

    DevX UX Expert -- User-Need Reviewer

    Three blocked use cases are real and well-documented: (1) root always-on content (cross-cutting rules, survives /compact re-injection), (2) nested directory-scoped content (per-subtree conventions, agent-native directory scoping), (3) read-only / diagnostic sessions (no file event, path-scoped rules never fire). The read-only session case is the most differentiating: APM can ship diagnostic skills but cannot currently place their triggers where a non-editing session will load them. The proposed dir: field is intuitive. Alternatives are carefully assessed. Strong, demonstrated user need.

    Supply Chain Security Expert -- Risk-Surface Reviewer

    The new primitive writes content to CLAUDE.md / AGENTS.md which are always-on context files for AI agents. This is an intentional content-write surface. The dir: field must be validated through path_security.validate_path_segments or ensure_path_within to prevent path traversal (e.g., dir: "../../etc"). The design doc must include a path safety requirement. No new auth surfaces introduced. Risk surface: medium, well-bounded by an explicit path guard requirement.

    OSS Growth Hacker -- Contributor-Tone Reviewer

    vlsi has author_association: NONE -- first-time or low-interaction contributor to microsoft/apm. This issue is among the most detailed and well-researched feature requests in the queue: cites internal compile mechanics, prior issues (#1138, #1146), and a real deployment case (IldarMinaev/engineer-workspace). The suggested comment explicitly invites them to contribute to the design doc. This contributor has done enough homework to be a productive participant in the design phase.

    Python Architect -- Architecture Reviewer

    New primitive type requires changes across: (1) primitive schema validation, (2) compilation pipeline dispatch, (3) Claude compiler dedup pass (exemption logic for the new primitive type), (4) target adapters for each harness. The cross-target compatibility matrix and the --single-agents interaction are non-trivial design decisions that, if wrong, will require breaking changes later. The proposal is directionally correct but the design must be formally specified before code lands. status/needs-design is correct; the issue is clear enough that a motivated contributor could draft the design doc.

    Doc Writer -- Documentation Reviewer

    A new primitive type requires: (1) new entry in docs/concepts/primitives-and-targets.md (compatibility matrix row for the new primitive), (2) updates to the producer/compile.md guide (new primitive section, dir: semantics), (3) potentially a new reference page. This is significant docs work that should be drafted alongside or immediately after the design doc. area/docs-site was dropped from proposed labels to stay within the 6-label cap; the implementing PR must carry it.

    APM CEO -- Triage Arbiter

    The direction is strategically sound and the demand is demonstrated (real deployments, +1 reactions). The read-only session use case is a meaningful differentiation for APM: the tool can ship operational skills that work even when the agent never touches a source file. However, shipping a new primitive type without a complete cross-target compatibility design would create breaking-change debt. needs-design is the correct gate. The design doc should be a collaboration between the team and vlsi, who has done the research. No priority on needs-design per rubric.

    {
      "decision": "needs-design",
      "decision_detail": "Schema for new primitive, cross-target compatibility matrix (Claude dedup-exempt path, Codex/Gemini/OpenCode native-context convention), deduplication exemption rule, --single-agents interaction, and path safety validation for dir: field must all be defined before code can land.",
      "theme": "theme/portability",
      "areas": ["area/multi-target", "area/package-authoring"],
      "type": "type/feature",
      "status": "status/needs-design",
      "priority": null,
      "preserved_labels": [],
      "milestone": null,
      "next_action": "Draft a design doc covering the four open questions (schema, compatibility matrix, dedup exemption, --single-agents interaction) and link back here.",
      "comment_markdown": "Direction is sound: package authors need a way to target native context files as a distinct primitive. needs-design: schema, compatibility matrix, dedup exemption rule, and --single-agents interaction must all be specified in a design doc before code lands."
    }

    Triage status: agentic proposal pending human ratification.
    Silence is approval. Maintainers can:

    • Override any label or milestone above by editing it directly --
      human edits are authoritative and will not be reverted on
      subsequent runs.
    • Re-trigger triage by applying the status/needs-triage label, or
      by removing status/triaged to enroll the issue in the next
      daily sweep.

    Posted by the Triage Panel workflow. See .apm/skills/apm-triage-panel for the panel skill.

    Generated by Triage Panel · sonnet46 6M · ◷

  2. added
    area/multi-target
    area/package-authoring
    status/needs-design
    status/triaged
    type/feature
    on Jun 16, 2026
  3. danielmeppiel commented on Jun 25, 2026

    @danielmeppiel
    Collaborator

    Grounding this against current apm compile behavior, then folding it into the design issue #1911.

    apm compile already emits native context files beyond .claude/rules:

    • root and nested AGENTS.md (vscode/agents families),
    • CLAUDE.md + .claude/ structure (claude family),
    • a toggle to include the instructions section directly in CLAUDE.md instead of .claude/rules/ (compile/cli.py).

    So the project-level "target native context files" ask is largely served today. The genuine residual is author-intent placement: a package author wanting a shipped fragment to land at a specific native file. That belongs to the PORTING layer of the converged design (#1911), not a new primitive type.

    Keeping this open and linking it to #1911 so the author-intent residual is resolved there rather than as a standalone new-primitive design. If you have a concrete case apm compile cannot express today, please add it here.

  4. vlsi commented on Jun 26, 2026

    @vlsi
    Author

    Thanks Daniel Meppiel (@danielmeppiel). Here are two concrete cases apm compile cannot express today, plus two constraints on any fix. Both target Claude, where instructions compile to .claude/rules/<name>.md and are deduplicated out of the context file.

    Case A: author-shipped root content (the Q3 author-intent residual).

    I author a gradle-essentials package and want every consumer who installs it to get this line in their root CLAUDE.md:

    always pass --quiet when an agent calls Gradle, to reduce output

    On the AGENTS.md family this folds into the consumer's root AGENTS.md transitively, so it works. On Claude it lands in the consumer's .claude/rules/ and is deduplicated out of CLAUDE.md. Whether it ever reaches the root CLAUDE.md is decided by the consumer's compile flags (--no-dedup, single_file), not by me as the package author. targets: does not help: it chooses which harness, not where inside it. The package has no way to declare "this fragment belongs in the consumer's root context file."

    Case B: nested context file on Claude (Q2).

    In my own project I want src/test/** guidance to live in src/test/CLAUDE.md, so a session working anywhere under that subtree loads it. With applyTo: "src/test/**" the AGENTS.md family produces src/test/AGENTS.md. Claude instead produces .claude/rules/<name>.md with paths:, never a nested CLAUDE.md. A paths: rule fires only when a matching file is opened, so a read-only session (incident triage, log review, infrastructure diagnostics) that never edits src/test/** never loads the guidance at all.

    Two constraints on whatever mechanism resolves this:

    1. No global, all-or-nothing flag. --no-dedup and compilation.single_file are project-wide switches. --no-dedup duplicates the fragment into both .claude/rules/ and the context file; single_file collapses the whole project into one root file and drops path-scoping for everything. I need per-fragment intent: this one fragment goes to the context file, while the rest of the project keeps distributed .claude/rules placement.

    2. A context-file fragment must not also generate a .claude/rules/ entry. If a fragment is declared for CLAUDE.md, APM should write it there and nowhere else. Emitting both copies loads the same text into the model twice. The point of routing to the context file is always-on placement, so the path-scoped duplicate is pure context bloat.

    So on Claude, Case A and Case B have no expression today, and the one available workaround (--no-dedup) breaks both constraints.

  5. danielmeppiel commented on Jul 1, 2026

    @danielmeppiel
    Collaborator

    Vladimir Sitnikov (@vlsi) thanks for the two concrete cases -- they made the gap precise. Here is where I landed after grounding against the harness docs, and I want your read before we build it.

    Correction to my earlier draft: I first leaned on "absent applyTo = always-on". That was a heuristic, and it was wrong -- omission is ambiguous. The explicit signal already exists in APM's native format (see below), so the fix keys on that, not on omission.

    The real gap

    The problem is not a missing primitive. It is that apm install ports an author's explicit placement intent to the wrong native form on Claude. APM's native instruction format is the VS Code / Copilot .instructions.md format, and that format already distinguishes always-on from file-scoped:

    • Always-on = a dedicated context file (.github/copilot-instructions.md, AGENTS.md, CLAUDE.md) or an .instructions.md with applyTo: "**". (VS Code docs use exactly applyTo: "**" for "project general coding standards".)
    • File-scoped = .instructions.md with a specific glob (applyTo: "src/**/*.ts").

    So the author's intent is explicit. The bug is that APM translates it faithlessly on Claude: a universal applyTo: "**" is written to .claude/rules/ with paths: "**" (path-scoped, lazily loaded, not re-injected after /compact) instead of landing in the always-on CLAUDE.md. On the AGENTS.md family the same content folds into the root context file, which is why it works there and not on Claude.

    Why not a new primitive

    Nine of the ten harnesses APM targets read the AGENTS.md standard: an author ships one fragment and it folds into the consumer's root or nested AGENTS.md, always-on, no per-harness work. The "root = always-on, subdirectory = scoped" semantics are vendor-documented, not something APM invents -- Codex reads AGENTS.md "before doing any work" with the closest nested file winning, and Windsurf/Devin processes AGENTS.md as "root-level = always-on, subdirectory = auto-glob". Claude is the sole holdout -- it ignores AGENTS.md and uses CLAUDE.md + .claude/rules/ instead. So this gap is not an APM defect in the author model; it is one harness not yet supporting the shared standard, plus APM porting to the wrong Claude surface.

    If we answered that with a new APM primitive (an agentsmd / context-file type with a dir: field), we would build a Claude-shaped workaround into the author's model. Wrong direction, for three reasons:

    • Portability over lock-in. The right fix is for harnesses to converge on AGENTS.md. A new primitive that exists only to paper over one harness's non-support entrenches divergence. We port to the standard; we do not glue per-harness verbs.
    • No invented author surface. APM emits canonical upstream formats; it does not invent new frontmatter for authors to learn. applyTo already exists and already carries the intent.
    • UX is the floor. Every new primitive is a new concept an author must learn before shipping. Reusing applyTo keeps authoring to one mental model across all ten targets.

    Proposed behavior

    Key the Claude porter on the explicit applyTo value the author already writes:

    applyTo Author intent Claude destination
    ** (universal) always-on, everywhere root CLAUDE.md (dedup-exempt)
    services/payments/** (directory scope) whole subtree nested services/payments/CLAUDE.md (dedup-exempt)
    **/*.py (file-type filter) when editing Python .claude/rules/<name>.md with paths: (unchanged)

    Examples matching your cases:

    • Case A -- gradle-essentials ships an instruction with applyTo: "**" carrying "always pass --quiet to Gradle". On install it lands in the consumer's root CLAUDE.md, always-on, and is not also written to .claude/rules/.
    • Case B -- an instruction with applyTo: "src/test/**" lands in src/test/CLAUDE.md, loaded for any session working under that subtree, including read-only ones.

    Both constraints you set are met: per-fragment intent (not a global compile flag), and no double-write into both .claude/rules/ and the context file.

    The discriminator

    The split is universal / directory-prefix glob (goes to the context file, always-on or subtree) vs file-type glob (stays a path-scoped rule). APM's compiler already parses the directory prefix out of a glob, so the signal is present -- this is a porting rule, not a new mechanism.

    One honest note (grounded in Claude's docs)

    Claude's memory docs state CLAUDE.md is loaded "in full at launch" (always-on), while .claude/rules/ is scoped to specific file types or subdirectories. They also note CLAUDE.md is treated as "context, not enforced configuration -- to block an action, use a PreToolUse hook". So routing to the context file makes always-on guidance reliably seen; it does not enforce it. That fits your use cases (conventions, triage guidance), and we would not oversell it as enforcement.

    Does keying on applyTo: "**" for always-on and a directory prefix for subtree placement match how you would want to express these, or do you see a case where placement should differ from what the glob says? If the latter, that is the signal we would need for an explicit field.

  6. vlsi commented on Jul 1, 2026

    @vlsi
    Author

    Proposed behavior

    Thanks, it looks understandable, and it looks like it solves the issue.

    Does that include AGENTS.md?
    In other words, does that mean apm instruction with applyTo: services/payments/** would render in services/payments/AGENTS.md?

  7. vlsi commented on Jul 8, 2026

    @vlsi
    Author

    Daniel Meppiel (@danielmeppiel) , I've got a few more questions:

    1. Does APM guarantee the order of "instructions" when producing "context files"?
    2. How does the "Proposed behavior" work for instructions that have multiple applyTo patterns? (e.g. they have an array of patterns or a comma-separated list of patterns)
    3. Will applyTo: ** instruction produce AGENTS.md or an instruction for Copilot?

    Looks like the change is not Claude-specific.

  8. added
    triage/recommended
    and removed
    status/triaged
    on Sep 12, 2026
  9. added
    pillar/consume
    area/compile
    and removed on Nov 12, 2026
  10. danielmeppiel commented on Nov 19, 2026

    @danielmeppiel
    Collaborator

    Vladimir Sitnikov (@vlsi) thank you, and sorry for the long silence. Good news: the platform moved in the right direction. Since v2.1.277, Claude Code reads AGENTS.md natively. Root AGENTS.md files load at session start, and a subdirectory's AGENTS.md loads when Claude opens a file there (docs). One condition: no CLAUDE.md may count, unless that CLAUDE.md imports @AGENTS.md.

    So instead of a Claude-only porting rule, APM will move the Claude target onto the standard. Instructions with applyTo: "**" go to the root AGENTS.md and directory-prefix globs to a nested AGENTS.md, the same output other harnesses get. File-type globs stay in .claude/rules/, and any CLAUDE.md APM writes imports @AGENTS.md. That covers your cases A and B, and it answers your questions: yes, it is the same AGENTS.md placement on every harness, and it is not Claude-specific. This is tracked with a scope record in #3939 (0.38).

    Until then, a workaround for your own project is to add @AGENTS.md to your CLAUDE.md and run apm compile for an AGENTS.md-family target. Closing this in favor of #3939.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/compilearea/multi-targetarea/package-authoringpillar/consumestatus/needs-designtriage/recommendedtype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions