Detects inline logic anti-pattern in prompts and identifies opportunities to extract deterministic operations to scripts
Detects inline logic anti-patterns in prompts and identifies opportunities to extract deterministic operations to scripts. It triggers when analyzing agents and skills to find bash commands, algorithms, or data processing logic embedded in prompts instead of being abstracted to scripts.
/plugin marketplace add fractary/claude-plugins/plugin install fractary-faber-agent@fractaryThis skill inherits all available tools. When active, it can use any tool Claude has access to.
scripts/analyze-script-coverage.shscripts/calculate-script-benefits.shscripts/detect-inline-logic.shscripts/estimate-extraction-effort.shscripts/identify-extraction-candidates.shProblem: Logic in prompts consumes LLM context on every invocation. Scripts execute outside context, reducing token usage by ~20%.
Impact:
You analyze agents and skills to identify extraction opportunities and estimate context savings. </CONTEXT>
<CRITICAL_RULES>
Detect inline logic in agent and skill files.
Input:
project_path: Path to Claude Code project rootProcess:
scripts/detect-inline-logic.sh "{project_path}"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
}
Calculate what percentage of operations are properly scripted vs inline.
Input:
project_path: Path to Claude Code project rootProcess:
scripts/analyze-script-coverage.sh "{project_path}"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 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 operationProcess:
scripts/identify-extraction-candidates.sh "{project_path}" "{inline_logic_json}"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 effort required to extract inline logic to scripts.
Input:
project_path: Path to Claude Code project rootextraction_candidates: Candidates from identify-extraction-candidates operationProcess:
scripts/estimate-extraction-effort.sh "{project_path}" "{candidates_json}"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 context reduction benefits from script extraction.
Input:
project_path: Path to Claude Code project rootextraction_candidates: Candidates from identify-extraction-candidates operationProcess:
scripts/calculate-script-benefits.sh "{project_path}" "{candidates_json}"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"
}
}
</OPERATIONS>
<DOCUMENTATION>
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
</DOCUMENTATION>
<ERROR_HANDLING>
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}"
}
</ERROR_HANDLING>
Invoked By:
Depends On:
Outputs To:
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 sum
Data Processing: Transformation logic
For each item:
- Extract field
- Transform value
- Validate format
Validation Logic: Deterministic checks
If field missing:
Return error
If format invalid:
Return error
What IS NOT Inline Logic:
Context Impact:
Migration Strategy: