Skip to content
UXClaim
Design Ops

Pattern Surgeon

AI-powered design pattern refactoring for 9 languages with auto-verification and rollback safety.

What it does

Pattern Surgeon is a Claude Code skill that analyzes your codebase and recommends or applies design patterns (Strategy, Factory, Adapter, Repository, Observer, Dependency Injection) across 9 languages: TypeScript, Python, Java, C#, PHP, Kotlin, Dart, and Swift.

How it works

Point the skill at a file or function. It detects the language automatically, scores candidate patterns against smell-detection rules, and either suggests changes or applies them with a safety checkpoint. Every mutation is verified—if tests or typecheck fail, it auto-reverts to the git snapshot. Never loops; maximum one retry.

Five modes

Suggest: “What pattern fits this?” Refactor: Apply a pattern with auto-verify-or-revert Compare: Score Strategy vs Factory for your code Follow: Match existing patterns in your codebase Greenfield: Implement new code using TDD-first with the right pattern

Use cases

Break apart big if-else chains, reduce service coupling, implement observer patterns in mobile apps, modernize legacy code, onboard teams to consistent patterns, and handle framework idioms (Hilt, Room, Riverpod, BLoC, SwiftUI, Spring, .NET).

Who benefits

Backend and mobile engineers refactoring large services, teams standardizing architecture, code reviewers enforcing patterns, and developers learning design patterns through real examples.

Frequently asked questions

How do I install Pattern Surgeon?
In Claude Code, run `/plugin marketplace add nuhin13/pattern-surgeon` then `/plugin install pattern-surgeon`. Alternatively, use `npx @nuhin13/pattern-surgeon` or `npm install -g @nuhin13/pattern-surgeon`. For teams, commit `.claude/skills/pattern-surgeon` to git so everyone gets it.
What languages does Pattern Surgeon support?
9 languages: TypeScript/JavaScript, Python, Java (Spring Boot), C# (.NET Core), PHP (Laravel), Kotlin (Android/Hilt), Dart (Flutter), and Swift (iOS). Language is auto-detected from package.json, pubspec.yaml, AndroidManifest.xml, Package.swift, and similar markers.
What design patterns can it refactor?
Six patterns: Strategy, Factory, Adapter, Repository, Observer, and Dependency Injection. Each includes smell-detection rules, when-NOT suppression rules, code examples in all 9 languages, and framework-specific idioms (Spring, Hilt, Riverpod, BLoC, Combine, SwiftUI).
How does the auto-revert safety work?
Before any code change, Pattern Surgeon creates a git checkpoint. After editing, it runs verify.sh to check typecheck and tests. If either fails, rollback.sh reverts to the snapshot. Exit code 0 keeps changes; codes 2/3 trigger one auto-retry; code 4 switches to recommend-only mode. Never loops.
Can I use Pattern Surgeon outside Claude Code?
Yes. It works with Codex CLI, Aider, Gemini CLI, Cursor, Windsurf, and Continue. See docs/CROSS-CLI.md for setup. The skill is a plain Markdown file with bash scripts—portable across any Claude-compatible editor.
What exactly can Pattern Surgeon access?
Only files you explicitly point it at (Read tool). It runs verify.sh and checkpoint/rollback scripts (Bash tool) to detect language, test, and revert safely. It never scans files unprompted, makes network requests, or writes without your confirmation. Full source is auditable.
Can I see real refactors it's done?
Yes. Read docs/case-studies/ for production refactors driven by the skill, including scoring matrices, before/after diffs, and verification logs. These show how Pattern Surgeon handles real code complexity.
Is there a test suite I can verify?
Yes. Clone the repo and run `bats tests/scripts/` to run 8 test suites covering all 9 languages and 6 patterns. All safety scripts (verify.sh, checkpoint.sh, rollback.sh) are plain bash—readable and auditable line-by-line.

Glossary

Design pattern
A reusable solution to a common coding problem (e.g., Strategy decouples algorithms; Factory abstracts object creation; Observer decouples event publishers from listeners).
Smell detection
Automatic analysis of code for signs that a pattern would help—e.g., long if-else chains suggest Strategy; tight coupling suggests Factory or Dependency Injection.
Auto-revert
Automatic rollback to a git checkpoint if typecheck or tests fail after refactoring, ensuring code quality is never compromised.
Checkpoint
A git snapshot (HEAD SHA) captured before any code mutation, used as a safe point to revert to if verification fails.

More in Design Ops

All →
Design Ops

Autonomous Development Pipeline

Claude Code skill turning specs into shipped code through adaptive phases with feedforward guides, feedback sensors, and requirement traceability.

0xPuncker
Design Ops

Ibras AI Agent

Claude Code marketplace for building and evaluating AI agents. Install plugins to generate complete Mastra evaluation systems with scorers, datasets, experim...

volfadar
Design Ops

Claude Skills

Production-grade Claude AI skills for stock analysis, prompt engineering, meeting documentation, and UX design with visual-first outputs.

bhrpraju
Design Ops

Propose

Run three parallel design agents with different philosophies to generate ranked approach proposals for any design decision.