모범 사례

Claude Code를 최대한 활용하기 위한 검증된 전략과 기법

컨텍스트 관리

효과적인 컨텍스트 관리는 Claude Code에서 정확하고 관련성 높은 응답을 얻는 핵심입니다.

컨텍스트를 집중적으로 유지

컨텍스트 윈도우에 관련 파일과 정보만 포함하세요. CLAUDE.md로 프로젝트별 가이드를 제공하세요. 새 주제는 /clear로 새 세션을 시작하세요.

컴팩트 모드 사용

컨텍스트가 커지면 /compact로 핵심 정보를 보존하면서 대화를 요약하세요. 곁다리 질문에는 /btw를 사용하여 메인 컨텍스트를 오염시키지 마세요.

메모리와 핸드오프 활용

프로젝트와 사용자 수준에서 CLAUDE.md를 사용하여 세션 간 중요한 컨텍스트를 유지하세요. 새로 시작하기 전에 HANDOFF.md를 작성하여 세션 간 컨텍스트를 이전하세요.

markdown
# Project-level CLAUDE.md example
# Place at your repository root

## Project Overview
This is a Next.js 15 app with TypeScript and Tailwind CSS.

## Architecture
- /src/app/ - App Router pages
- /src/components/ - Reusable UI components
- /src/lib/ - Utility functions and configs

## Commands
- pnpm dev - Start dev server
- pnpm test - Run tests
- pnpm lint - Run linter

## Conventions
- Use functional components with hooks
- Prefer immutable patterns (spread, map, filter)
- All new files must have tests

Use /btw for Side Questions

When you have a quick question unrelated to your main task, prefix it with /btw. This tells Claude it's a tangent so the main conversation flow stays clean and focused.

Write HANDOFF.md Before Fresh Starts

Before ending a long session, ask Claude to write a HANDOFF.md summarizing current progress, decisions made, and next steps. Your next session can pick up exactly where you left off.

bash
# Ask Claude to create a handoff document
> Write a HANDOFF.md summarizing what we did today,
> open decisions, and next steps.

# In your next session
> Read HANDOFF.md and continue from where we left off.

검증 & 테스트

정확성과 품질을 보장하기 위해 항상 Claude Code의 출력을 검증하세요.

수락 전 검토

코드 변경을 수락하기 전에 항상 검토하세요. 비주얼 디프로 변경 내용을 파악하세요. 머지 전에 모든 것을 검토하기 위해 드래프트 PR을 만드세요.

자주 테스트 실행

변경 후 Claude에게 테스트를 실행하도록 요청하세요. 자동 검증을 위해 autotest 훅을 설정하세요. 프롬프트에 테스트 명령어를 포함하세요.

jsonc
# In your CLAUDE.md, add verification commands:
## After Every Change
- Run: pnpm test
- Run: pnpm lint
- Run: pnpm typecheck

# Or set up a PostToolUse hook in .claude/settings.json:
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "command": "pnpm test --bail 2>&1 | tail -20"
      }
    ]
  }
}

체크포인트와 자가 검증 사용

안전하게 실험하고 /rewind로 롤백하기 위해 git 체크포인트를 활용하세요. Claude에게 주장을 재확인하도록 요청하고 웹 앱의 시각적 검증에는 /chrome을 사용하세요.

Ask Claude to Verify Its Own Work

After implementation, explicitly ask Claude to review what it wrote. Phrases like "now review that code for bugs" or "does this handle edge cases?" trigger a critical second pass that often catches issues.

bash
# Good verification prompts:
> Now review that implementation for edge cases
> Run the tests and fix any failures
> Check if this handles null/undefined inputs
> Does this match the existing code style?

Use /chrome for Visual Verification

For web applications, use /chrome to let Claude take a screenshot and visually verify that UI changes look correct. This catches CSS issues, layout problems, and visual regressions that tests miss.

플랜 모드 & 구조적 사고

구현 전 구조적 분석이 필요한 복잡한 작업에 플랜 모드를 사용하세요.

계획부터 시작

복잡한 기능의 경우 Shift+Tab을 눌러 플랜 모드에 진입하세요. Claude가 코드를 작성하기 전에 문제를 분석하도록 하세요. 실행을 승인하기 전에 계획을 검토하세요.

대규모 작업 분해

복잡한 작업을 더 작고 관리 가능한 단계로 나누세요. 이는 정확성을 향상시키고 각 부분의 검증을 쉽게 만듭니다. 격리된 조사에 서브에이전트를 사용하세요.

bash
# Instead of one big prompt:
> Build a complete auth system with OAuth, sessions, and RBAC

# Break it down into phases:
> Phase 1: Set up the session store with Redis.
>   Only create the session middleware - no auth yet.
>   Run tests before moving on.

> Phase 2: Add email/password authentication.
>   Use the session store from Phase 1.
>   Add login, logout, and registration routes.

> Phase 3: Add OAuth (Google, GitHub).
>   Integrate with the existing session/auth system.

> Phase 4: Add role-based access control.
>   Define roles: admin, editor, viewer.
>   Add middleware to protect routes.

확장 사고 사용

깊은 추론이 필요한 복잡한 아키텍처 결정에 확장 사고를 활성화하세요. 'think', 'think hard', 또는 'ultrathink' 키워드를 사용하세요.

bash
# Trigger levels of extended thinking:

> think about how to refactor this module
# Light analysis, good for moderate complexity

