Skip to main content
Module 4: Mastery 5 / 6
Advanced S23 Custom Agents Skills

Custom Agents & Skills

Build your own .md-based extensions for specialized workflows.

March 20, 2026 20 min read

What You’ll Learn

Claude Code is not a fixed product. It is an extensible platform. By dropping Markdown files into specific directories, you add entirely new capabilities — slash commands, specialized reviewers, automated workflows, domain-specific assistants.

By the end, you’ll understand:

  • The difference between skills and agents
  • How to write a skill (a workflow you or Claude can invoke)
  • How to write an agent (a subagent Claude delegates to)
  • Design patterns for both
  • How to restrict tools for safety
  • The lifecycle from invocation to execution

The Problem

Every team has workflows. Deploy procedures, review checklists, testing protocols, onboarding guides. This knowledge usually lives in two places: documentation nobody reads, and one person’s head.

"How do we deploy?"        → Ask Sarah
"What's our PR checklist?" → It's in the wiki... somewhere
"Database migrations?"     → Dave wrote a script, check his home dir

What if this knowledge were AI-executable instructions — not just documentation, but instructions the AI follows step by step, every time? That is what custom agents and skills do.

How It Works

Skills vs Agents

┌──────────────────────────────────────────────────────┐
│  Skills                          Agents (subagents)   │
│                                                       │
│  Invoked by you (/deploy) or     Delegated by Claude  │
│  loaded by Claude when the       through the Agent    │
│  description matches             tool, or requested   │
│                                  by you (@-mention)   │
│                                                       │
│  Runs in the main conversation   Runs in its own      │
│  (instructions injected)         context window and   │
│                                  returns a summary    │
│                                                       │
│  Location:                       Location:            │
│  .claude/skills/<name>/SKILL.md  .claude/agents/      │
│                                    <name>.md          │
└──────────────────────────────────────────────────────┘
AspectSkillAgent
Invoked byYou (/skill-name), or Claude when its description matchesClaude via the Agent tool; you can name or @-mention one
ContextLoaded into the main conversation (or a forked subagent with context: fork)Its own context window; only the result returns
PurposeStep-by-step workflows, templates, reference knowledgeSpecialized roles (reviewer, explorer)
Tool controlallowed-tools pre-approves tools for the invoking turntools allowlist or disallowedTools denylist
Location.claude/skills/<name>/SKILL.md.claude/agents/<name>.md
ScopeBroad (complete workflows)Focused (single responsibility)

Both also work at the user level (~/.claude/skills/, ~/.claude/agents/) and inside plugins. Older custom commands in .claude/commands/ still work and create the same /name; skills add a folder for supporting files and control over who can invoke them.

Skill Anatomy

A skill is a SKILL.md file: YAML frontmatter that tells Claude Code how to treat it, followed by Markdown instructions. Save this one as .claude/skills/deploy/SKILL.md --- the folder name becomes the /deploy command:

---
name: deploy
description: Deploy the application to production with safety checks
disable-model-invocation: true
---

# Deploy

1. Run `git status` to check for uncommitted changes
2. Run the full test suite with `npm test`
3. If tests fail, stop and report the failures
4. Run `npm run build` and verify no errors
5. Show the user: test results, build size, files changed
6. Ask: "Ready to deploy? [yes/no]"
7. Only if confirmed: run `git push origin main`
8. Report deployment status

## Rules
- NEVER push without user confirmation
- If any step fails, stop and report

The opening --- must be the file’s first line, or Claude Code treats the whole file as instructions. description is what Claude reads to decide when a skill applies, so put the key use case first. disable-model-invocation: true keeps Claude from starting a workflow with side effects on its own: you run it with /deploy, and Claude can’t decide to deploy because the code looks ready.

Agent Anatomy

An agent defines a specialized role that Claude can delegate to as a subagent. Save this as .claude/agents/security-reviewer.md:

---
name: security-reviewer
description: Reviews code changes for security vulnerabilities. Use after changes to authentication, input handling, or data access.
tools: Read, Glob, Grep
model: sonnet
---

You are a security-focused code reviewer. Be thorough
but avoid false positives.

