--- topic: instructions-gotchas source_keys: - apm-cli-0-28-0-experiments - apm-docs-site - claude-code-memory-docs - cursor-rules-docs - github-copilot-custom-instructions-docs - apm-v0-39-3-changelog - apm-cli-0-39-3-experiments --- Surprising behaviours and source contradictions for the instructions primitive. The section "Re-run on 0.39.3" at the end records what changed when the experiments were repeated on the repo-pinned apm 0.39.3; where it disagrees with an earlier section, it wins. "Verified" means observed with the installed apm 0.28.0 in a throwaway directory outside the repo. Everything else is stated as sourced or inferred. ## Verified failure modes ### Unquoted glob silently widens scope `applyTo: **/*.py` (unquoted) is a YAML alias error. Verified outcome: - `apm compile` and `apm compile --validate` print "Failed to parse" and skip the file, exit 0; the validated-primitive count is one lower. - `apm install` still deploys the file, to `.claude/rules/.md` with no `paths:` frontmatter. A rule meant for Python files becomes an unconditional rule loaded in every session. Nothing errors. - Any frontmatter that is broken YAML (for example `description: [broken`) behaves the same way. - Claude Code itself behaves consistently: invalid frontmatter is ignored and the rule loads without `paths`. Rule for the skill: always quote `applyTo`, and after scaffolding check that the deployed file has the expected `paths:`; a missing frontmatter block is the symptom. ### Validation never fails Missing `description`, missing `applyTo` and an empty body are warnings only. `apm compile --validate` prints "All primitives validated successfully" and exits 0 even for those, and shows none of the warnings. Only a real `apm compile` prints them. `apm install` and `apm audit --ci` print nothing about instruction content. The official docs call `description` and `applyTo` required; the binary does not enforce either. Any enforcement has to live in this repo's own checks. ### Nested files: compile sees them, install does not `.apm/instructions/sub/x.instructions.md` is folded into compiled root files but never deployed natively. A plain `x.md` (no `.instructions` infix) is ignored by both. ### Compile writes nothing when native rules exist (Claude, Copilot, Antigravity) `apm compile --target claude` after an install exits 0, prints "produced no output files" and creates no `CLAUDE.md`. Use `--force-instructions` or compile in a project with no native rules. A test that only checks the exit code passes without testing anything. ### Compile duplicates content for the other targets For cursor, windsurf, kiro, codex (and grok, opencode by source) compile still writes `AGENTS.md` even though native rules exist, so the same instruction reaches the agent twice. ### Install overwrites hand-authored rule files For claude, cursor, windsurf, kiro and antigravity, an existing file at the deployed path is replaced without warning. Copilot skips it and asks for `--force`. ### Empty-source compile In a package with no instruction primitives, plain `apm compile --target claude` prints "No instruction files found in .apm/ directory" and exits 1; `apm compile --clean` exits 0. This matches the apm-workflow compile reference. Exit 0 with no output is a different case: instructions exist but are already deployed natively (above). ## Cursor-specific - Install emits `globs` plus `description` and never `alwaysApply`. Per the Cursor docs a rule with only a `description` is "Apply Intelligently", so an unscoped apm instruction does not become always-on in Cursor (inferred from docs plus verified output; Cursor runtime not tested). - Multiple globs are emitted as a YAML list (Kiro likewise). The Cursor docs show only a comma-separated string. Unverified whether Cursor honours the list form. ## Claude-specific - `description` is dropped, so it can never appear in a `.claude/rules/` file; do not rely on it for Claude Code. Source: the apm source transform and verified deployed output. The apm docs do not state this. - A rule with no `applyTo` becomes a file with no frontmatter and loads at every launch, which costs context. Claude Code guidance is to keep each file short (under 200 lines). - The documented Claude `paths` budget is 1,000 brace-expanded patterns and 4 MiB. ## Contradictions between sources | Point | Official apm docs | Installed 0.28.0 behaviour | |---|---|---| | `description` | Required | Warning only | | `applyTo` | Listed as required and also as optional | Optional, warning only | | Instruction with no `applyTo` | Folded into compiled root files instead of a per-file rule | Still deployed per-file on every rule-directory target (Claude: no frontmatter; Cursor: description only; Windsurf: `always_on`; Kiro: `always`) and also compiled | | Grok deployed name | `.grok/rules/.md` | `.grok/rules/.instructions.md` | | Compile scope | Docs say compile "only handles instructions" | Consistent for content, but compile also emits GEMINI.md and honours the agents_md mode | | Cursor and Windsurf at user scope | Two fetches of the docs disagreed | Source excludes both at user scope; the source was preferred | An earlier version of this topic's schema file described missing `description` and empty content as errors and `skip_instructions` as a config flag; both were wrong for 0.28.0 (warnings; internal variable). ## Unverified - Whether Cursor accepts a YAML list for `globs`. - Whether Copilot ignores unknown frontmatter keys such as `description`; its docs list only `applyTo` and `excludeAgent`. - Runtime behaviour of Windsurf, Kiro and Antigravity on the emitted frontmatter; no downstream docs were fetched. - Windsurf user-scope global rules. - The Context7 step was unavailable (invalid API key), so the registry carries no fresh Context7 pull. Doc pages were summarised by a smaller model before reaching this file and can be lossy. - Apm versions other than 0.28.0 were not tested. 0.38.0 and 0.39.0 changed the Claude layout, moving `**`- and directory-scoped rules into `AGENTS.md` once compiled. The `.claude/rules/` items above may therefore not hold on 0.39.x. See `instructions-target-mapping.md`, "Claude layout in 0.38 and later", and `migration-0-28-to-0-39.md`. ## What belongs in an instruction body From the Claude Code memory docs (`claude-code-memory-docs`): instructions reach Claude as context, not enforced configuration, so adherence rises with specificity and falls with length and contradiction. - Write rules concrete enough to verify: "Use 2-space indentation", "Run `npm test` before committing", "API handlers live in `src/api/handlers/`", not "Format code properly" or "Keep files organized". - Keep to facts Claude should hold every session: build commands, conventions, layout, "always do X" rules. The `/doctor` trim check cuts what Claude can derive from the codebase (directory layouts, dependency lists, architecture overviews) and keeps pitfalls, rationale and conventions that differ from tool defaults. - A multi-step procedure, or guidance that matters for one task, belongs in a skill. Guidance that matters for one part of the codebase belongs in a path-scoped rule. - Something that must happen at a fixed point (before every commit) or must be blocked is a hook or a `permissions.deny` entry, never an instruction: "Settings rules are enforced by the client regardless of what Claude decides to do. CLAUDE.md instructions shape Claude's behavior but are not a hard enforcement layer." - Two instructions that contradict each other make Claude pick one arbitrarily, across user and project files and across rules. - Under 200 lines per file; one topic per file. ## Re-run on 0.39.3 (holocron#273) Observed with the repo-pinned apm 0.39.3 in throwaway packages outside the repo. - **Unquoted or broken frontmatter fails install.** `applyTo: **/*.py` unquoted, or `description: [broken`, makes `apm install` exit 1 with `Rejected frontmatter in ` and deploy nothing. No transaction change is committed. Compile still prints `Failed to parse`, skips the file and exits 0; `--validate` counts it out. The silent widening above no longer happens on install. - **Claude compile layout.** `apm compile --target claude` writes `AGENTS.md` with the instruction bodies and a `CLAUDE.md` that holds only `@AGENTS.md` under the generated header. Compile also warns `applyTo for '' matched no files` when a pattern matches nothing in the project. - **Dedup is per instruction.** Compile omits only the instructions already deployed to `.claude/rules/`. A nested or newly added instruction still reaches `AGENTS.md`, and when every instruction is deployed no `CLAUDE.md` is written. `--force-instructions` puts all of them in. When the compile also serves a target with no dedup (codex), `AGENTS.md` carries every instruction. - **Unscoped rules move to `AGENTS.md` only when compile wrote them there.** Install deploys an unscoped rule to `.claude/rules/.md` with no frontmatter, and a later compile dedups it, so it stays. It moves only when compile actually wrote it into `AGENTS.md`: compile before install, `--force-instructions`, or a no-dedup target in the same compile. The next install then deletes that file and prints `Retired .claude/rules/.md: AGENTS.md now carries it for Claude Code`. A `**/*.py` rule stays in `.claude/rules/`. - **Hand-authored collisions are skipped on Claude too.** A hand-written `.claude/rules/.md` or `.github/instructions/.instructions.md` is kept, with `files skipped -- local files exist, not managed by APM`, exit 0. `apm install --force` overwrites it. The 0.28.0 silent overwrite on Claude is gone. - **Stale cleanup covers every rule target.** Renaming a source deletes the old file on antigravity, claude, copilot, cursor, grok-build, kiro and windsurf. - **Per-target transforms.** Unchanged from 0.28.0 except: Cursor writes several patterns as one comma-separated `globs:` string, not a list; Antigravity writes `trigger: always_on` for an unscoped rule. - **Empty package.** With no `.apm/` content, plain compile exits 1 with `No APM content found to compile`. With skills but no instructions it is still `No instruction files found in .apm/ directory`, exit 1. `--clean` exits 0 in both. - **Unchanged:** `--validate` hides the warnings a real compile prints; a nested file is compiled but never deployed; `description` is dropped on Claude.