Skillzwave

Claude Code Skills Deep Dive Part 2

Updated
12 min read

Part 2 of 2: Advanced Patterns. Building on the foundations from Part 1, this guide covers advanced topics: tool permissions, sub-agent orchestration, hook integration, and production optimization strategies.

Prerequisites: This guide assumes familiarity with Part 1: Foundations, including SKILL.md structure and Progressive Disclosure Architecture.

Advanced skill patterns showing interconnected components: tools, sub-agents, hooks, and external integrations
Advanced skills orchestrate tools, sub-agents, and hooks for complex workflows

What You'll Learn

  • Tool permissions and security patterns
  • Sub-agent orchestration for parallel tasks
  • Hook integration for deterministic behavior
  • Production optimization and debugging
  • Error recovery and graceful degradation

Tool Permissions and Security

Tool permissions are the security backbone of skills. They define exactly what actions a skill can perform, following the principle of least privilege.

Tool permission hierarchy showing allowed and restricted tool access patterns
Tool permissions control exactly what actions your skill can perform

Permission Syntax

allowed-tools:
  # Full tool access
  - Read
  - Write
  - Grep

  # Scoped access with patterns
  - Bash(git:*)           # Any git command
  - Bash(npm run:*)       # npm run scripts only
  - Bash(docker ps)       # Specific command only

  # MCP server tools
  - mcp__github__*        # All GitHub MCP tools
  - mcp__slack__post      # Specific Slack action

Security Best Practices

  • Start restrictive — Add permissions only as needed
  • Use patternsBash(git:*) instead of full Bash access
  • Avoid wildcards — Be specific about what you need
  • Document rationale — Explain why each permission is needed

Sub-Agent Orchestration

Complex tasks often benefit from delegation. Sub-agents allow your skill to spawn specialized workers for parallel or sequential operations.

Sub-agent orchestration diagram showing main agent delegating to specialized worker agents
Sub-agents enable parallel execution and specialized task handling

When to Use Sub-Agents

  • Multi-file refactoring across a codebase
  • Parallel test execution or validation
  • Documentation generation for multiple modules
  • Independent tasks that can run concurrently
# Sub-Agent Usage in Skills
When processing multiple files:
1. Identify independent work units
2. Use Task tool to spawn sub-agents
3. Collect and synthesize results
4. Present unified output to user

Example trigger: "Refactor all API endpoints"
→ Spawns sub-agent per endpoint file
→ Each validates changes independently
→ Main agent merges results

Hook Integration

Hooks make AI behavior deterministic and auditable. They execute shell commands at specific points in the Claude Code lifecycle, enabling validation, logging, and enforcement of standards.

Hook integration flow showing pre-tool, post-tool, and notification hooks in the AI workflow
Hooks intercept AI operations for validation, logging, and enforcement

Hook Types

PreToolCall

Validate before tool execution. Can block operations.

PostToolCall

React after tool completes. Ideal for logging.

Notification

Observe without affecting flow. Great for monitoring.

Stop

Trigger on session end. Cleanup and reporting.

Example: Commit Message Validation

# .claude/settings.json
{
  "hooks": {
    "PreToolCall": [
      {
        "matcher": "Bash(git commit:*)",
        "command": "python scripts/validate-commit.py"
      }
    ]
  }
}

Production Optimization

Moving skills from development to production requires attention to performance, reliability, and maintainability.

Performance Checklist

  • Token budget — Keep initial load under 5,000 tokens
  • Lazy references — Point to docs, don't embed them
  • Scoped tools — Minimize tool list for faster parsing
  • Cache strategies — Use file-based caching for expensive operations

Reliability Patterns

  • Graceful degradation — Fall back when services are unavailable
  • Retry logic — Handle transient failures automatically
  • Timeout handling — Set reasonable limits on operations
  • Error context — Provide actionable error messages

Debugging Skills

When skills don't behave as expected, systematic debugging helps identify the issue:

  1. Check tool permissions — Is the required tool allowed?
  2. Verify references — Do all referenced files exist?
  3. Test triggers — Does the activation phrase work?
  4. Review context — Is the skill loading unnecessary content?
  5. Check hooks — Are hooks blocking expected behavior?
# Debug command
claude --debug skill-name

# Verbose logging
CLAUDE_DEBUG=1 claude "trigger phrase"

# Check skill loading
claude /skill info skill-name

Continue Learning

You now have a comprehensive understanding of Claude Code skills, from foundations to advanced patterns. Here are paths to continue your journey:

Ready to Build?

Put your knowledge into practice. Create a skill using the patterns you've learned.