NxtCloud NxtCloud Workshop / Claude Code & MCP 핸즈온
로그인

Lab 03. 기본 동작법

이 랩에서 다루는 것
  • 세션 명령: /model · /context · /compact · /plan 등 자주 쓰는 슬래시 명령
  • 권한 모델: 에이전트가 무엇을 실행하도록 허용할지
  • CLAUDE.md 메모리 계층: user · project · local 3단계
  • Custom Commands: 반복 프롬프트를 /명령 으로 패키징
Step 1. 세션 명령 익히기

세션 안에서 / 를 입력하면 슬래시 명령 목록이 뜹니다. 자주 쓰는 것부터.

명령설명
/modelopus · sonnet · haiku 전환
/init프로젝트를 분석해 CLAUDE.md 초안 생성
/context현재 컨텍스트 사용량 확인
/compact대화를 요약해 컨텍스트 압축
/clear대화 컨텍스트 초기화(새 작업 시작)
/usage사용량 확인
/plan계획 모드. 변경 없이 계획부터
/mcpMCP 서버 관리 (Lab 04~06)
!명령느낌표로 셸 명령을 실행해 결과를 컨텍스트에 추가

!ls 처럼 느낌표로 시작하면 터미널 명령이 실행되고 그 출력이 대화에 들어옵니다. esc 는 한 번 누르면 취소, 두 번 누르면 직전 동작을 되감습니다.

🎯 체크포인트
  • /model 로 모델을 전환해 봤다
  • !ls 로 셸 명령 실행 결과가 컨텍스트에 들어오는 것을 확인했다
Step 2. 권한 모델

Claude Code 는 파일을 고치거나 셸 명령을 실행하기 전에 사용자에게 묻습니다. 터미널 에이전트의 안전장치입니다.

권한 모드동작언제
기본(default)편집·명령마다 확인처음엔 이 모드로 관찰
/plan 계획 모드읽기만, 변경 없이 계획부터 제시큰 작업 전에 방향 합의
acceptEdits파일 편집은 자동 승인신뢰가 쌓인 반복 작업
--dangerously-skip-permissions모든 확인 건너뜀⚠️ 격리된 환경에서만

💡 큰 작업은 /plan 으로 계획을 먼저 받고, 좋으면 실행을 승인하는 흐름이 안전합니다. 권한을 한꺼번에 풀어 주는 건 격리된 실험 환경에서만 하세요.

🎯 체크포인트
  • /plan 으로 계획 모드를 켜고, 변경 전에 계획이 먼저 나오는 것을 확인했다
Step 3. CLAUDE.md 메모리 계층

CLAUDE.md매 세션 시작 시 자동으로 한 번 읽히는 메모리입니다. “어떻게 일할지” 와 “이 프로젝트의 규칙” 을 적어 두면 매 세션 다시 설명할 필요가 없습니다.

⏱️ 로드 시점: 세션을 시작할 때 한 번 로드됩니다. 세션 도중 CLAUDE.md 를 고쳐도 지금 세션에는 반영되지 않습니다 → 바꿨으면 새 세션을 여세요.

3계층: 어디에 두느냐로 범위가 갈립니다

레벨위치범위적는 것
User~/.claude/CLAUDE.md내 모든 프로젝트 공통”어떻게 일할지” (작업 계약서)
Project./CLAUDE.md이 프로젝트 (git 으로 팀 공유)아키텍처 · 에러 핸들링 · 코드 스타일
Local.claude/CLAUDE.local.md이 프로젝트, 나만 (git 미공유)개인 메모 · 임시 규칙

여러 레벨이 동시에 있으면 모두 합쳐져 로드됩니다(User + Project + Local).

사용자 레벨 = “작업 계약서”

~/.claude/CLAUDE.md 에는 Claude 가 어떻게 협업할지를 정의합니다. 문서 작성법이나 페르소나(성격) 설정이 아니라, 일하는 절차와 기본값입니다. 기본 골격은 보통 Planning · Communication · Defaults 세 덩어리입니다.

## Planning
- Propose a brief plan before non-trivial work (new features, multi-file changes, architectural decisions).
- Trivial work (typos, obvious fixes, single-line changes) — just do it.
- If multiple reasonable approaches exist, present them with tradeoffs. Don't pick silently.