> think hard about the tradeoffs between
> microservices vs monolith for our scale
# Deeper analysis, explores more alternatives

> ultrathink about the security implications
> of our auth architecture
# Maximum reasoning depth, best for critical decisions

Use Subagents for Investigation

When planning reveals unknowns, use subagents to investigate specific areas without polluting your main context. Each subagent gets its own context window and can focus on one aspect of the problem.

Review and Iterate on Plans

Don't accept the first plan. Ask Claude to consider alternatives, identify risks, and think about edge cases. A good plan should include rollback strategies and success criteria.

프롬프트 엔지니어링

Claude Code와 소통하는 방식은 결과의 품질에 큰 영향을 미칩니다.

구체적으로 작성

파일 경로, 함수 이름, 예상 동작을 포함한 명확하고 구체적인 지시를 제공하세요. '에러 수정해줘'가 아니라 'user.tsx의 handleSubmit에서 null 참조를 수정해줘'라고 말하세요.

bash
# Bad: vague prompt
> Fix the bug in the login page

# Good: specific prompt with context
> In src/app/auth/login.tsx, the handleSubmit
> function throws a null reference when the
> email field is empty. Add input validation
> before the API call on line 45. The validation
> should show an inline error message matching
> the style in src/components/FormError.tsx.

예시와 컨텍스트 제공

Claude에게 원하는 패턴이나 스타일의 예시를 보여주세요. @로 특정 파일을 참조하세요. 에러, UI, 디자인의 스크린샷을 붙여넣으세요. 성공 기준을 포함하세요.

제약 조건과 표준 설정

프로젝트 제약 조건, 코딩 표준, 따라야 할 패턴에 대해 Claude에게 알려주세요. 검증 단계를 포함하세요: '모든 테스트가 통과하고 린터가 깨끗해야 해'.

bash
# Include constraints directly in your prompt:
> Add a user search endpoint to the API.
> Requirements:
> - Follow the pattern in src/api/products.ts
> - Use Zod for input validation
> - Add rate limiting (100 req/min)
> - Return paginated results
> - Include unit tests with >80% coverage
> - All existing tests must still pass
> - No console.log statements

Use @ References and Images

Reference files directly with @filename to pull them into context. Paste screenshots of error messages, UI designs, or expected output. Visual context often communicates requirements better than words.

Front-load Intent, Not Just Instructions

Start prompts with WHY before WHAT. When Claude understands the goal, it makes better decisions about implementation details and catches design issues early.

bash
# Less effective: just instructions
> Add a cache layer to getUserById

# More effective: intent + instructions
> Users are seeing 2s load times on profile pages
> because getUserById hits the database every time.
> Add a Redis cache layer with 5-minute TTL.
> Invalidate on user update. Follow the caching
> pattern we use in getProductById.

Claude Code 확장

대규모 프로젝트와 팀에서 Claude Code를 효과적으로 사용하는 기법.

CI/CD에 헤드리스 모드 사용

자동화된 코드 리뷰, 테스트 생성, 문서 업데이트를 위해 claude -p로 CI/CD 파이프라인에 Claude Code를 통합하세요.

yaml
# GitHub Actions example: automated code review
name: Claude Code Review
on: [pull_request]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Claude Review
        run: |
          claude -p "Review the changes in this PR.
            Focus on: security issues, performance,
            and code style. Output as markdown." \
            --output-format json > review.json

팀 표준 구성

팀 멤버 간 일관된 동작을 위해 공유 CLAUDE.md 파일을 사용하세요. 커스텀 스킬과 서브에이전트를 만드세요. 팀 배포를 위해 플러그인으로 공유하세요.

json
# .claude/settings.json - shared team config
{
  "permissions": {
    "allow": [
      "Read",
      "Glob",
      "Grep",
      "Bash(pnpm test*)",
      "Bash(pnpm lint*)"
    ],
    "deny": [
      "Bash(rm -rf *)",
      "Bash(git push --force*)"
    ]
  },
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "command": "npx prettier --write $CLAUDE_FILE_PATH"
      }
    ]
  }
}

서브에이전트와 팀 활용

서브에이전트로 파일 간 팬아웃하세요. 조율된 병렬 작업에 에이전트 팀(실험적)을 사용하세요. 에이전트 간 격리를 위해 git worktree를 사용하세요.

Use Git Worktrees for Parallel Agents

When running multiple Claude Code agents on the same repo, use git worktrees to give each agent its own working directory. This prevents file conflicts and lets agents work truly in parallel.

bash
# Create worktrees for parallel agents
git worktree add ../project-agent-1 -b feature/auth
git worktree add ../project-agent-2 -b feature/api

# Run Claude in each worktree
cd ../project-agent-1 && claude -p "Implement auth"
cd ../project-agent-2 && claude -p "Build API endpoints"

# Merge results back
git checkout main
git merge feature/auth
git merge feature/api

Create Custom Skills for Repeated Tasks

If your team frequently performs the same type of task (e.g., creating API endpoints, writing migration scripts), define custom skills with SKILL.md files that encode your team's patterns and standards.

markdown
# .claude/skills/api-endpoint/SKILL.md
---
name: create-api-endpoint
description: Create a new REST API endpoint
---

## Steps
1. Create route handler in src/api/
2. Add Zod validation schema
3. Add rate limiting middleware
4. Write integration tests
5. Update OpenAPI spec

## Template
Follow the pattern in src/api/products.ts
Always include error handling middleware
Use the shared response format from src/lib/response.ts