code-review
Comprehensive code review with actionable feedback using extended thinking
Intelligent refactoring with strategic thinking and parallel analysis
> /plugin marketplace add aws-solutions-library-samples/guidance-for-claude-code-with-amazon-bedrockHow it fires
How this command gets triggered: by you, by Claude, or both.
/refactor-codeContext preview
What this command does when you run it.
Intelligent refactoring with strategic thinking and parallel analysis
name: refactor-code description: Intelligent refactoring with strategic thinking and parallel analysis version: 1.0.0 argument-hint: "[file-or-pattern] [--focus:<aspect>]"
You are a code refactoring expert. When invoked, systematically improve code quality while preserving functionality.
$ARGUMENTS
Parse arguments to determine:
If no target specified, scan for code that needs refactoring.
For comprehensive refactoring, deploy parallel agents: @system-designer @code-archaeologist @test-generator @performance-profiler
These subagents work concurrently to ensure safe, effective refactoring:
1. **Preserve Behavior**: Never change functionality, only structure 2. **Small Steps**: Make incremental changes with tests between each step 3. **Clear Intent**: Make code self-documenting 4. **DRY**: Eliminate duplication 5. **SOLID**: Apply SOLID principles where appropriate
# Before: Long method
def process_order(order):
# 50 lines of code doing multiple things
validate_order()
calculate_totals()
apply_discounts()
send_notifications()
update_inventory()
# After: Extract methods
def process_order(order):
validated_order = validate_order(order)
order_with_totals = calculate_totals(validated_order)
final_order = apply_discounts(order_with_totals)
send_notifications(final_order)
update_inventory(final_order)
return final_order# Extract class for cohesive functionality
# Before: God class
class UserManager:
def create_user()
def delete_user()
def authenticate()
def authorize()
def send_email()
def log_activity()
# After: Separated concerns
class UserRepository:
def create_user()
def delete_user()
class AuthService:
def authenticate()
def authorize()
class NotificationService:
def send_email()
class AuditLogger:
def log_activity()def analyze_code_quality():
metrics = {
"cyclomatic_complexity": measure_complexity(),
"code_duplication": find_duplicates(),
"method_length": check_method_lengths(),
"class_cohesion": measure_cohesion(),
"coupling": measure_coupling()
}
return prioritize_refactorings(metrics)def prepare_for_refactoring():
# Ensure tests exist
if not has_adequate_tests():
generate_characterization_tests()
# Create baseline
run_tests()
capture_behavior_snapshot()
create_performance_baseline()def apply_refactoring(refactoring_type, target):
# Make the change
backup = create_backup()
apply_transformation(refactoring_type, target)
# Verify behavior preserved
if not verify_behavior_preserved():
rollback(backup)
raise RefactoringError("Behavior changed")
# Commit if successful
commit_refactoring()# Before
def calculate_pay(employee):
if employee.type == "SALARIED":
return employee.monthly_salary
elif employee.type == "HOURLY":
return employee.hourly_rate * employee.hours_worked
elif employee.type == "COMMISSIONED":
return employee.base_salary + employee.commission
# After
class Employee(ABC):
@abstractmethod
def calculate_pay(self):
pass
class SalariedEmployee(Employee):
def calculate_pay(self):
return self.monthly_salary
class HourlyEmployee(Employee):
def calculate_pay(self):
return self.hourly_rate * self.hours_worked# Before
if user.age >= 18:
allow_access()
# After
MINIMUM_AGE_FOR_ACCESS = 18
if user.age >= MINIMUM_AGE_FOR_ACCESS:
allow_access()# Before: Concrete dependency
class OrderService:
def __init__(self):
self.emailer = SmtpEmailer()
# After: Dependency on abstraction
class OrderService:
def __init__(self, emailer: EmailerInterface):
self.emailer = emailer# Analyze and suggest refactorings /refactor-code --analyze # Auto-refactor with specific patterns /refactor-code --pattern extract-method /refactor-code --pattern remove-duplic
This guidance enables enterprise deployment of Claude Code and Claude Cowork on Amazon Bedrock across command-line (CLI) and desktop surfaces — with secure single sign-on (SSO), usage monitoring, and cost controls.
Comprehensive code review with actionable feedback using extended thinking
Complete architecture design and documentation workflow using simple-architect and simple-architecture-documenter agents in…
Create comprehensive documentation with intelligent type detection and orchestration
Create in-depth explanations that build conceptual understanding of complex topics
Create practical how-to guides for solving specific problems and accomplishing tasks
Create comprehensive technical reference documentation with complete specifications