## Communication
- Be direct and specific. No hedging on technical recommendations.
- If uncertain, say so and ask — don't guess.
- When recommending: state what, why, and what could go wrong.

## Defaults
- Prefer editing existing files over creating new ones.
- Don't create documentation files (README, etc.) unless asked.
- Stop after 3 failed attempts and reassess the approach.

실제로 쓰이는 더 정교한 예시 두 가지. 펼쳐서 참고하세요.

예시. Karpathy 스타일 (행동 가드레일)
# CLAUDE.md

Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.

**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.

## 1. Think Before Coding

**Don't assume. Don't hide confusion. Surface tradeoffs.**

Before implementing:
- Check if similar patterns or utilities already exist in the codebase.
- State your assumptions explicitly. If uncertain, ask.
- If multiple interpretations exist, present them - don't pick silently.
- If a simpler approach exists, say so. Push back when warranted.
- If something is unclear, stop. Name what's confusing. Ask.

## 2. Simplicity First

**Minimum code that solves the problem. Nothing speculative.**

- No features beyond what was asked.
- No abstractions for single-use code.
- No "flexibility" or "configurability" that wasn't requested.
- No error handling for truly unreachable code paths. When uncertain, handle it.
- If you write 200 lines and it could be 50, rewrite it.

Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.

## 3. Surgical Changes

**Touch only what you must. Clean up only your own mess.**

When editing existing code:
- Don't "improve" adjacent code, comments, or formatting.
- Don't refactor things that aren't broken.
- Match existing style, even if you'd do it differently.
- If you notice unrelated dead code, mention it - don't delete it.

When your changes create orphans:
- Remove imports/variables/functions that YOUR changes made unused.
- Don't remove pre-existing dead code unless asked.

The test: Every changed line should trace directly to the user's request.

## 4. Goal-Driven Execution

**Define success criteria. Loop until verified.**

Transform tasks into verifiable goals:
- "Add validation" → "Write tests for invalid inputs, then make them pass"
- "Fix the bug" → "Write a test that reproduces it, then make it pass"
- "Refactor X" → "Ensure tests pass before and after"

For multi-step tasks, state a brief plan:
```
1. [Step] → verify: [check]
2. [Step] → verify: [check]
3. [Step] → verify: [check]
```

Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.

---

**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
예시. Boris 스타일 (워크플로 오케스트레이션)
## Workflow Orchestration

### 1. Plan Node Default
- Enter plan mode for ANY non-trivial task (3+ steps or architectural decisions)
- If something goes sideways, STOP and re-plan immediately
- Use plan mode for verification steps, not just building
- Write detailed specs upfront to reduce ambiguity

### 2. Subagent Strategy
- Use subagents liberally to keep main context window clean
- Offload research, exploration, and parallel analysis to subagents
- For complex problems, throw more compute at it via subagents
- One tack per subagent for focused execution

### 3. Self-Improvement Loop
- After ANY correction from the user: update tasks/lessons.md with the pattern
- Write rules for yourself that prevent the same mistake
- Ruthlessly iterate on these lessons until mistake rate drops
- Review lessons at session start for relevant project

### 4. Verification Before Done
- Never mark a task complete without proving it works
- Diff behavior between main and your changes when relevant
- Ask yourself: "Would a staff engineer approve this?"
- Run tests, check logs, demonstrate correctness

### 5. Demand Elegance (Balanced)
- For non-trivial changes: pause and ask "is there a more elegant way?"
- If a fix feels hacky: "Knowing everything I know now, implement the elegant solution"
- Skip this for simple, obvious fixes - don't over-engineer
- Challenge your own work before presenting it

### 6. Autonomous Bug Fixing
- When given a bug report: just fix it. Don't ask for hand-holding
- Point at logs, errors, failing tests -- then resolve them
- Zero context switching required from the user
- Go fix failing CI tests without being told how

## Task Management

1. **Plan First:**       Write plan to tasks/todo.md with checkable items
2. **Verify Plan:**      Check in before starting implementation
3. **Track Progress:**   Mark items complete as you go
4. **Explain Changes:**  High-level summary at each step
5. **Document Results:** Add review section to tasks/todo.md
6. **Capture Lessons:**  Update tasks/lessons.md after corrections

## Core Principles

- **Simplicity First:** Make every change as simple as possible. Impact minimal code.
- **No Laziness:**      Find root causes. No temporary fixes. Senior developer standards.
- **Minimal Impact:**   Changes should only touch what's necessary. Avoid introducing bugs.