## Checklist
- SQL injection: raw queries with user input
- XSS: unescaped output in templates
- Auth bypass: missing middleware on protected routes
- Secrets: hardcoded API keys, passwords, tokens
- Path traversal: unsanitized file paths
- SSRF: user-controlled URLs in server requests

## Output Format
For each finding: file, line, severity, issue, fix.
If clean: "No security issues found." and list what you checked.

Only name and description are required. The Markdown body becomes the subagent’s system prompt. The tools field is what actually restricts it: this reviewer gets Read, Glob, and Grep and nothing else. model chooses the model it runs on (sonnet, opus, haiku, fable, a full model ID, or inherit).

When Claude delegates, the call looks like this:

{
  "type": "tool_use",
  "name": "Agent",
  "input": {
    "subagent_type": "security-reviewer",
    "description": "Security review of src/api",
    "prompt": "Review the changes in src/api/ for security issues"
  }
}

You can also ask for an agent by name (“Use the security-reviewer agent on these changes”), @-mention it to guarantee it runs, or start a whole session as that agent with claude --agent security-reviewer.

The Skill Lifecycle

┌──────────────────────────────────────────────────────┐
│  1. Session starts: Claude Code discovers skills      │
│     (~/.claude/skills, .claude/skills, plugins)       │
│     ▼                                                 │
│  2. Each skill's description is listed for Claude     │
│     (unless disable-model-invocation: true)           │
│     ▼                                                 │
│  3. You type /deploy, or Claude decides a skill fits  │
│     ▼                                                 │
│  4. The rendered SKILL.md enters the conversation     │
│     as one message and stays for later turns          │
│     ▼                                                 │
│  5. Claude follows the steps with its normal tools    │
│     (allowed-tools pre-approves some for that turn)   │
│     ▼                                                 │
│  6. Workflow completes (or you interrupt)             │
└──────────────────────────────────────────────────────┘

Skill Design Patterns

Pattern 1: Step-by-Step Workflow

The most common pattern. A numbered sequence of actions:

## Steps
1. Check preconditions
2. Gather information
3. Present plan to user
4. Execute with safety checks
5. Verify results
6. Report summary

Pattern 2: Decision Tree

For workflows that branch based on conditions:

## Process

Check the project type:

- If `package.json` exists → Node.js project
  - If `tsconfig.json` exists → TypeScript
    - Use `npx tsc --noEmit` for type checking
  - Else → JavaScript
    - Use `node --check` for syntax validation

- If `requirements.txt` exists → Python project
  - Use `python -m py_compile` for syntax checking

- If `Cargo.toml` exists → Rust project
  - Use `cargo check` for compilation checking

Pattern 3: Template-Based Output

For skills that generate structured content:

## Output Template

Generate a changelog entry using this format:

### [version] - YYYY-MM-DD

#### Added
- New features

#### Changed
- Changes to existing features

#### Fixed
- Bug fixes

Fill each section by analyzing git commits since the last tag.

Agent Design Patterns

Pattern: Specialized Reviewer

---
name: performance-reviewer
description: Reviews code for performance problems. Use when a change touches database access, list endpoints, or hot loops.
tools: Read, Glob, Grep
---

Analyze code for performance issues.

## Check For
- N+1 queries in database access patterns
- Missing pagination on list endpoints
- Unbounded array operations (map/filter on large datasets)
- Missing indexes suggested by query patterns
- Synchronous operations that should be async

Pattern: Explorer with Structured Output

---
name: architecture-explorer
description: Maps the architecture of an unfamiliar codebase. Use before planning changes in code you haven't read.
tools: Read, Glob, Grep
model: haiku
---

Map the architecture of this codebase.

## Output Format
- Entry points (main files, index files)
- Dependency graph (what imports what)
- Data flow (where data enters, transforms, exits)
- External dependencies (APIs, databases, services)

The explorer runs on Haiku because mapping a codebase is high-volume reading, not deep reasoning (Session 21).

Tool Restrictions

Restricting an agent’s tools follows the principle of least privilege. A reviewer should not edit code. An explorer should not run commands. Put the restriction in frontmatter, not in prose --- a “Tools: Read only” line in the body is just an instruction, while the tools field removes everything else:

