# Custom commands and skills in Claude Code

URL: https://developertoolkit.ai/en/claude-code/automate/custom-commands/
Description: Package repeatable team workflows as Claude Code Agent Skills (SKILL.md): invocation rules, precedence, forked execution, and CI verification.

Custom commands in Claude Code are packaged as Agent Skills under `.claude/skills/<name>/SKILL.md` (with legacy `.claude/commands/<name>.md` files still supported). Each skill becomes a shared `/<name>` workflow with structured frontmatter, invocation controls, supporting scripts, and optional subagent isolation—turning ad-hoc personal prompts into versioned, verifiable team standards.

One engineer's pre-PR checklist catches missing tests and unparameterised queries, while teammates run different prompts and catch those defects only during human review. This guide is for developers tired of pasting the same procedures into chat and tech leads standardising repeatable workflows across an entire repository.

## Skills versus legacy command files

Author every new workflow as a skill under `.claude/skills/<name>/SKILL.md`. Skills follow the open [Agent Skills](https://agentskills.io) standard (also catalogued at [skills.wondel.ai](https://skills.wondel.ai)) so the core instruction body transfers across Claude Code, Codex, and Cursor while supporting Claude-specific extensions such as invocation guards, inline command injection, and forked subagent execution.

| Capability | Legacy `.claude/commands/<name>.md` | Skill `.claude/skills/<name>/SKILL.md` |
| --- | --- | --- |
| Invocation | `/<name>` (subfolders add `:` prefixes) | `/<name>` or frontmatter `name` |
| Supporting files (scripts, templates, refs) | No | Yes, alongside `SKILL.md` |
| Name collision outcome | Overridden by skill | Takes precedence |
| Cross-agent portability | Claude Code only | Open `SKILL.md` standard (drop Claude-only fields when porting) |

Skills conserve context budget: only each skill's short `description` sits in context until invoked, at which point the full body enters the conversation. Write terse standing instructions rather than narrative prose, because every line stays in context across subsequent turns.

## Scopes and precedence rules

Commit team workflows to `.claude/skills/` inside the repository; package cross-repository commands as a namespaced team plugin ([plugins ecosystem](/en/ecosystem/plugins/)).

| Scope | Path | Active in |
| --- | --- | --- |
| Managed (enterprise) | Managed settings skills directory | Every user on organization-managed machines |
| Personal | `~/.claude/skills/<name>/SKILL.md` | Local projects on your machine (not cloud or remote runs) |
| Project | `.claude/skills/<name>/SKILL.md` | Everyone who clones this repository |
| Nested | `<subdir>/.claude/skills/<name>/SKILL.md` | Sessions started in or touching `<subdir>` |
| Plugin | `<plugin>/skills/<name>/SKILL.md` | Enabled repos, namespaced as `/<plugin>:<name>` |

Three precedence invariants prevent silent shadowing:

- **Enterprise beats personal, and personal beats project.** A local `~/.claude/skills/deploy/` silently shadows the team's `.claude/skills/deploy/` on your machine alone.
- **Avoid built-in aliases such as `/review`.** A project skill cannot hijack the built-in `/review` alias for `/code-review`; name team review workflows distinctly (for example `/pre-pr` or `/team-review`).
- **Plugin skills never collide** because their plugin prefix namespaces them automatically.

## Designing an evidence-producing skill

A high-leverage team command runs real repository gates and outputs a fixed evidence structure rather than open-ended commentary.

1. **Create `.claude/skills/pre-pr/SKILL.md`** and align the gate commands with your repository scripts:

   ````markdown
   ---
   description: Run repository merge gates on the current branch and report a structured readiness verdict. Use before opening a pull request.
   disable-model-invocation: true
   allowed-tools: Bash(git diff *) Bash(npm run *)
   ---

   ## Changed files

   !`git diff --stat origin/main...HEAD`

   ## Standing instructions

   1. Run `npm run typecheck`, `npm run lint`, and `npm run test` in order. Record exact commands and exit codes.
   2. On failure, print the first failing file and line. Do not edit source code.
   3. For every modified file under `src/`, identify the covering test or flag the file as untested.
   4. Reply strictly in this format:

      VERDICT: READY | BLOCKED
      | Gate | Command | Exit code |
      Untested files: <list or "none">
      Review first: up to three file:line locations with one reason each
   ````

2. **Parameterise repeatable workflows with named arguments.** Use `$ARGUMENTS` or explicit `arguments` with `argument-hint` (for example `/fix-issue 482`) so teammates see expected inputs in autocomplete.

3. **Commit the skill and protect `.claude/` in `CODEOWNERS`.** Because skills shape agent behaviour and can pre-approve tool rules across every developer machine, review skill edits with the same scrutiny as CI workflows.

## Invocation boundaries, permissions, and forked execution

Three frontmatter controls govern safety and context hygiene. Consult the [official Claude Code documentation](https://code.claude.com/docs) for the complete frontmatter schema and shell-injection settings.

| Frontmatter setting | User invokes | Claude auto-invokes | Best fit |
| --- | --- | --- | --- |
| Default | Yes | Yes | Safe, read-only checklists and reusable reference steps |
| `disable-model-invocation: true` | Yes | No | Anything with side effects: commits, pushes, deploys, messages, `/pre-pr` |
| `user-invocable: false` | No | Yes | Background domain guidance loaded only when relevant |

Understand two critical security and context mechanics before shipping skills to a team:

- **`allowed-tools` grants permissions rather than restricting them.** Listing tools in `allowed-tools` pre-approves them for that invocation turn while leaving all other tools governed by normal policy—and project skill grants can apply even in non-interactive runs without a workspace trust prompt. Use `disallowed-tools` or `permissions.deny` to restrict capabilities, review `.claude/skills/` before running Claude on untrusted repos, and enforce `disableSkillShellExecution` in managed settings when shell injection (`` !`command` ``) must be disabled org-wide.
- **Offload heavy inspection with `context: fork`.** When a command sweeps dozens of files (such as finding every call site of a public API before refactoring), add `context: fork` and `agent: Explore` so the skill runs inside an isolated read-only subagent and returns only a concise summary instead of filling your main session ([custom subagents](/en/claude-code/automate/custom-subagents/)).

**Copy-paste prompt: capture a proven session workflow as a skill**

```text
Turn the workflow we just completed into a project skill at .claude/skills/cut-release/SKILL.md.
Frontmatter: write a concise use-case-first description; set disable-model-invocation: true because it pushes tags; scope allowed-tools strictly to the exact read/git/gh commands used.
Body: terse numbered instructions under 60 lines with zero narration. End with a fixed output block starting with "VERDICT: DONE | STOPPED" plus every command run and its exit code.
Show the draft and wait for my approval before saving.
```

## Proving a skill actually works

Seeing a slash command print text proves only that the file loaded. Verify skills across four objective gates:

1. **Automated frontmatter validation in CI.** Claude Code silently ignores misspelt frontmatter keys or malformed YAML—meaning a typo in `disable-model-invocation` quietly lets Claude auto-trigger a deploy skill. Run a zero-secret CI script on every PR touching `.claude/` that checks opening `---` on line 1, valid YAML parsing, required `description`, and known schema keys, and run `npx @wondelai/harness-audit` to audit skill hygiene alongside hooks and memory ([Harness Audit](/en/harness-audit/)). Protect both `.claude/` and `.github/` under `CODEOWNERS`.
2. **Fresh-session A/B evaluation.** Test three realistic requests in clean sessions with the skill enabled versus disabled (or run automated trigger/output evals when shipping plugin skills). Writing and testing in the same session hides instruction gaps.
3. **Structured, re-runnable output.** Require a fixed verdict and command/exit-code table so reviewers can verify claims in seconds rather than reading transcripts.
4. **Context-budget pruning.** Audit skill token overhead and actual usage periodically (via Claude Code's built-in skill diagnostics) and remove unused skills whose descriptions tax every turn.

## When custom commands and skills misbehave

| Symptom | Likely cause | Recovery |
| --- | --- | --- |
| `/name` missing from menu | Skill lives in an unvisited nested directory or `.claude/skills/` was created mid-session | Reload skills or restart the session; inspect loaded skills via `/skills` |
| Frontmatter guard has no effect | Opening `---` is not on line 1, YAML failed to parse, or a key is misspelt | Run your CI frontmatter linter and launch with `--debug` to view parse errors |
| Teammate gets different behaviour for the same `/name` | A personal copy in `~/.claude/skills/` shadows the committed project skill | Delete or rename the personal skill; personal scope outranks project scope |
| `/review` ignores a custom team command | `/review` is reserved as an alias for built-in `/code-review` | Rename the team skill distinctly (for example `/team-review` or `/pre-pr`) |
| Shell injection aborts the command | An inline `` !`command` `` exited non-zero or hit a permission rule | Handle expected non-zero exits explicitly or pre-approve the safe command in `allowed-tools` |
| Skill influence fades in long sessions | Compaction truncates re-attached skill bodies | Keep skill bodies concise, re-invoke when needed, and move hard invariants into [hooks](/en/claude-code/automate/hooks-automation/) |
| Claude stops auto-selecting the right skill | Too many installed skills exceed the description listing budget | Put the trigger condition first in `description` and disable unused skills |

## Official docs and next steps

Refer to the [official Claude Code documentation](https://code.claude.com/docs) for exact frontmatter fields, plugin evaluation commands, and built-in skills, and browse the open standard at [Agent Skills](https://agentskills.io) and [skills.wondel.ai](https://skills.wondel.ai).

- [Custom subagents](/en/claude-code/automate/custom-subagents/): define dedicated read-only or worktree-isolated specialists for `context: fork` skills.
- [Hooks automation](/en/claude-code/automate/hooks-automation/): enforce non-negotiable rules deterministically instead of relying on skill instructions.
- [Memory system](/en/claude-code/build/memory-system/): decide what belongs in `CLAUDE.md` versus an on-demand skill.
- [Skills ecosystem](/en/ecosystem/skills/): security, supply-chain review, and cross-tool portability across Claude Code, Codex, and Cursor.
