| name | managing-snippets |
| description | Comprehensive guide for managing Claude Code snippets v2.0 - discovering locations, creating snippets from files, searching by name/pattern/description, and validating configurations. Use this skill when users want to create, search, or manage snippet configurations in their Claude Code environment. Updated for LLM-friendly interface with TTY auto-detection. |
Managing Snippets (v2.0)
Snippets auto-inject context when regex patterns match user messages. This skill provides a streamlined workflow for discovering snippet locations, creating snippets, searching configurations, and direct file editing.
About Snippets
Snippets are pattern-triggered context injection files that enhance Claude's capabilities by automatically loading relevant information when specific keywords appear in user prompts. Think of them as "smart bookmarks" that activate based on what you're working on.
What Snippets Provide
- Automatic context loading - Inject relevant documentation when keywords match
- Workflow enhancement - Load domain-specific guidance without manual selection
- Consistency - Ensure same context is available across sessions
- Efficiency - Skip manual skill invocation for frequently-used contexts
When to Use Snippets
- Frequently-used skills that should activate on keywords (e.g., "DOCKER", "TERRAFORM")
- Domain-specific documentation that's needed for specific topics
- Quick-reference material that should load automatically
- Workflow guides tied to specific technologies or tasks
Anatomy of a Snippet
Every snippet consists of two components:
1. config.local.json Entry (Required)
Located at:
/Users/wz/.claude/plugins/marketplaces/warren-claude-code-plugin-marketplace/claude-context-orchestrator/scripts/config.local.json
Structure:
{
"name": "snippet-identifier",
"pattern": "\\b(PATTERN)\\b[.,;:!?]?",
"snippet": ["../snippets/local/category/name/SNIPPET.md"],
"separator": "\n",
"enabled": true
}
Key fields:
name: Unique identifier for the snippetpattern: Regex pattern that triggers the snippet (MUST follow standard format)snippet: Array of file paths to inject (relative to config file)separator: How to join multiple files (usually"\n")enabled: Whether snippet is active (true/false)
2. SNIPPET.md File (Required)
Located in subdirectory under:
/Users/wz/.claude/plugins/marketplaces/warren-claude-code-plugin-marketplace/claude-context-orchestrator/snippets/local/
Structure:
---
name: "Descriptive Name"
description: "When to use this snippet and what it provides"
---
[Content to be injected into context]
Organization: Snippets are organized by category:
snippets/local/communication/- Email, reports, writing templatessnippets/local/documentation/- Guides, references, how-tossnippets/local/development/- Code patterns, debugging workflowssnippets/local/productivity/- Workflow automation, task managementsnippets/local/output-formats/- Formatting styles, templates
CLI v2.0 Overview
The snippets CLI provides four focused commands:
paths- Discover available snippet categories and locationscreate- Create snippets from source files with validationlist/ search - Search snippets by name, pattern, or descriptionvalidate- Verify configuration integrity
Installation:
cd /Users/wz/.claude/plugins/.../scripts
make install # Global: uv tool install
# OR
make dev # Local dev: uv run snippets
Auto-detect modes:
- TTY (terminal): Interactive selection interface
- Non-TTY (piped): JSON output for scripting
Snippet Management Process
Follow these steps in order to effectively manage snippets.
Step 1: Discover Available Locations
Before creating a snippet, explore where snippets can be placed using the paths command.
List all categories:
snippets paths
# OR with JSON output
snippets paths --output json
Filter by keyword:
snippets paths dev # Shows categories matching "dev"
snippets paths email # Shows categories matching "email"
Output:
- Base directory path
- Category names (communication, documentation, development, productivity, output-formats)
- Category descriptions
- Full paths to each category
Step 2: Planning the Pattern
Determine the regex pattern that will trigger your snippet. Patterns must follow the standard format (see Regex Protocol below).
Pattern planning:
- List all keywords that should trigger the snippet
- Convert to ALL CAPS (e.g., "docker" → "DOCKER")
- Handle multi-word patterns (use
_,-, or no separator) - Combine alternatives with
| - Apply standard format:
\b(PATTERN)\b[.,;:!?]?
Examples:
- Single keyword:
\b(DOCKER)\b[.,;:!?]? - Multiple alternatives:
\b(DOCKER|CONTAINER|DOCKERFILE)\b[.,;:!?]? - Multi-word:
\b(BUILD_ARTIFACT)\b[.,;:!?]?
Step 3: Creating a Snippet
Create snippets using the create command, which validates and registers the snippet automatically.
Creation workflow:
Create source SKILL.md file with frontmatter:
--- name: "Docker Best Practices" description: "Use when working with Docker containers, images, and containerization" pattern: "\\b(DOCKER|CONTAINER|DOCKERFILE)\\b[.,;:!?]?" --- # Docker Best Practices [Content here...]Run create command:
snippets create source.md snippets/local/development/docker/SKILL.md # With pattern override snippets create source.md snippets/local/development/docker/SKILL.md \ --pattern "\\b(NEW_PATTERN)\\b[.,;:!?]?" # Force overwrite existing snippets create source.md snippets/local/development/docker/SKILL.md --force
What create does:
- ✅ Validates source file exists
- ✅ Parses YAML frontmatter (name, description, pattern)
- ✅ Validates pattern format (ALL CAPS, proper structure)
- ✅ Validates destination is within snippets/local/
- ✅ Extracts snippet name from destination path
- ✅ Checks destination doesn't already exist (unless --force)
- ✅ Creates destination directory
- ✅ Copies file to destination
- ✅ Registers in config.local.json automatically
Helpful error messages:
- Missing frontmatter → Shows required YAML structure
- Invalid pattern → Explains pattern requirements with examples
- Invalid destination → Shows expected path format
- Missing pattern → Reminds to add --pattern flag or pattern field
Common mistakes to avoid:
- ❌ Using lowercase in pattern
- ❌ Missing
\\bword boundaries (requires double backslash) - ❌ Destination outside snippets/local/ directory
- ❌ Forgetting YAML frontmatter
Step 4: Searching and Inspecting Snippets
Search snippets using enhanced multi-level matching (name → pattern → description).
List all snippets:
snippets # Default: list all (TTY: interactive, piped: JSON)
snippets list # Explicit list command
snippets --output json # Force JSON output
Search by keyword:
snippets docker # Searches name, pattern, and description
snippets kubernetes # Priority: exact name > name contains > pattern > description
Interactive mode (TTY):
- Shows formatted list with match indicators
- Navigate with arrow keys
- Select to open in $EDITOR
- ESC to cancel
Non-interactive mode (piped/JSON):
- JSON output with match_type and match_priority
- Can pipe to jq for filtering
- Suitable for scripting
Match priority ranking:
- Exact name match (priority 1) -
snippets mailfinds snippet named "mail" - Name contains (priority 2) -
snippets dockfinds "docker" - Pattern content (priority 3) -
snippets KUBECTLfinds patterns with KUBECTL - Description match (priority 4) -
snippets "email templates"finds description matches
What to check:
- Enabled status (✓ or ✗)
- Pattern alternatives (does it cover all intended keywords?)
- File paths (do they point to correct locations?)
- Content (read SKILL.md to verify)
Regular audits:
- Review snippets monthly
- Disable unused snippets (edit config.local.json)
- Update patterns based on usage
- Remove outdated content
Step 5: Updating Snippets (Direct File Editing)
Philosophy: v2.0 CLI focuses on search and creation. Updates are done by editing files directly.
Modify existing snippets when:
- Pattern doesn't match expected keywords
- Content is outdated
- Need to enable/disable temporarily
- Want to rename for clarity
Update workflow:
Find the snippet:
snippets docker # Search to locate snippet # OR in interactive mode: select snippet → opens in $EDITORDetermine what needs updating:
- Pattern expansion → Edit config.local.json
- Content modification → Edit SKILL.md directly
- Status change → Edit config.local.json (
enabledfield) - Rename → Edit config.local.json (
namefield)
For pattern updates:
# Edit config.local.json directly vim ~/.claude/plugins/.../scripts/config.local.json # Modify the pattern field { "name": "docker", "pattern": "\\b(DOCKER|CONTAINER|DOCKERFILE|KUBECTL)\\b[.,;:!?]?", # Added KUBECTL ... }For content updates:
# Edit SKILL.md directly vim ~/.claude/plugins/.../snippets/local/development/docker/SKILL.md # Update content while maintaining YAML frontmatterValidate changes:
snippets validate # Check for errors snippets validate --output json # JSON output for scriptingTest:
- Type trigger keyword in new prompt
- Confirm content loads correctly
Context-aware updating: If a snippet failed to load during a session, analyze why:
- Did the pattern not match? → Edit config.local.json to expand pattern
- Was it disabled? → Change
"enabled": falsetotrue - Missing keywords? → Add alternatives to pattern
Step 6: Deleting Snippets (Direct File Editing)
Remove snippets that are:
- No longer needed
- Superseded by other snippets or skills
- Creating conflicts with other patterns
Deletion workflow:
Backup first:
# Create backup of config cp ~/.claude/plugins/.../scripts/config.local.json \ ~/.claude/plugins/.../scripts/config.local.json.backup.$(date +%Y%m%d_%H%M%S) # Backup snippet file cp -r ~/.claude/plugins/.../snippets/local/category/snippet-name \ ~/.claude/plugins/.../backups/snippet-name_$(date +%Y%m%d_%H%M%S)Remove from config.local.json:
vim ~/.claude/plugins/.../scripts/config.local.json # Delete the entire mapping object # Ensure JSON remains valid (check commas)Optionally delete SKILL.md:
rm -rf ~/.claude/plugins/.../snippets/local/category/snippet-nameValidate and verify:
snippets validate # Check JSON is valid snippets # Confirm snippet is gone # Type trigger keyword → should not load
Restoration: If you need to restore:
cp backup/config.local.json.backup.TIMESTAMP config.local.jsoncp -r backup/snippet-name_TIMESTAMP snippets/local/category/snippet-namesnippets validateand test trigger keyword
Regex Protocol (Standard Format)
CRITICAL: All snippet patterns MUST follow this format.
Standard Format
\b(PATTERN)\b[.,;:!?]?
Rules:
- Word boundaries:
\bat start and end - Parentheses: Pattern wrapped in
() - ALL CAPS: Uppercase only (A-Z, 0-9)
- Multi-word: Use
_,-, or no separator (never spaces) - No mixed separators: Can't mix
_and-in same pattern - Optional punctuation:
[.,;:!?]?at end - Alternation: Use
|for multiple keywords
Why Full Punctuation Matters
Users naturally add punctuation when typing. Excluding punctuation causes mismatches:
- ❌ Pattern
[.,;:]?does NOT match "ARTIFACT!" - ✅ Pattern
[.,;:!?]?matches "ARTIFACT!", "ARTIFACT?", "ARTIFACT."
Always use the full set: [.,;:!?]?
Valid Examples
\b(DOCKER)\b[.,;:!?]? # Single word
\b(DOCKER|CONTAINER|DOCKERFILE)\b[.,;:!?]? # Alternation
\b(BUILD_ARTIFACT)\b[.,;:!?]? # Underscore separator
\b(BUILD-ARTIFACT)\b[.,;:!?]? # Hyphen separator
\b(BUILDARTIFACT)\b[.,;:!?]? # No separator
Invalid Examples
\b(docker)\b[.,;:!?]? # ❌ Lowercase
\b(BUILD ARTIFACT)\b[.,;:!?]? # ❌ Space separator
\b(BUILD_ART-IFACT)\b[.,;:!?]? # ❌ Mixed separators
\bDOCKER\b # ❌ Missing parens and punctuation
\b(DOCKER)\b[.,;:]? # ❌ Incomplete punctuation
Pattern Transformation
User input → Standard format:
Convert to ALL CAPS:
- "docker" → "DOCKER"
- "build artifact" → "BUILD_ARTIFACT"
Handle multi-word:
- Choose one separator:
_(preferred),-, or none - Apply consistently throughout pattern
- Choose one separator:
Handle alternation:
- "docker, container, dockerfile" →
(DOCKER|CONTAINER|DOCKERFILE)
- "docker, container, dockerfile" →
Apply standard format:
- Wrap in
\bboundaries - Add parentheses
- Add
[.,;:!?]?for punctuation
- Wrap in
JSON Escaping
IMPORTANT: In config.local.json, backslashes must be doubled:
{
"pattern": "\\b(DOCKER)\\b[.,;:!?]?"
}
Single \b becomes \\b in JSON.
Complete Examples
Example 1: Create Docker Snippet
Step 1: Understand needs
- Trigger: "docker", "container", "dockerfile"
- Provides: Docker best practices and commands
- Frequent use: Yes
Step 2: Plan pattern
- Keywords: DOCKER, CONTAINER, DOCKERFILE
- Pattern:
\b(DOCKER|CONTAINER|DOCKERFILE)\b[.,;:!?]?
Step 3: Create snippet
Create directory:
mkdir -p ~/.claude/plugins/.../snippets/local/development/dockerCreate SNIPPET.md:
--- name: "Docker Best Practices" description: "Use when working with Docker containers, images, and containerization" --- # Docker Best Practices [Content here...]Add to config.local.json:
{ "name": "docker", "pattern": "\\b(DOCKER|CONTAINER|DOCKERFILE)\\b[.,;:!?]?", "snippet": ["../snippets/local/development/docker/SNIPPET.md"], "separator": "\n", "enabled": true }
Step 4: Test
- Type "DOCKER" → snippet loads
- Type "working with containers" → snippet loads
Example 2: Update Pattern After Mismatch
Scenario: User typed "kubectl" but kubernetes snippet didn't load
Step 5: Update pattern
Current pattern:
\b(KUBERNETES|K8S)\b[.,;:!?]?Analysis: Missing "kubectl" keyword
New pattern:
\b(KUBERNETES|K8S|KUBECTL)\b[.,;:!?]?Edit config.local.json:
{ "name": "kubernetes", "pattern": "\\b(KUBERNETES|K8S|KUBECTL)\\b[.,;:!?]?", ... }Test: Type "kubectl" → snippet now loads
Example 3: Delete Unused Snippet
Backup → Remove from config.local.json → Delete SNIPPET.md → Verify
File Locations
- Config:
~/.claude/plugins/.../scripts/config.local.json - Snippets:
~/.claude/plugins/.../snippets/local/{category}/{name}/SNIPPET.md - Categories:
communication/,documentation/,development/,productivity/,output-formats/
Best Practices
- Check architecture first (read config.local.json before creating)
- Pattern in config.local.json, NOT YAML frontmatter
- Use ALL CAPS in patterns with full punctuation:
[.,;:!?]? - Double-escape in JSON:
\\bnot\b - Test after changes
- Backup before deletion
Quick Reference (v2.0)
| Task | Command / Action |
|---|---|
| Discover categories | snippets paths or snippets paths <filter> |
| Create snippet | snippets create source.md snippets/local/category/name/SKILL.md |
| List all snippets | snippets or snippets list |
| Search snippets | snippets <keyword> (searches name/pattern/description) |
| Update pattern | Edit pattern field in config.local.json directly |
| Update content | Edit SKILL.md file directly (or use snippets <name> in TTY → opens $EDITOR) |
| Enable/disable | Change enabled field in config.local.json |
| Delete snippet | 1. Backup files 2. Remove from config.local.json 3. Delete SKILL.md directory |
| Validate config | snippets validate or snippets validate --output json |
| Test pattern | Type trigger keyword in new prompt |
Troubleshooting
| Issue | Fix |
|---|---|
| Not loading | Check enabled: true, pattern matches (ALL CAPS), file path correct |
| Pattern not matching | Verify standard format, use [.,;:!?]?, test with ALL CAPS |
| Too many loading | Check overlapping patterns, disable conflicts |
| JSON errors | Validate syntax, use \\b not \b |
Critical Reminders
Architecture:
- Pattern goes in config.local.json (NOT YAML frontmatter)
- Always read config.local.json before creating snippets
- Double-escape in JSON:
\\b
When User Corrects You: Stop → Read actual files → Understand architecture → Fix all related mistakes → Verify