프로젝트 레벨 = 이 코드베이스의 규칙

./CLAUDE.md(프로젝트 루트)에는 이 프로젝트에서만 통하는 사실을 적습니다: 아키텍처 원칙 · 에러 핸들링 · 코드 스타일 · 하지 말 것. /init 으로 초안을 만든 뒤 다듬는 게 빠릅니다: Claude 가 코드베이스를 훑어 스택 · 구조를 채워 줍니다.

예시. ShopFront (Next.js 14 전자상거래)
# 프로젝트: ShopFront
App Router, Stripe 결제, Prisma ORM을 사용하는 Next.js 14 전자상거래 애플리케이션입니다.

## 코드 스타일

- TypeScript strict 모드 사용, `any` 타입 금지
- default export 대신 named export 사용
- CSS: Tailwind 유틸리티 클래스 사용, 커스텀 CSS 파일 금지

## 명령어

- `npm run dev`: 개발 서버 시작 (포트 3000)
- `npm run test`: Jest 테스트 실행
- `npm run test:e2e`: Playwright end-to-end 테스트 실행
- `npm run lint`: ESLint 검사
- `npm run db:migrate`: Prisma 마이그레이션 실행

## 아키텍처

- `/app`: Next.js App Router 페이지 및 레이아웃
- `/components/ui`: 재사용 가능한 UI 컴포넌트
- `/lib`: 유틸리티 및 공유 로직
- `/prisma`: 데이터베이스 스키마 및 마이그레이션
- `/app/api`: API 라우트

## 중요 사항

- .env 파일은 절대 커밋하지 마세요
- /app/api/webhooks/stripe의 Stripe webhook 핸들러는 반드시 서명을 검증해야 합니다
- 제품 이미지는 로컬이 아닌 Cloudinary에 저장됩니다
- 인증 플로우에 대한 자세한 내용은 @docs/authentication.md를 참고하세요

💡 Claude Code 는 벡터DB 임베딩 검색이 아니라 에이전트가 직접 grep · 파일 읽기로 탐색(agentic retrieval)해 코드베이스를 이해합니다. CLAUDE.md 는 그 탐색의 출발점 · 지도 역할을 합니다.

🎯 체크포인트
  • ~/.claude/CLAUDE.md 에 나만의 “작업 계약서” 를 작성하고 새 세션에서 반영되는지 확인했다
  • /init 으로 프로젝트 CLAUDE.md 초안을 만들어 봤다
Step 4. Custom Commands

자주 쓰는 프롬프트는 마크다운 파일로 만들어 /명령 으로 부를 수 있습니다. 파일 이름이 곧 명령 이름입니다.

📎 Skills 와의 관계: Custom Commands 는 이제 Skills 에 통합됐습니다. .claude/commands/review.md 는 계속 동작하고(하위 호환), Skills 는 여기에 Claude 가 필요할 때 자동 호출 까지 더한 상위 개념입니다. 입문 단계에선 이 명령 파일 방식이 가장 간단합니다.

mkdir -p .claude/commands        # 프로젝트 레벨
mkdir -p ~/.claude/commands      # 사용자 레벨(전역)

.claude/commands/review.md 를 만들면 세션에서 /review 로 실행됩니다.

---
description: 변경 사항을 리뷰합니다
---

변경된 파일을 읽고 버그 · 스타일 · 보안 관점에서 리뷰해 주세요.
심각도와 함께 정리합니다.

$ARGUMENTS 로 인자를 받을 수도 있습니다: .claude/commands/explain.md.

---
description: 파일을 쉽게 설명합니다
argument-hint: <파일경로>
---

$ARGUMENTS 파일을 읽고, 초보자도 이해할 수 있게 구조와 역할을 설명해 주세요.

세션에서 /explain src/app.py 처럼 인자를 붙여 실행합니다.

🎯 체크포인트
  • Custom Command 1개를 만들어 슬래시 명령 자동완성에 뜨는지 확인했다
  • 실제로 실행해 동작을 확인했다

다음 단계

기본기를 익혔습니다. 이제 외부 세계와 연결할 차례입니다. Lab 04. MCP 체험 에서 브라우저 MCP 를 붙여 에이전트가 실제 웹페이지를 다루는 것을 직접 봅니다.