| name | script-extractor |
| description | Detects inline logic anti-pattern in prompts and identifies opportunities to extract deterministic operations to scripts |
| model | claude-haiku-4-5 |
Script Extractor Skill
Problem: Logic in prompts consumes LLM context on every invocation. Scripts execute outside context, reducing token usage by ~20%.
Impact:
- Inline logic: Consumed in every invocation (thousands of tokens)
- Script abstraction: Zero context cost (executed via Bash)
You analyze agents and skills to identify extraction opportunities and estimate context savings.
detect-inline-logic
Detect inline logic in agent and skill files.
Input:
project_path: Path to Claude Code project root
Process:
- Execute:
scripts/detect-inline-logic.sh "{project_path}" - Scan agents and skills for logic patterns
- Return detection results
Output:
{
"status": "success",
"inline_logic_detected": true,
"total_instances": 15,
"by_file": [
{
"file": ".claude/agents/data-processor.md",
"type": "agent",
"instances": 5,
"patterns": [
{
"pattern_type": "bash_command",
"line_number": 45,
"code_snippet": "grep -r \"pattern\" | awk '{print $1}'",
"severity": "high",
"extraction_candidate": true
},
{
"pattern_type": "algorithm",
"line_number": 78,
"code_snippet": "for each item, calculate sum...",
"severity": "medium",
"extraction_candidate": true
}
]
}
],
"total_lines_of_inline_logic": 127
}
analyze-script-coverage
Calculate what percentage of operations are properly scripted vs inline.
Input:
project_path: Path to Claude Code project root
Process:
- Execute:
scripts/analyze-script-coverage.sh "{project_path}" - Count total operations
- Count scripted operations
- Calculate coverage percentage
Output:
{
"status": "success",
"coverage_analysis": {
"total_operations": 45,
"scripted_operations": 32,
"inline_operations": 13,
"coverage_percentage": 0.71,
"grade": "Good"
},
"breakdown": {
"agents": {
"total": 10,
"scripted": 5,
"inline": 5,
"coverage": 0.50
},
"skills": {
"total": 35,
"scripted": 27,
"inline": 8,
"coverage": 0.77
}
},
"thresholds": {
"excellent": 0.90,
"good": 0.70,
"acceptable": 0.50,
"needs_improvement": 0.30
}
}
identify-extraction-candidates
Identify specific code blocks that should be extracted to scripts.
Input:
project_path: Path to Claude Code project rootinline_logic: Detected inline logic from detect-inline-logic operation
Process:
- Execute:
scripts/identify-extraction-candidates.sh "{project_path}" "{inline_logic_json}" - Rank candidates by extraction value
- Group similar patterns
Output:
{
"status": "success",
"extraction_candidates": [
{
"candidate_id": "data-processor-validation",
"file": ".claude/agents/data-processor.md",
"location": "lines 45-62",
"pattern_type": "data_validation",
"code_size": 18,
"extraction_value": "high",
"reason": "Deterministic validation logic, reused 3 times",
"suggested_script": "scripts/validate-data.sh",
"context_savings": 450
},
{
"candidate_id": "api-client-parsing",
"file": ".claude/skills/api-client/SKILL.md",
"location": "lines 89-103",
"pattern_type": "json_parsing",
"code_size": 15,
"extraction_value": "medium",
"reason": "JSON parsing logic",
"suggested_script": "scripts/parse-api-response.sh",
"context_savings": 375
}
],
"total_candidates": 13,
"high_value_count": 5,
"medium_value_count": 6,
"low_value_count": 2
}
estimate-extraction-effort
Estimate effort required to extract inline logic to scripts.
Input:
project_path: Path to Claude Code project rootextraction_candidates: Candidates from identify-extraction-candidates operation
Process:
- Execute:
scripts/estimate-extraction-effort.sh "{project_path}" "{candidates_json}" - Estimate time per candidate
- Calculate total effort
Output:
{
"status": "success",
"effort_estimates": [
{
"candidate_id": "data-processor-validation",
"complexity": "medium",
"extraction_hours": 2,
"testing_hours": 1,
"total_hours": 3,
"dependencies": ["existing validation scripts"]
}
],
"total_effort": {
"extraction_hours": 24,
"testing_hours": 12,
"total_hours": 36,
"total_days": 4.5
}
}
calculate-script-benefits
Calculate context reduction benefits from script extraction.
Input:
project_path: Path to Claude Code project rootextraction_candidates: Candidates from identify-extraction-candidates operation
Process:
- Execute:
scripts/calculate-script-benefits.sh "{project_path}" "{candidates_json}" - Calculate current context consumed by inline logic
- Project context after extraction
- Calculate reduction
Output:
{
"status": "success",
"benefits": {
"current_inline_tokens": 15000,
"projected_inline_tokens": 3000,
"tokens_saved": 12000,
"reduction_percentage": 0.80,
"description": "80% reduction in inline logic tokens (15K → 3K)"
},
"per_file_impact": [
{
"file": ".claude/agents/data-processor.md",
"current_size": 52000,
"projected_size": 40000,
"reduction": 12000,
"percentage": 0.23
}
],
"roi": {
"extraction_days": 4.5,
"tokens_saved_per_invocation": 12000,
"invocations_to_break_even": 15,
"description": "Pays off after ~15 invocations"
}
}
✅ COMPLETED: Script Extractor
Project: {project_path}
───────────────────────────────────────
Inline Logic: {count} instances ({lines} lines)
Script Coverage: {percentage}% ({grade})
Extraction Candidates: {count} ({high_value} high value)
Context Savings: {tokens} tokens ({percentage}% reduction)
Extraction Effort: {days} days
───────────────────────────────────────
Results returned to: project-auditor agent
No inline logic detected:
{
"status": "success",
"inline_logic_detected": false,
"message": "All operations properly abstracted to scripts"
}
Script execution failed:
{
"status": "error",
"error": "script_failed",
"script": "{script_name}",
"message": "{error_output}"
}
Integration
Invoked By:
- project-auditor agent (Phase 5: Execute - detailed analysis)
Depends On:
- Agent and skill files
- Existing scripts/ directories in skills
Outputs To:
- Anti-patterns list (inline logic detection)
- Recommendations (extraction candidates)
- Context optimization calculator
Design Notes
Inline Logic Patterns Detected:
Bash Commands: Direct shell commands in prompts
Execute: grep -r "pattern" | awk '{print $1}'Algorithms: Step-by-step logic in prompts
1. Read file 2. Parse JSON 3. Filter results 4. Calculate sumData Processing: Transformation logic
For each item: - Extract field - Transform value - Validate formatValidation Logic: Deterministic checks
If field missing: Return error If format invalid: Return error
What IS NOT Inline Logic:
- Orchestration (invoking skills in sequence)
- Workflow phases (INSPECT → ANALYZE → ...)
- User interaction prompts
- Decision trees (which skill to invoke)
Context Impact:
- Inline logic: 500-2000 tokens per operation
- Script reference: 20-50 tokens ("Execute: scripts/foo.sh")
- Savings: 90-95% per operation
Migration Strategy:
- Identify deterministic logic
- Extract to parameterized script
- Replace inline logic with script invocation
- Test script independently
- Update documentation