"매 LLM agent 가 codebase-wide refactoring 을 매 propose / apply / verify 하는 workflow." 2026 현재 매 Claude Code (Opus 4.7), Cursor (Composer), Aider, Continue, Codex CLI 등이 매 multi-file edit + test loop 를 자동화. 매 핵심은 매 deterministic checks (test, type, lint) 로 매 LLM 의 stochasticity 를 매 제어. 매 "AI 가 짜준다"가 아닌 매 "AI 가 propose, CI 가 verify".
매 핵심
매 effective workflow
Plan → Apply → Verify → Commit: 매 매 step 마다 매 human 또는 매 automated gate.
Small diffs: 매 100-300 lines / commit. 매 1000+ line PR 은 매 review 불가능.
Test as oracle: 매 LLM 의 output 을 매 existing test suite 로 검증. 매 test 없으면 매 refactoring 시도 X.
Type-driven: 매 TS / Python (mypy/pyright) / Rust 등 매 strict typing 이 매 hallucination 을 매 catch.
매 적합 task
Rename / move (매 IDE refactor 와 비슷하나 매 cross-language).
Library migration (매 Express → Fastify, 매 enzyme → RTL, 매 moment → date-fns).
API surface 변경의 매 callsite 일괄 업데이트.
Style 통일 (매 callback → async/await, 매 class → hooks).
매 dead code 제거.
매 부적합 task
매 architectural redesign — 매 human 의 design 결정 필요.
매 perf-critical hot path — 매 measurement 없이 매 LLM 의 "looks faster" 신뢰 X.
매 security-sensitive (auth, crypto) — 매 human review 필수.
매 응용
Legacy codebase 의 점진적 modernization.
Mass dependency upgrade.
Test coverage 가속.
💻 패턴
1) Claude Code 의 대규모 rename
claude
> Rename `getUserData` to `fetchUserProfile` across the repo.
> Update all callsites, tests, and JSDoc.
> Run `npm test` after.
2) Plan-first prompt (Opus 4.7)
Before editing, output a numbered PLAN of files & changes.
Wait for "approved" before applying any edit.
After each file, run `pnpm typecheck` and stop on first error.
3) Codemod fallback (deterministic)
// jscodeshift transform — 매 LLM 보다 매 reliable for syntactic
import{API,FileInfo}from'jscodeshift';exportdefaultfunction(file: FileInfo,api: API){returnapi.jscodeshift(file.source).find('CallExpression',{callee:{name:'getUserData'}}).replaceWith(p=>api.jscodeshift.callExpression(api.jscodeshift.identifier('fetchUserProfile'),p.value.arguments)).toSource();}
4) Hybrid: codemod + LLM cleanup
# 매 1) codemod 로 매 syntactic 변경
jscodeshift -t rename.ts src/
# 매 2) LLM 으로 매 semantic 보정 (매 import path, comment, type narrowing)
claude "Fix any remaining type errors after the rename."
5) Test-driven refactor loop
# 매 Aider / Claude Code 의 매 auto-test loop
claude --auto-test "Extract logger to a separate module. Run pytest after."# 매 pytest fail → 매 LLM 이 매 fix 시도 → 매 max 3 retries → 매 stop
6) Diff size guard (pre-commit)
# .git/hooks/pre-commitLINES=$(git diff --cached --shortstat | grep -oE '[0-9]+ insertions'| head -1)if["${LINES%% *}" -gt 500];thenecho"Refusing >500 line AI commit. Split it.";exit1fi
# 매 매 refactor PR 의 mandatory gatesgates:- typecheck:pnpm tsc --noEmit- test:pnpm vitest run- lint:pnpm biome check- perf:bench compare main vs HEAD (regression < 5%)
매 결정 기준
상황
Approach
매 syntactic mass change
Codemod (jscodeshift / ast-grep)
매 semantic + 매 cross-cutting
LLM (Claude Code / Cursor)
매 1-file refactor
IDE refactor menu
매 risk-heavy (auth/payment)
Manual + LLM 보조 review
매 large repo (>1M LoC)
Hybrid: codemod 먼저, LLM 보정
기본값: 매 plan-first + 매 small diff + 매 test gate. 매 syntactic 부분은 매 codemod, 매 semantic 부분만 매 LLM.