---
name: security-reviewer
description: Reviews code changes for security vulnerabilities
tools: Read, Glob, Grep          # allowlist: only these tools
# disallowedTools: Write, Edit   # or: inherit everything except these
---

With this allowlist the reviewer can’t edit files, run commands, or spawn subagents of its own (subagents can otherwise nest up to three levels deep by default). On macOS, Linux, and WSL, listing Glob and Grep without Bash also gives this subagent the dedicated search tools. For skills, allowed-tools only pre-approves tools for the turn that invokes the skill; it does not take any tools away. To block tools, use permission deny rules, or disallowed-tools while a skill is active.

Key Insight

Custom agents and skills encode your team’s workflow knowledge. They turn tribal knowledge into repeatable, consistent AI behavior.

The difference between a mediocre Claude Code setup and a powerful one is not the model — it is the quality of the skills and agents. A well-written deploy skill means every deploy follows the same safety checks. A well-written security reviewer means every PR gets the same scrutiny.

This is “infrastructure as code” applied to AI workflows: workflows as Markdown. No compilation, no framework, no deployment. Drop a file, gain a capability.

Think about what your team does repeatedly:

  • Code reviews with specific checklists
  • Deploy procedures with safety gates
  • Data migration protocols
  • Onboarding new team members to the codebase

Each one can become a skill or agent that runs the same way every time, no matter who triggers it.

Hands-On Example

Build a custom review skill and a security reviewer agent.

The Review Skill

Create .claude/skills/team-review/SKILL.md:

---
description: Review the current branch against main with the team checklist and a security pass. Use when asked to review a branch or prepare a PR.
---

# Team Review

Review the current branch's changes against the base branch.

## Steps

1. Run `git diff main...HEAD --stat` to see changed files
2. For each changed file:
   - Read the full diff with `git diff main...HEAD -- <file>`
   - Check for:
     - Missing error handling
     - Hardcoded values that should be config
     - Functions longer than 50 lines
     - Missing type annotations
     - Console.log or debug statements left in
3. Use the security-reviewer agent on the changed files
4. Compile all findings into a report:

## Report Format

### Summary
[1-2 sentence overview]

### Findings
| File | Line | Severity | Issue |
|------|------|----------|-------|

### Security Review
[Output from security-reviewer agent]

### Recommendation
[Approve / Request Changes / Needs Discussion]

Why not call it review? Claude Code already uses /review as an alias of its bundled /code-review skill, so give team skills distinct names. This skill leaves out disable-model-invocation: a review only reads code, so letting Claude load it when you ask it to review your branch is safe.

The Security Reviewer Agent

Create .claude/agents/security-reviewer.md:

---
name: security-reviewer
description: Reviews code changes for security vulnerabilities. Use after changes to authentication, input handling, or data access.
tools: Read, Glob, Grep
---

You review code for security vulnerabilities. Be thorough
but avoid false positives. Only flag issues you are
confident about.

## Checklist
- [ ] No SQL injection (parameterized queries)
- [ ] No XSS (output escaping)
- [ ] No hardcoded secrets
- [ ] Auth middleware on protected routes
- [ ] Input validation on user-facing endpoints
- [ ] No path traversal in file operations

## Output
List findings with file, line, severity, and fix.
If clean, state "No security issues found."

Now type /team-review: Claude follows the skill, delegates the security pass to the security-reviewer subagent, and produces a structured report. Every review is consistent, regardless of who runs it.

What Changed

Without ExtensionsWith Custom Agents & Skills
Workflows live in documentationWorkflows are AI-executable Markdown
Consistency depends on who runs itSame steps every time
New team members need trainingSkills encode the training
Reviews vary by reviewerAgents apply the same checklist
Tribal knowledge lives in people’s headsKnowledge lives in version-controlled files
Adding capabilities requires codeAdding capabilities requires a Markdown file

Next Session

You now have the tools to extend Claude Code with your own workflows. Session 24 brings it all together with Production Patterns — moving from a personal productivity tool to a team-wide platform, with observability, CI/CD integration, cost management, and the maturity model for scaling AI-assisted development.