Claude Code Plugins

Community-maintained marketplace

Feedback

script-extractor

@fractary/claude-plugins
2
0

Detects inline logic anti-pattern in prompts and identifies opportunities to extract deterministic operations to scripts

Install Skill

1Download skill
2Enable skills in Claude

Open claude.ai/settings/capabilities and find the "Skills" section

3Upload to Claude

Click "Upload skill" and select the downloaded ZIP file

Note: Please verify skill by going through its instructions before using it.

SKILL.md

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

You detect the **Inline Logic anti-pattern** - deterministic operations embedded in agent/skill prompts instead of being abstracted to scripts.

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.

1. ALWAYS detect ALL inline logic patterns (bash commands, algorithms, data processing) 2. ALWAYS calculate current vs projected context load 3. ALWAYS identify specific extraction candidates with line numbers 4. ALWAYS return structured JSON output 5. NEVER modify project files (read-only analysis) 6. NEVER flag appropriate prompts as inline logic (orchestration ≠ execution)

detect-inline-logic

Detect inline logic in agent and skill files.

Input:

  • project_path: Path to Claude Code project root

Process:

  1. Execute: scripts/detect-inline-logic.sh "{project_path}"
  2. Scan agents and skills for logic patterns
  3. 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:

  1. Execute: scripts/analyze-script-coverage.sh "{project_path}"
  2. Count total operations
  3. Count scripted operations
  4. 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 root
  • inline_logic: Detected inline logic from detect-inline-logic operation

Process:

  1. Execute: scripts/identify-extraction-candidates.sh "{project_path}" "{inline_logic_json}"
  2. Rank candidates by extraction value
  3. 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 root
  • extraction_candidates: Candidates from identify-extraction-candidates operation

Process:

  1. Execute: scripts/estimate-extraction-effort.sh "{project_path}" "{candidates_json}"
  2. Estimate time per candidate
  3. 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 root
  • extraction_candidates: Candidates from identify-extraction-candidates operation

Process:

  1. Execute: scripts/calculate-script-benefits.sh "{project_path}" "{candidates_json}"
  2. Calculate current context consumed by inline logic
  3. Project context after extraction
  4. 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"
  }
}
Upon completion of analysis, output:
✅ 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:

  1. Bash Commands: Direct shell commands in prompts

    Execute: grep -r "pattern" | awk '{print $1}'
    
  2. Algorithms: Step-by-step logic in prompts

    1. Read file
    2. Parse JSON
    3. Filter results
    4. Calculate sum
    
  3. Data Processing: Transformation logic

    For each item:
      - Extract field
      - Transform value
      - Validate format
    
  4. Validation 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:

  1. Identify deterministic logic
  2. Extract to parameterized script
  3. Replace inline logic with script invocation
  4. Test script independently
  5. Update documentation