Conventions claude

From xiaolai/nlpm · View interactive version

Conventions claude is an AI agent skill from the GitHub repository xiaolai/nlpm. Claude Code artifact schemas: plugin.json, frontmatter, hooks, settings, tools.

How to use this skill

Skill file

Claude Code Conventions

Tool-specific overlay for Claude Code plugin artifacts. Loaded by the scorer and checker when an artifact is classified as Tier 2-Claude (per agents/scorer.md step 3). The universal floor lives in nlpm:conventions; this overlay adds Claude-Code-specific schemas on top.

Last refreshed: 2026-08-02 against current docs (Claude Code ≥ v2.1.218); §2.2, §2.4 and §14 corrected 2026-10-01 against Claude Code 2.1.285. Notation: a + splits $+ARGUMENTS and the dollar-brace variables such as $+{CLAUDE_PLUGIN_ROOT} throughout this file. The real tokens have no +. They are split because Claude Code replaces the contiguous tokens with their values whenever it loads a skill, including when an agent preloads it, so a literal token here would reach the reader as an empty string or a path (§2.4).

Primary authoritative sources:


1. `.claude-plugin/plugin.json`

The plugin manifest.

Required fields:

The manifest is fully optional — artifacts auto-discover from conventional paths, and only name is required when present. Unrecognized top-level fields are ignored with a warning (error only under claude plugin validate --strict).

Optional fields:

NOT plugin.json fields (common mistake):

Artifact path fields (all optional, string or string[]):

Plugin structure note: a bin/ directory in a plugin root puts its executables on the Bash tool's PATH — files there are invokable as bare commands in any Bash call while the plugin is enabled.

Example manifest → reference.md.


2. Commands and Skills — merged surfaces (v2.1.x change)

Critical: as of Claude Code v2.1.x, commands and skills are the same architecture. Both surfaces support the same frontmatter and execution semantics. The recommended canonical path is:

.claude/skills/<name>/SKILL.md     # preferred for new development
.claude/commands/<name>.md         # still works; equivalent behavior

Existing .claude/commands/ files continue to function. New code should prefer the skill layout because it allows companion files (scripts/, references/, examples/) in the same directory.

Authoritative reference: <https://code.claude.com/docs/en/skills.md> (command/skill frontmatter now lives here; the old slash-commands.md page was retired)

2.1 Frontmatter (shared between commands and skills)

Recommended (per official docs, the only recommended frontmatter field — all keys are technically optional):

Optional (universal):

Optional (v2.1.x additions — NEW since pre-2026 conventions):

Boolean frontmatter fields accept yes/no/on/off/1/0 (any case) in addition to true/false (v2.1.218+). The combined description + when_to_use shown in the skill listing is truncated at 1,536 characters — keep triggers within that budget.

2.2 Body conventions

2.3 Dynamic context injection

2.4 String substitutions (valid in command/skill bodies)

Claude Code replaces these tokens in command and skill bodies. Do NOT flag them as undefined variables. Each is written with this file's + split (see Notation at the top); drop the + to get the real token.

| Token | Replaced with |

|---|---|

| $+ARGUMENTS | every argument passed on invocation |

| $+ARGUMENTS[N] | the argument at index N, 0-based |

| $+N (a digit, e.g. $+0) | shorthand for $+ARGUMENTS[N] |

| $+name | a named argument declared in arguments: (§2.1) |

| $+{CLAUDE_SESSION_ID} | the current session ID |

| $+{CLAUDE_EFFORT} | the current effort level |

| $+{CLAUDE_SKILL_DIR} | the directory that holds the skill's SKILL.md |

| $+{CLAUDE_PLUGIN_ROOT} | the plugin's install directory |

| $+{CLAUDE_PLUGIN_DATA} | the plugin's persistent data directory |

| $+{CLAUDE_PROJECT_DIR} | the project directory |

Preloading substitutes too (observed on Claude Code 2.1.285, 2026-10-01): when an agent preloads a skill through skills:, $+ARGUMENTS becomes an empty string and every $+{CLAUDE_…} token above becomes its value; $+N and $+name stay literal because a preload passes no arguments. A backslash protects $+ARGUMENTS but not the braced tokens. A reference skill that describes these tokens must therefore split them as this file does, or its reader sees the substituted values instead of the token names.


3. Shared Partials

Reusable shared partials located in commands/shared/.

Rules:


4. Agent Frontmatter

Agents live in .claude/agents/<name>.md.

