Task 3.2
Commands & Skills
When to use slash commands vs isolated skills
📘What You Need to Know
Commands: Shared Prompt Templates
Custom slash commands live in .claude/commands/ as Markdown files. Each file becomes a command you invoke with a leading slash — for example, security-review.md becomes /security-review. Commands are reusable prompt templates that standardize team workflows: code reviews, release checklists, or onboarding steps.
Crucially, commands run in the current session context. They share the same context window as your ongoing conversation. That makes them fast and convenient for quick, one-step actions, but it also means any verbose output or exploratory work pollutes your main session.
- •Location: .claude/commands/*.md
- •Invocation: /command-name [arguments]
- •Context: same session, same context window
- •Sharing: committed to git for team-wide consistency
# .claude/commands/security-review.md
Review the following code for:
- SQL injection
- XSS vulnerabilities
- Authentication bypass
Check files: $ARGUMENTS
Output format: severity, file, line, descriptionSkills: Isolated Complex Operations
Skills live in .claude/skills/ as SKILL.md files with YAML frontmatter. They are designed for complex operations that need isolation from your main session. The context: fork frontmatter field tells Claude Code to fork execution into a separate context, preventing a large refactor or deep exploration from consuming or polluting your primary conversation.
Skills also support allowed-tools to restrict which tools the skill can access — for example, limiting a review skill to Read and Grep only, preventing accidental file edits during analysis. The argument-hint field describes expected arguments so users know how to invoke the skill correctly.
---
name: refactor-to-di
description: Refactor a module to use dependency injection
context: fork
allowed-tools: [Read, Edit, Grep]
argument-hint: <module-path>
---
Refactor the module at $ARGUMENTS to use dependency injection.
Preserve all existing behavior and update tests accordingly.context: fork — Why Isolation Matters
When you run a complex skill with context: fork, Claude executes the work in a fresh, isolated context. Only the essential results return to your main session — not every intermediate file read, failed attempt, or verbose reasoning step. This prevents context degradation in long sessions where Claude starts forgetting earlier constraints.
Think of it like opening a new browser window with only the tabs you need, instead of piling more tabs onto an already crowded window. For a multi-file dependency injection refactor across dozens of files, isolation keeps your main session clean so you can continue other work afterward.
Simple, no isolation needed → command. Complex, needs isolation → skill with context: fork.
allowed-tools — Restricting Skill Capabilities
Without allowed-tools restrictions, a skill inherits broad tool access — including Write, Edit, and Bash. For read-only operations like security audits or architecture reviews, you should restrict tools to [Read, Grep] so the skill cannot accidentally modify files. For refactors, you might allow [Read, Edit, Grep] but exclude Bash to prevent unintended shell commands.
The exam tests whether you understand that skills without tool restrictions can access more than intended. Always match allowed-tools to the skill's purpose: read-only analysis gets read-only tools; implementation skills get edit tools.
Skills without allowed-tools can modify files or run shell commands you did not intend. Restrict tools to match the skill's purpose.
Decision Framework: Command vs Skill
Use a command when the task is quick, well-defined, and benefits from sharing the current session context — "run lint and show errors," "format this file," or "summarize this PR." Use a skill when the task is complex, multi-step, or produces verbose intermediate work that would clutter your session — "refactor this module to use dependency injection," "audit the entire codebase for security issues," or "explore three architectural approaches."
Commands are like sticky notes on your desk: fast, visible, part of your current workflow. Skills are like delegating to a colleague in a separate room: they do the heavy work and report back with results, keeping your desk clean.
⚠️Exam Traps
Trap: Using commands for complex tasks that need context isolation
Why it's wrong: Commands share the current session context — verbose multi-file work pollutes the main thread and causes context degradation.
Trap: Not specifying allowed-tools in skills
Why it's wrong: Skills without tool restrictions can access Write, Edit, and Bash even for read-only analysis tasks.
Trap: Using a skill with context: fork for a one-line lint check
Why it's wrong: Forking context adds overhead for trivial tasks that benefit from staying in the current session.
Trap: Confusing .claude/commands/ with .claude/rules/
Why it's wrong: Commands are user-invoked slash templates; rules are auto-loaded based on file globs.
✓Concept Check
You need to refactor a payment module to use dependency injection — a complex, multi-file change that will involve reading many files and iterative edits. What should you use?
🔨Build Exercise
Intermediate40 minutesCreate a Command and a Skill
What you'll learn
- •Build a team-shared slash command for quick actions
- •Build an isolated skill with context: fork and allowed-tools
- •Apply the command vs skill decision framework