Monorepo에서의 Claude Code
고급 10 min
Monorepo는 AI 코딩 어시스턴트에게 고유한 도전을 제시합니다: 대규모 코드베이스, 서로 다른 컨벤션을 가진 여러 패키지, 복잡한 의존성 그래프 등. 이 가이드에서는 범위 지정 CLAUDE.md 파일부터 worktree 기반 병렬 개발, 크로스 패키지 리팩토링 전략까지, monorepo에서 Claude Code를 성공적으로 사용하기 위한 설정 방법을 보여줍니다.
monorepoworktreeTurborepoNx워크스페이스
Monorepo CLAUDE.md 전략
In a monorepo, a single root-level CLAUDE.md is not enough. You need a layered approach: a root CLAUDE.md for shared conventions, plus package-level CLAUDE.md files for package-specific rules.
The root CLAUDE.md should cover cross-cutting concerns: the monorepo tool (Turborepo, Nx, pnpm workspaces), shared linting and formatting rules, and the overall architecture pattern. Package-level files should describe that specific package's tech stack, testing approach, and API contracts.
Claude Code reads CLAUDE.md files hierarchically. When working in packages/api, it loads both the root CLAUDE.md and packages/api/CLAUDE.md. This means you do not need to repeat shared conventions in every package file.
# Root CLAUDE.md
## Monorepo: pnpm workspaces + Turborepo
## Packages: apps/web, apps/api, packages/shared, packages/ui
## Shared Rules
- pnpm only (no npm/yarn)
- Imports between packages use @repo/* alias
- All packages use TypeScript strict mode
# packages/api/CLAUDE.md
## Express + Prisma API
- Tests: vitest, co-located
- Routes follow REST conventions
# packages/ui/CLAUDE.md
## React component library
- Storybook for development
- Export via barrel files (index.ts)
Worktree를 활용한 범위 지정 세션
Worktrees are a game-changer for monorepo development. Instead of switching branches and rebuilding everything, worktrees let you work on multiple features simultaneously in isolated copies of the repository.
Claude Code integrates with git worktrees natively. You can spin up a worktree, make changes in isolation, and merge back when ready. This is especially useful in monorepos where a change in one package might affect others — the worktree lets you test the full impact without disrupting your main working copy.
A practical pattern is to use one worktree per feature branch. Each worktree gets its own Claude Code session, so you can context-switch between features without Claude losing track of what you were doing.
# Create a worktree for a feature
git worktree add ../my-repo-feature-auth -b feature/auth
# Start Claude Code in the worktree
cd ../my-repo-feature-auth
claude
# Work in isolation — main repo is untouched
claude "add OAuth2 to packages/api"
# When done, merge back
cd ../my-repo
git merge feature/auth
git worktree remove ../my-repo-feature-auth
크로스 패키지 리팩토링
One of Claude Code's strengths in monorepos is cross-package refactoring. Renaming a shared type, updating an API contract, or migrating a dependency across all packages would be tedious manually but Claude can handle it in a single session.
The key is to give Claude the full picture. Start by telling it which packages are affected and what the change entails. Claude will read the relevant files across packages, plan the changes, and apply them consistently.
For large refactors spanning more than 5 packages, consider breaking the work into phases. Do the shared packages first, then update consumers. This reduces the chance of inconsistent intermediate states and makes code review easier.
# Cross-package type rename
claude "rename UserProfile to AccountProfile in packages/shared/types.ts and update all imports across apps/web, apps/api, and packages/ui"
# Dependency migration across all packages
claude "migrate from moment.js to date-fns in all packages. Update imports, adjust API calls, and fix tests."
# Shared component API change
claude "add a 'size' prop to Button in packages/ui. Update all usages in apps/web to pass size='md' as default."
빌드 및 테스트 최적화
Monorepo build times can be long, so it is important to tell Claude how to run targeted builds and tests. Without guidance, Claude might run a full monorepo build after every change, wasting time and resources.
Configure your CLAUDE.md with the commands for building and testing individual packages. Most monorepo tools support this natively: Turborepo has --filter, Nx has --projects, and pnpm has --filter. Teaching Claude these commands dramatically speeds up the feedback loop.
Also consider adding a build dependency graph to your CLAUDE.md. When Claude understands that packages/api depends on packages/shared, it knows to rebuild shared first when it changes a shared type. This prevents confusing build errors that waste debugging time.
# CLAUDE.md build commands section
## Build & Test
- Single package: pnpm --filter @repo/api test
- With dependencies: pnpm --filter @repo/api... build
- Affected only: pnpm turbo test --filter=...[HEAD~1]
## Dependency Graph
# packages/shared → packages/ui → apps/web
# packages/shared → apps/api
# Change in shared → rebuild all downstream
# Claude uses these efficiently
claude "fix the type error in packages/shared/utils.ts and run tests only for affected packages"
실행 미리보기
Monorepo에서의 Claude Code
Monorepo에서의 Claude Code에 대해
Claude Code 가이드는 Claude Code의 특정 측면을 마스터하기 위한 심층적인 단계별 안내를 제공합니다. Monorepo에서의 Claude Code은(는) 고급 수준의 가이드로, 일상 워크플로우에서 Claude Code를 최대한 활용하기 위한 베스트 프랙티스, 실전 기법, 실용적인 팁을 안내합니다.