Reusable logic for categorizing files as Command, Agent, Skill, or Documentation based on structure and content analysis
Analyzes file structure and content to accurately categorize files into:
Commands:
*-command.md or *command.md.claude/commands/ directoryintegration-scan.md)Agents:
*-agent.md or *agent.mdagents-templates/ directorySkills:
SKILL.md or *-SKILL.md or *-skill.mdskills/*/ directoriesDocumentation:
.md filesdocs/ directoryRead the YAML frontmatter (if present) to identify:
Command Indicators:
---
description: "..."
allowed-tools: [...]
author: "..."
version: "X.Y"
---
Skill Indicators:
---
name: skill-name
description: "..."
---
Agent Indicators (less structured, more prose):
## Agent Identity
**Role**: [Agent Role]
**Version**: X.Y.Z
**Purpose**: [Purpose description]
Commands have:
!)allowed-tools restrictionsAgents have:
Skills have:
Documentation has:
Scan content for category-specific keywords:
Command Keywords:
!bash, !git, !npm, etc. (shell commands)Agent Keywords:
Skill Keywords:
Documentation Keywords:
function categorizeFile(filePath, content):
// Phase 1: Filename and location
if filename matches command patterns OR in .claude/commands/:
category = "Command"
confidence = "High"
else if filename == "SKILL.md" OR in skills/*/:
category = "Skill"
confidence = "High"
else if in agents-templates/:
category = "Agent"
confidence = "High"
else if in docs/:
category = "Documentation"
confidence = "Medium"
// Phase 2: Frontmatter analysis (refine)
frontmatter = extractYAML(content)
if frontmatter contains "allowed-tools" AND "version":
category = "Command"
confidence = "High"
else if frontmatter contains "name" (no allowed-tools):
category = "Skill"
confidence = "High"
// Phase 3: Content structure (if still uncertain)
if confidence != "High":
if content contains "## Agent Identity":
category = "Agent"
confidence = "High"
else if content contains "## When to Use":
category = "Skill"
confidence = "Medium"
else if content contains "!bash" OR "!git":
category = "Command"
confidence = "Medium"
// Phase 4: Fallback
if category == null:
category = "Other"
confidence = "Low"
reason = "Unable to determine category, manual review needed"
return {category, confidence, reasoning}
For each categorized file, return:
### [Filename]
- **Category**: [Command|Agent|Skill|Documentation|Other]
- **Confidence**: [High|Medium|Low]
- **Reasoning**: [Why this category was assigned]
- **Frontmatter**: [✅ Valid | ⚠️ Malformed | ❌ Missing]
- **Required Fields**: [List of found/missing fields]
- **Recommended Location**: [Target directory path]
Input:
File: USING-GIT-WORKTREES-SKILL.md
Content:
---
name: using-git-worktrees
description: Creates isolated git worktrees...
---
# Using Git Worktrees
## When to Use
...
Output:
### USING-GIT-WORKTREES-SKILL.md
- **Category**: Skill
- **Confidence**: High
- **Reasoning**: Filename matches skill pattern, frontmatter has 'name' field, content has "When to Use" section
- **Frontmatter**: ✅ Valid
- **Required Fields**: name ✅, description ✅
- **Recommended Location**: skills/using-git-worktrees/SKILL.md
Input:
File: integration-scan.md
Content:
---
description: "Scan and categorize incoming files"
allowed-tools: ["Read", "Bash(find)"]
author: "Claude Command and Control"
version: "1.0"
---
# Integration Scan
## Purpose
...
Output:
### integration-scan.md
- **Category**: Command
- **Confidence**: High
- **Reasoning**: Filename uses verb-noun pattern, frontmatter has 'allowed-tools' and 'version'
- **Frontmatter**: ✅ Valid
- **Required Fields**: description ✅, allowed-tools ✅, author ✅, version ✅
- **Recommended Location**: .claude/commands/integration-scan.md
Input:
File: notes.md
Content:
# Random Notes
Some thoughts about the project...
Output:
### notes.md
- **Category**: Other
- **Confidence**: Low
- **Reasoning**: No frontmatter, no structural indicators, generic content
- **Frontmatter**: ❌ Missing
- **Required Fields**: N/A
- **Recommended Location**: Manual review required
/integration-scan - Primary categorization logic/integration-process - Determines target directory/integration-validate - Validates category-specific structure# In integration-scan command
For each file in /INTEGRATION/incoming:
1. Read file content
2. Use file-categorization skill
3. Extract category and confidence
4. Include in scan report
5. Mark for processing if High confidence
6. Flag for review if Medium/Low confidence
Issue: YAML syntax error
Action: Note in categorization output
Category: "Other" with reason "Invalid frontmatter"
Recommendation: Fix YAML before processing
Issue: Filename says "command" but structure says "skill"
Action: Confidence = "Medium"
Reasoning: "Filename and content indicators conflict"
Recommendation: Manual review
Issue: File is empty or too short (<100 chars)
Action: Category = "Other"
Confidence: "Low"
Reasoning: "Insufficient content for categorization"
Test with:
Expected accuracy:
1.0 (2025-11-23)
Skill Status: Production Ready Accuracy Target: >95% for High confidence categorizations Dependencies: None (standalone logic)