The system prompt is the markdown body of the file (in --agents JSON form it is the prompt key). There is no system-prompt frontmatter key — flagging or recommending one is a bug (corrected 2026-06-07 against sub-agents.md).

Documented fields:

Convention / additional fields:

Plugin-shipped agents are restricted: hooks, mcpServers, and permissionMode are ignored for agents distributed inside a plugin (security). Score plugin agents accordingly.

Best practice: include <example> blocks in description. The description is placed in the Agent tool's text on every turn and is the only thing Claude sees when choosing an agent, so examples belong there (not in the body). One well-chosen <example> plus a "Not for …" sentence carries the routing signal; extra examples are allowed but cost always-on context. nlpm R09 deducts 5 points when the description exceeds 1,200 characters.


5. Skills — Claude Code path conventions

Universal SKILL.md spec lives in nlpm:conventions (open spec at agentskills.io). Claude Code uses these path conventions:

Skill discovery paths now support parent-directory and monorepo nested scanning (v2.1.x). Skills from ./parent/.claude/skills/ and ./packages/frontend/.claude/skills/ auto-load. Skills from --add-dir paths also load from .claude/skills/ within added directories.

Supporting files: Same directory as SKILL.md — scripts/, references/, examples/, etc. Reference them from SKILL.md so Claude knows when to load them.

Skill preloading in agents (v2.1.x): Declare skills: [name1, name2] in agent frontmatter to inject full skill content at startup (vs. Claude auto-loading on demand).


6. Rules

Rules live in .claude/rules/<name>.md.

Frontmatter:

Body format:

Budget: Under 500 lines total per rules file.

Naming convention for ordered sets: NN-kebab-name.md (e.g. 01-formatting.md).


7. Hook Events (Claude Code)

Hook events are case-sensitive. Using wrong case silently ignores the hook.

Confirmed against 2026-06-07 docs refresh (hooks.md):

| Event | Trigger | Context fields |

|---|---|---|

| SessionStart | Session begin | source (startup/resume/clear/compact), model |

| SessionEnd | Session end | (trigger only) |

| UserPromptSubmit | User submits a prompt | prompt text |

| PreToolUse | Before any tool call | tool_name, tool_input |

| PostToolUse | After tool call | tool_name, tool_input, tool_output |

| PermissionRequest | When Claude requests permission | tool_name, tool_input, permission_mode |

| Stop | Once per turn | reason (can set decision: block to prevent stopping) |

| StopFailure | Once per turn — Claude failed to complete | reason |

| FileChanged | Per file change | filename, watcher_path |

Beyond the table above, many more events are valid (SubagentStop, PreCompact, Notification, PostToolUseFailure, Setup, SubagentStart, PermissionDenied, PostCompact, TaskCompleted, MessageDisplay, …). Full allow-list → reference.md. Any documented event name is valid even if it post-dates this doc; do NOT flag as unknown — verify against hooks.md rather than penalizing.

Hook types (canonical, all lowercase in JSON):

A command hook may add "shell": "powershell" to run that hook in PowerShell instead of the default shell.

Matcher patterns: string (exact), pipe-separated list (Bash|Edit), or regex (non-alphanumeric chars).

MCP tool naming: mcp__<server>__<tool> (e.g., mcp__memory__write.*). Hook matchers use this format.

Exit codes (command hooks):


8. `hooks.json` Format

Located at .claude/hooks.json or <plugin>/hooks/hooks.json.

Full example, structure rules and optional hook-object fields → reference.md.


9. `.mcp.json`

Claude Code reads MCP server registrations from a standalone JSON file at the repo root (NOT embedded in settings.json like Gemini, NOT inside config.toml like Codex).

Example → reference.md.

Plugin scope: <plugin>/.mcp.json at the plugin root, or inline in plugin.json under mcpServers. (Only the plugin-root form is documented; the older .claude-plugin/.mcp.json variant is not.)


10. CLAUDE.md (memory file)

Four memory scopes load in order (managed policy → user → project → local):

| Scope | Path | Notes |

|---|---|---|

| Managed policy | OS-specific managed path (e.g. /Library/Application Support/ClaudeCode/CLAUDE.md) | org-wide, set by administrators |

| User | ~/.claude/CLAUDE.md | personal, applies to all projects |

| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | shared, committed |

| Local | ./CLAUDE.local.md | gitignored personal overrides for this repo |

