Skip to content

Skills and Commands: Reusable Patterns

How to package reusable capabilities as skills and reusable prompt workflows as commands, so agents can load exactly what they need for a task without bloating the default context.

  • 4 min read
  • Theory and practice
  • Day 4 of 7

Theory

Rules give agents your project's persistent ground rules. But not every piece of context belongs in every conversation. Skills and commands are the tools you reach for when you want to package reusable knowledge or prompt templates that get loaded on demand, exactly when you need them, and nowhere else.

The problem: context bloat

If you put everything into your rules file, you end up with a wall of text the agent has to parse on every single interaction. A rule about how to write database migrations doesn't need to be in context when you're asking for help with a CSS layout issue. Too much irrelevant context dilutes attention and slows things down. Skills and commands solve this: they let you keep the default context lean and pull in specialized knowledge exactly when the task calls for it.

Skills: reusable capability descriptions

A skill is a Markdown file that describes how to perform a specific type of task, following your team's patterns and conventions. The agent loads it when the task matches, either automatically (based on the description) or explicitly (when you tell it to use a skill).

Think of a skill as a senior engineer's knowledge for a specific domain, written down so any agent can use it. Good candidates for skills:

  • How to add a new API endpoint in your service (including validation, error handling, and test conventions)
  • How to create a database migration in your stack
  • How to write a new React component following your team's pattern
  • How to add a new CLI command with the right argument parsing conventions

In VS Code and Copilot, skills are .skill.md files stored in .github/skills/. In Claude Code they're referenced in CLAUDE.md. In Cursor, the equivalent is a rules file with a narrow applyTo scope.

The key thing that makes a skill different from a rule: a rule states a constraint ("always use functional components"). A skill describes a workflow ("here's the full process for adding a new component, step by step").

---
name: Add an API endpoint
description: Step-by-step guide for adding a new REST endpoint
---

## When to use this skill
Use this when you need to add a new endpoint to the Express API.

## Steps
1. Define the route in `src/routes/`
2. Create the handler in `src/handlers/` following the existing error handling pattern
3. Add input validation using Zod
4. Write a unit test and an integration test
5. Update the OpenAPI spec in `docs/openapi.yaml`

Commands: reusable prompt templates

A command is a saved prompt you can invoke quickly, often with variables that get filled in at runtime. Instead of rewriting the same prompt every time you want to do a code review, write it once as a command and invoke it with a keyboard shortcut or slash command.

In VS Code and Copilot, commands are .prompt.md files stored in .github/prompts/. Cursor has a built-in commands system. Both support variables like ${file}, ${selection}, and ${input:description}.

---
name: PR review
description: Review a pull request diff for bugs, missing tests, and security issues
---

Review the following diff:

${selection}

Focus on:
- Logic errors and off-by-one bugs
- Missing error handling
- Security issues (injection, insecure defaults)
- Missing test coverage for new branches

Format your response as a numbered list of findings. If nothing stands out, say so.

When you invoke this command with a diff selected, the variable gets filled in automatically and the agent gets the fully-formed prompt.

Skills vs. Rules vs. Commands: when to use each

What you wantUse
A constraint that should always applyRule
A step-by-step workflow for a recurring task typeSkill
A reusable prompt template you invoke explicitlyCommand

Building a library over time

The most effective teams treat skills and commands as a shared asset. When someone on the team writes a good migration skill or a sharp code review command, they commit it to the repo. Over time you build a library of reusable patterns that works with any model, survives tool changes, and onboards new engineers faster than any wiki ever could.

Practice

Run this in a repository you already know, not a toy project. The point is to feel where the practice helps and where it gets in the way on code that has history.

Build one skill and one command for a real project you work on. The goal is to have something genuinely useful at the end, not a toy example.

Part 1: Write a skill

  1. Think about recurring task types in your codebase. Good candidates are tasks you've done at least three times that always follow the same steps: adding an endpoint, creating a component, writing a migration, adding a CLI command.
  2. Pick one. Write a .skill.md (or equivalent for your tool) that walks through the full process step by step. Include: when to use the skill, the specific files to touch, the conventions to follow, and any common mistakes to avoid.
  3. Test it: give the agent a task that matches the skill and see if it follows the workflow. Compare the output to what you'd get without the skill.

Part 2: Write a command

  1. Pick a prompt you rewrite manually and often. Good candidates: code review, writing a commit message from a diff, generating a test file, summarizing what a function does.
  2. Write it as a .prompt.md (or equivalent). Use at least one variable so it's actually reusable across different inputs.
  3. Run it on three different real inputs. Note where it works well and where the prompt needs refinement.

Reflect:

  • How did the skill change the quality or consistency of the agent's output compared to a plain prompt?
  • How much time did writing the skill and command take versus the time they'll save over repeated use?
  • Are there two or three more skills or commands you'd want to add based on this exercise?

The rest of day 4

  1. 01From Prompt Engineering to Context Engineering
  2. 02Rules and Instructions: Persistent Context for Your Agent
  3. 03Skills and Commands: Reusable PatternsYou are here
  4. 04Custom Agents and Personas
  5. 05Rules, Skills, Commands, and Custom Agents: Knowing What to Use When
  6. 06Model Context Protocol (MCP): What It Is and Why It Matters
  7. 07MCP Security: What Can Go Wrong
  8. 08Harness Engineering: Everything Around the Model
Where this comes from

This path is the shortest route to the ideas. AI-Native Software Engineering (O'Reilly Media) is where each one is worked out in full, with the patterns, the trade-offs and the failure modes. The pillars cover the foundations one long essay at a time.