Trilha 3 » 3.1 Skills System
Modulo 3.1

⚡ Skills System

Workflows reutilizaveis como slash commands: discovery, parsing, substituicao de argumentos, execucao inline/fork e integracao MCP.

⏱ ~50 min 📊 6 secoes 🎯 Avancado
1

Skill Lifecycle: Six Stages

Uma skill e um "named, reusable prompt workflow" armazenado como SKILL.md com YAML frontmatter. O lifecycle completo passa por 6 estagios:

1. Discovery

Walk managed/user/project directories. Resolve symlinks para deduplicate.

2. Load

Read SKILL.md. Parse YAML frontmatter. Estima token budget.

3. Parse

Extract fields into Command object. Validate hooks, paths, effort, shell.

4. Substitute

Replace $ARGUMENTS, $1/$name, shell !backtick, ${CLAUDE_SKILL_DIR}.

5. Execute

Run inline (same context) ou fork (isolated sub-agent com own token budget).

6. Inject

Tool result enters conversation. Allowed tools e model override applied.

flowchart LR
D["**Discovery**
Walk managed / user /
project / --add-dir paths.
Read dir entries.
Resolve symlinks."]
L["**Load**
Read SKILL.md.
Parse YAML frontmatter.
Estimate token budget."]
P["**Parse**
Extract all frontmatter
fields into Command
object. Validate hooks,
paths, effort, shell."]
S["**Substitute**
Replace $ARGUMENTS,
$1/$name, shell !backtick,
${CLAUDE_SKILL_DIR},
${CLAUDE_SESSION_ID}."]
E["**Execute**
Run inline (expand into
conversation) or fork
(isolated sub-agent with
own token budget)."]
I["**Inject**
Tool result enters
conversation. Allowed
tools and model override
applied for this turn."]
D --> L --> P --> S --> E --> I
style D fill:#22201d,stroke:#7d9ab8,color:#b8b0a4
style L fill:#22201d,stroke:#7d9ab8,color:#b8b0a4
style P fill:#22201d,stroke:#6e9468,color:#b8b0a4
style S fill:#22201d,stroke:#c47a50,color:#b8b0a4
style E fill:#22201d,stroke:#8e82ad,color:#b8b0a4
style I fill:#22201d,stroke:#6e9468,color:#b8b0a4
                    
2

Four Sources & Priority Order

Skills sao carregadas de 4 fontes com prioridade definida. "When two sources define a skill with the same name, the first one loaded wins." Deduplication usa resolved file paths, nao nomes.

1
Managed / Policy

managed/.claude/skills/ -- Enterprise-controlled, highest priority

2
User

~/.claude/skills/ -- Personal cross-project library

3
Project

.claude/skills/ -- Repository-scoped

4
Bundled

Compiladas no CLI -- Lowest priority

3

SKILL.md Format & Frontmatter

O formato SKILL.md usa YAML frontmatter com 15+ fields que controlam tudo: quais tools a skill pode usar, em qual modelo roda, quando ativa automaticamente.

---
name: "Display Name"
description: "One-line summary"
when_to_use: "Auto-invoke hint"
allowed-tools:
  - Bash(gh:*)
  - Read
  - Write
argument-hint: "[branch] [message]"
arguments: branch message
context: fork
model: claude-opus-4-5
effort: high
version: "1.0.0"
user-invocable: true
paths: src/payments/**
hooks:
  PreToolUse: [...]
shell:
  interpreter: bash
---
# Markdown body with $variable substitution

Frontmatter Field Reference

Field Type Purpose
namestringOverride directory-derived name
allowed-toolslistTool permission patterns
contextforkIsolated sub-agent execution
modelstringModel override for skill
effortlow/med/highThinking budget
pathsglobConditional activation by file pattern
disable-model-invocationboolBlock Skill tool invocation
4

Argument Substitution Pipeline

A substituicao de argumentos segue uma pipeline de 6 passos em ordem definida. Se nenhum placeholder for encontrado, argumentos sao appended automaticamente.

1
Named args: $foo, $bar (from arguments frontmatter)
2
Indexed args: $ARGUMENTS[0], $0, $1
3
Full arg string: $ARGUMENTS
4
Fallback: Se nenhum placeholder encontrado, args appended como ARGUMENTS: ...
5
Shell injection: !`command` ou blocos ```! (local skills only)
6
Special variables: ${CLAUDE_SKILL_DIR}, ${CLAUDE_SESSION_ID}

Exemplo: /myskill "hello world" foo e parseado como ["hello world", "foo"] via shell-quote parsing.

5

MCP Skills & Bundled Skills

MCP Skills (Remote)

  • No shell injection -- !backtick e ```! blocos silently skipped
  • ${CLAUDE_SKILL_DIR} unavailable -- sem directory local
  • ✅ Separate registry em AppState.mcp.commands
  • ✅ Merged via getAllCommands() at invocation
  • 🔒 "MCP skills are remote and untrusted"

Bundled Skills (Built-in)

  • /simplify -- 3 parallel review agents
  • /commit, /remember, /verify
  • /debug, /stuck
  • /skillify -- writes SKILL.md (internal)
  • 🔒 Secure nonce dirs (O_EXCL | O_NOFOLLOW | 0o600)
registerBundledSkill({
  name: 'simplify',
  description: 'Review changed code for reuse, quality, and efficiency.',
  userInvocable: true,
  async getPromptForCommand(args) {
    return [{ type: 'text', text: SIMPLIFY_PROMPT }]
  },
})
6

Permissions, Auto-Allow & Live Reloading

checkPermissions() segue um waterfall de 5 passos:

1. Deny rules: Block se name ou prefix (:*) matches deny list
2. Remote canonical: Auto-allowed (experimental)
3. Allow rules: Proceed se explicit allow matches
4. Safe properties: Auto-allow se sem allowed-tools, model override, hooks, ou paths
5. Ask user: Prompt for permission with suggestions

Live Reloading

O skillChangeDetector monitora directories com chokidar. Quando qualquer SKILL.md muda, debounce de 300ms, fire ConfigChange hooks, e limpa memoization caches. Em Bun, stat-polling substitui FSWatcher (deadlock bug).

7

Conditional Skills & Legacy Support

Conditional Skills (paths-based)

"A skill with a paths frontmatter field is a conditional skill. It is loaded at startup but not surfaced to Claude until the user opens or edits a file whose path matches one of the glob patterns."

---
paths: src/payments/**
description: "Stripe refund workflow"
---

Patterns usam .gitignore syntax. Um ** pattern e tratado como unconditional.

Legacy Support

O diretorio antigo /commands/ (.claude/commands/) ainda funciona com single .md files e skill-name/SKILL.md format, mas novo trabalho deve usar .claude/skills/.

📋 Resumo do Modulo

Skills vivem em skill-name/SKILL.md; directory name vira slash command
4 fontes: managed > user > project > bundled
2 modos de execucao: inline (same context) ou forked (isolated)
MCP skills nunca executam shell injection (hard security boundary)
paths frontmatter faz skills condicionais (invisiveis ate matching file)
Skill listing capped em 1% do context window
Simple skills auto-approved; powerful skills precisam allow rules
Files watched live; no restart needed (chokidar 300ms debounce)
Trilha 3 3.2 Agent System