Repository navigation
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>.mdwithpaths:is path-scoped and lazily loaded. Claude pulls it in only when it touches a matching file.- A root
CLAUDE.md/AGENTS.mdis 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 apaths:rule.
Three use cases are blocked:
- Root, always-on. Short cross-cutting rules an agent benefits from on every turn (tool-selection conventions, repo-wide layout, "use the
ghCLI for GitHub operations").applyTo: "**/*"does not help: it still compiles to a rule file and is still deduplicated out of the root file. - 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. - 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 inCLAUDE.md/AGENTS.mdto 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, ordir: "services/payments"for a nested one), and APM writes the content into that directory'sCLAUDE.md/AGENTS.md. - On Claude the content lands in the chosen
CLAUDE.mdand 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.mdfor Codex and OpenCode,GEMINI.md), the primitive maps onto the existing context-file path; nested directories use that harness's nested-AGENTS.mdconvention. - The difference from
instructionsis the destination (a native context file, root or nested), not the scoping strategy.--single-agentscollapses 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 inCLAUDE.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 nestedAGENTS.mdfor fold-into-root targets viaapplyTo:, but for Claude the matching content is deduplicated out of the nestedCLAUDE.mdand 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 tomemory/constitution.md, not a reusable primitive an upstream package can ship throughapm 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
/compactthe 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:
- the Claude-Code deduplication that omits the instructions section from
CLAUDE.md(apm compile --target claude, docsproducer/compile.md, closes [FEATURE] Skip instructions in CLAUDE.md when already deployed to .claude/rules/ #1138 / fix(compile): deduplicate Claude Code instructions (#1138) #1146); - distributed placement driven by
applyTo:(concepts/primitives-and-targets.md, "Where compiled context files land"); - the compatibility matrix where
instructions / claude = nativeresolves to.claude/rules/<name>.md.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Jun 16, 2026
Triage decision
needs-design
Proposed labels
Note:
area/docs-sitewas 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-designissues 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
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 throughpath_security.validate_path_segmentsorensure_path_withinto 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-designis 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-designis 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." }danielmeppiel commentedon Jun 25, 2026
Grounding this against current
apm compilebehavior, then folding it into the design issue #1911.apm compilealready emits native context files beyond.claude/rules:AGENTS.md(vscode/agents families),CLAUDE.md+.claude/structure (claude family),CLAUDE.mdinstead 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 compilecannot express today, please add it here.vlsi commentedon Jun 26, 2026
Thanks Daniel Meppiel (@danielmeppiel). Here are two concrete cases
apm compilecannot express today, plus two constraints on any fix. Both target Claude, where instructions compile to.claude/rules/<name>.mdand are deduplicated out of the context file.Case A: author-shipped root content (the Q3 author-intent residual).
I author a
gradle-essentialspackage and want every consumer who installs it to get this line in their rootCLAUDE.md:On the
AGENTS.mdfamily this folds into the consumer's rootAGENTS.mdtransitively, so it works. On Claude it lands in the consumer's.claude/rules/and is deduplicated out ofCLAUDE.md. Whether it ever reaches the rootCLAUDE.mdis 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 insrc/test/CLAUDE.md, so a session working anywhere under that subtree loads it. WithapplyTo: "src/test/**"theAGENTS.mdfamily producessrc/test/AGENTS.md. Claude instead produces.claude/rules/<name>.mdwithpaths:, never a nestedCLAUDE.md. Apaths:rule fires only when a matching file is opened, so a read-only session (incident triage, log review, infrastructure diagnostics) that never editssrc/test/**never loads the guidance at all.Two constraints on whatever mechanism resolves this:
No global, all-or-nothing flag.
--no-dedupandcompilation.single_fileare project-wide switches.--no-dedupduplicates the fragment into both.claude/rules/and the context file;single_filecollapses 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/rulesplacement.A context-file fragment must not also generate a
.claude/rules/entry. If a fragment is declared forCLAUDE.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.danielmeppiel commentedon Jul 1, 2026
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.
The real gap
The problem is not a missing primitive. It is that
apm installports an author's explicit placement intent to the wrong native form on Claude. APM's native instruction format is the VS Code / Copilot.instructions.mdformat, and that format already distinguishes always-on from file-scoped:.github/copilot-instructions.md,AGENTS.md,CLAUDE.md) or an.instructions.mdwithapplyTo: "**". (VS Code docs use exactlyapplyTo: "**"for "project general coding standards".).instructions.mdwith 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/withpaths: "**"(path-scoped, lazily loaded, not re-injected after/compact) instead of landing in the always-onCLAUDE.md. On theAGENTS.mdfamily 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.mdstandard: an author ships one fragment and it folds into the consumer's root or nestedAGENTS.md, always-on, no per-harness work. The "root = always-on, subdirectory = scoped" semantics are vendor-documented, not something APM invents -- Codex readsAGENTS.md"before doing any work" with the closest nested file winning, and Windsurf/Devin processesAGENTS.mdas "root-level = always-on, subdirectory = auto-glob". Claude is the sole holdout -- it ignoresAGENTS.mdand usesCLAUDE.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-filetype with adir:field), we would build a Claude-shaped workaround into the author's model. Wrong direction, for three reasons: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.applyToalready exists and already carries the intent.applyTokeeps authoring to one mental model across all ten targets.Proposed behavior
Key the Claude porter on the explicit
applyTovalue the author already writes:applyTo**(universal)CLAUDE.md(dedup-exempt)services/payments/**(directory scope)services/payments/CLAUDE.md(dedup-exempt)**/*.py(file-type filter).claude/rules/<name>.mdwithpaths:(unchanged)Examples matching your cases:
gradle-essentialsships an instruction withapplyTo: "**"carrying "always pass--quietto Gradle". On install it lands in the consumer's rootCLAUDE.md, always-on, and is not also written to.claude/rules/.applyTo: "src/test/**"lands insrc/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.mdis loaded "in full at launch" (always-on), while.claude/rules/is scoped to specific file types or subdirectories. They also noteCLAUDE.mdis 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.vlsi commentedon Jul 1, 2026
Thanks, it looks understandable, and it looks like it solves the issue.
Does that include AGENTS.md?
In other words, does that mean
apm instructionwithapplyTo: services/payments/**would render inservices/payments/AGENTS.md?vlsi commentedon Jul 8, 2026
Daniel Meppiel (@danielmeppiel) , I've got a few more questions:
applyTopatterns? (e.g. they have an array of patterns or a comma-separated list of patterns)applyTo: **instruction produce AGENTS.md or an instruction for Copilot?Looks like the change is not Claude-specific.
danielmeppiel commentedon Nov 19, 2026
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.mdnatively. RootAGENTS.mdfiles load at session start, and a subdirectory'sAGENTS.mdloads when Claude opens a file there (docs). One condition: noCLAUDE.mdmay count, unless thatCLAUDE.mdimports@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 rootAGENTS.mdand directory-prefix globs to a nestedAGENTS.md, the same output other harnesses get. File-type globs stay in.claude/rules/, and anyCLAUDE.mdAPM writes imports@AGENTS.md. That covers your cases A and B, and it answers your questions: yes, it is the sameAGENTS.mdplacement 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.mdto yourCLAUDE.mdand runapm compilefor an AGENTS.md-family target. Closing this in favor of #3939.