Auto-memory is a separate system at ~/.claude/projects/<slug>/memory/ (see §15) — there is no .claude/memory/*.md convention.

Recommended pattern for multi-tool projects (per analysis/multi-tool-design-2026-05.md decision #5): make AGENTS.md the canonical universal memory file and ship no CLAUDE.md. Claude Code 2.1.277+ reads AGENTS.md natively when no CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md sits in the working directory or above it (~/.claude/CLAUDE.md does not count); Codex reads it natively; Gemini/Antigravity can be configured to read it via the context.fileName array. This is how nlpm itself works. A plugin root must not carry a CLAUDE.md at all — claude plugin validate warns that it is not loaded as plugin context.

For Claude Code older than 2.1.277, the compatibility shim is a one-line CLAUDE.md that imports AGENTS.md:

@AGENTS.md

Body conventions when content lives in CLAUDE.md directly:


11. `.claude/settings.json` and `.claude/settings.local.json`

.local.json is gitignored (per-user); the non-local file is shared — never set bypassPermissions: true in the shared file. Field table (incl. autoMemoryEnabled/autoMemoryDirectory, see §15) → reference.md.


12. LSP Servers (`.lsp.json`)

Stable in 2026 (was experimental in 2025). .lsp.json file, or a lspServers object in plugin.json. Required fields command + extensionToLanguage. Full per-server schema → reference.md.


13. Monitors (`monitors/monitors.json`)

Experimental — lives under experimental.monitors (§1); its manifest schema may change between releases while it stabilizes. Plugin background watchers; requires v2.1.105+. Per-entry required name + command + description. Full schema → reference.md.


14. Reference Syntax

Commands referencing shared partials: point at the file by absolute path — "Follow the steps in $+{CLAUDE_PLUGIN_ROOT}/commands/shared/discover.md". Claude Code substitutes $+{CLAUDE_PLUGIN_ROOT} in command, skill and agent bodies; a bare commands/shared/… path does not resolve, because a command is not told where its plugin lives.

Give each partial user-invocable: false and disable-model-invocation: true, so it stays out of the skill listing while commands still read it.

Agents referencing skills in frontmatter:

skills: ["nlpm:conventions", "nlpm:conventions-claude"]

Hooks referencing scripts:

"command": "$+{CLAUDE_PLUGIN_ROOT}/scripts/check.sh"

Always use $+{CLAUDE_PLUGIN_ROOT} for intra-plugin file references. Hardcoded absolute paths break portability.

Cross-plugin skill references use the same plugin:skill format. The plugin must be installed for the reference to resolve.


15. Memory File Conventions (`~/.claude/projects/<slug>/memory/`)

Auto memory (v2.1.59+) lives at ~/.claude/projects/<project-slug>/memory/, toggled by autoMemoryEnabled / relocated by autoMemoryDirectory (§11); individual files need name/description/type frontmatter and an entry in the MEMORY.md index. Full schema, type values and rules → reference.md.


16. Claude Code Tool Catalog

Tool names valid in tools:, allowed-tools:, disallowed-tools:. Never flag a well-formed tool name as "unknown" or "undocumented" — the catalog grows and any string matching Pascal-name or mcp__<server>__<tool> patterns is valid. Key renames: Task → Agent (alias kept); MultiEdit, BashOutput, KillBash removed; TodoWrite default-off (→ Task* family); SlashCommand folded into Skill.

Full catalog — built-in tools, renames/removals, MCP naming → reference.md. Authoritative source: code.claude.com/docs/en/tools-reference.md.


17. Plugin distribution

Marketplace manifest: .claude-plugin/marketplace.json at the marketplace repo root. Required top-level: name, owner (maintainer-info object), plugins. Optional: $schema, description, version, metadata.description, metadata.version, metadata.pluginRoot, forceRemoveDeletedPlugins, allowCrossMarketplaceDependenciesOn, renames. Per-plugin entries may add category, tags, strict, relevance, defaultEnabled. Full schema, source types, and renames/strict semantics → reference.md.

Plugin from URL (v2.1.x): --plugin-url and --plugin-dir flags accept .zip archives.

Namespacing: plugin skills, commands, and agents are all namespaced under the plugin — /my-plugin:hello for skills/commands, my-plugin:code-reviewer in the @-mention typeahead for agents. Prevents conflicts.


18. Scope and uncertainty

This skill covers Claude Code conventions. It does NOT cover:

Resolved in the 2026-08-02 refresh (no longer uncertain):

Still approximate (verify before citing a specific tag):

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.