서브에이전트 협업 모드
Claude Code의 서브에이전트 이해하고 활용하기 — 병렬 탐색, 백그라운드 작업, 격리 실행
API 키가 필요하신가요? 회원가입 →엔드포인트 & Base URL →
이 페이지 목차
서브에이전트 협업 모드¶
상상해 보세요. Claude에게 큰 모듈 리팩터링을 부탁했는데, 리팩터링 전에 먼저 세 가지를 파악해야 한다고 해요 — 기존 API 인터페이스는 무엇이 있는지, 데이터베이스 스키마는 어떻게 생겼는지, 테스트 커버리지는 어떤지요. 일반 모드에서는 Claude가 이것들을 하나씩 순차적으로 확인할 수밖에 없어요. 그런데 세 개의 "분신"을 동시에 보내 조사하게 할 수 있다면 어떨까요?
그것이 바로 서브에이전트의 매력이에요.
서브에이전트란¶
Agent 도구의 개념¶
서브에이전트는 Claude Code의 특수한 도구로, 메인 세션이 독립적인 Claude 인스턴스를 만들어 특정 작업을 실행하도록 해요. "Claude가 조수를 고용했다"고 생각하면 돼요.
메인 세션의 Claude는 프로젝트 매니저로서 전체 조율을 담당해요. 심층 조사가 필요한 하위 작업을 만나면 서브에이전트를 띄워 전담하게 하고, 자신은 다른 일을 계속 처리할 수 있어요.
서브에이전트와 메인 세션의 차이¶
| 항목 | 메인 세션 | 서브에이전트 |
|---|---|---|
| 컨텍스트 | 전체 대화 기록 포함 | 독립적인 컨텍스트 창, 작업 설명만 포함 |
| 수명 주기 | Claude Code를 닫을 때까지 유지 | 작업 완료 후 자동 종료 |
| 도구 접근 | 권한이 부여된 모든 도구 | 특정 도구 하위 집합으로 제한 가능 |
| 실행 방식 | 사용자와 대화형 상호작용 | 자율 실행, 완료 후 결과 반환 |
| 컨텍스트 소비 | 모든 작업이 동일한 컨텍스트 소비 | 메인 세션의 컨텍스트를 소비하지 않음 |
| 결과 | 직접 표시 | 요약 형태로 메인 세션에 반환 |
가장 핵심적인 차이는 독립적인 컨텍스트 창이에요. 서브에이전트는 자체 컨텍스트 공간을 가지므로 탐색 과정이 메인 세션의 컨텍스트를 늘리지 않아요. 최종 결과만 메인 세션으로 전달돼요 — 누군가를 출장 보내 조사하게 하고, 돌아오면 조사 과정 전체를 재생할 필요 없이 보고서만 받으면 되는 것과 같아요.
독립적인 컨텍스트 창의 장점¶
독립적인 컨텍스트가 왜 그렇게 중요할까요? 실제 예를 들어 볼게요.
200개 파일이 있는 프로젝트를 Claude가 분석해야 한다고 가정해요. 메인 세션에서 파일을 하나씩 읽으면 파일당 평균 200줄일 때 파일 내용만으로 40,000줄의 컨텍스트를 차지해요. 여기에 Claude의 분석 과정까지 더하면 컨텍스트가 금방 가득 차요.
서브에이전트는 달라요. 서브에이전트가 자신의 컨텍스트에서 이 파일들을 읽고 분석한 뒤, 마지막에 몇백 줄짜리 분석 보고서만 돌려줘요. 메인 세션의 컨텍스트는 거의 늘지 않고, 이후 작업을 계속할 여유도 충분해요.
내장 서브에이전트 유형¶
Claude Code의 서브에이전트는 사실 고정된 "유형"이 아니라 메인 세션이 작업 성격에 따라 유연하게 만들어요. 다만 실제로는 서브에이전트가 보통 다음과 같은 역할을 맡아요.
Explore (코드 검색 및 탐색)¶
서브에이전트의 가장 흔한 용도예요. Claude가 프로젝트의 특정 측면을 이해해야 할 때 Explore 서브에이전트를 띄워요.
기능:
- 파일 읽기 (Read)
- 코드 검색 (Grep, Glob)
- 디렉터리 구조 확인
- 코드 의존성 분석
제한:
- 보통 읽기 전용 도구만 부여
- 파일 수정 불가
- 명령 실행 불가
대표적인 시나리오:
Analyze public interfaces for all services in the src/services/ directory
Find all files that reference UserService
Understand the workflow of the authentication middleware
Plan (아키텍처 설계 및 계획)¶
계획이나 설계안을 수립하는 데 쓰이는 서브에이전트예요.
기능:
- Explore의 모든 기능
- 웹 검색 (문서, 모범 사례)
- 상세한 설계 문서 생성
대표적인 시나리오:
Design a cache layer architecture
Evaluate feasibility of migrating from REST to GraphQL
Formulate a database sharding strategy
General-Purpose (범용 작업)¶
특정 실행 작업을 처리하는 서브에이전트로, 모든 도구에 접근할 수 있어요.
기능:
- 파일 읽기 및 쓰기
- 명령 실행
- 테스트 실행
- 의존성 설치
대표적인 시나리오:
Run the full test suite in the background
Generate API documentation
Execute code formatting
서브에이전트를 사용해야 할 때¶
시나리오 1: 코드 검색 및 이해¶
낯선 코드베이스를 Claude가 깊이 이해해야 할 때, 서브에이전트가 탐색을 효율적으로 완료할 수 있어요.
I just took over this project. Please help me understand its architecture comprehensively:
1. Use a subagent to analyze the backend directory structure and core modules
2. Use a subagent to analyze the frontend component tree and state management
3. Use a subagent to analyze the database schema and entity relationships
Then synthesize information from all three areas and give me a project architecture overview.
Claude는 세 개의 서브에이전트를 띄워 이 작업들을 병렬로 실행한 뒤 보고서를 종합할 수 있어요.
시나리오 2: 여러 솔루션 병렬 조사¶
여러 기술 솔루션을 비교해야 할 때 서브에이전트의 병렬 능력이 아주 유용해요.
I need to choose a message queue for the project. Please research the following solutions separately:
1. Redis Streams — check if our existing Redis configuration supports it
2. RabbitMQ — evaluate the cost of introducing new dependencies
3. Using PostgreSQL's LISTEN/NOTIFY directly
For each solution, analyze the pros and cons and compatibility with our project.
시나리오 3: 오래 걸리는 작업을 백그라운드에서 실행¶
테스트 실행이나 문서 생성처럼 오래 걸리는 작업이 있어요. 이런 작업을 서브에이전트에 맡겨 백그라운드에서 실행할 수 있어요.
Please run the full test suite in the background while I continue working on other things.
Tell me the results when the tests are done.
Claude는 백그라운드 서브에이전트를 띄워 테스트를 실행해요. 기다리지 않고 메인 세션과 계속 대화할 수 있어요.
시나리오 4: 고위험 작업 격리¶
잠재적으로 위험한 작업을 실행해야 할 때 서브에이전트로 격리할 수 있어요.
Please try the following operations using a subagent:
1. Switch to a temporary branch
2. Try upgrading React to 19.x
3. Run the build and see how many compatibility errors there are
4. Send me the error list
Do not operate on the main branch.
서브에이전트 실전 튜토리얼¶
예제 1: 서브에이전트로 낯선 코드베이스 이해하기¶
중간 규모의 Python 프로젝트(소스 파일 약 50개)에 첫날 출근했다고 가정해요. 구조를 빠르게 파악해야 해요.
프롬프트:
It's my first day on this project. Please help me quickly build an understanding of it.
Use subagents to analyze the following areas in parallel:
1. Project structure and entry points — scan directory structure, find main entry, routing definitions, config files
2. Data models — analyze all model files and draw entity relationships
3. Business logic — analyze the services directory and understand core business workflows
4. External dependencies — analyze requirements.txt and actual imports to identify key dependencies
Finally, synthesize all the information into a project overview of no more than 500 words.
Claude의 실행 과정:
Claude는 여러 서브에이전트를 만들어 작업을 독립적으로 실행해요. 각 서브에이전트는 스스로 탐색한 뒤 결과를 반환해요. 과정 전반에 걸쳐 다음과 같은 출력을 보게 돼요.
Launching 4 subagents for parallel analysis...
[Subagent 1] Analyzing project structure...
- Scanned 52 Python files
- Found entry point: main.py → FastAPI app
- Route definitions in routers/ directory (8 routing modules)
- Config: config.py + .env
[Subagent 2] Analyzing data models...
- Found 12 SQLAlchemy models
- Core entities: User, Organization, Project, Task, Comment
- Key relationships: User ← many-to-many → Organization, Project → has-many → Task
[Subagent 3] Analyzing business logic...
- 9 service files
- Core workflows: user management, project management, task assignment, notification system
- Async task processing using Celery
[Subagent 4] Analyzing external dependencies...
- 32 direct dependencies
- Key dependencies: FastAPI, SQLAlchemy, Celery, Redis, Alembic
- Found 2 unused dependencies (requests, beautifulsoup4)
마지막으로 Claude가 네 서브에이전트의 결과를 종합해 구조화된 프로젝트 개요를 제공해요.
예제 2: 여러 서브에이전트를 병렬로 띄워 솔루션 비교하기¶
실시간 알림을 어떻게 구현할지 고민 중이고 여러 솔루션을 비교하고 싶어요.
I need to add real-time notification functionality to the project. Please help me evaluate the following three solutions in parallel:
Solution A: WebSocket (using FastAPI's built-in WebSocket support)
Solution B: Server-Sent Events (SSE)
Solution C: Polling
For each solution, please analyze:
1. Compatibility with our existing architecture (check existing code)
2. Implementation complexity (approximately how many files need changes)
3. Performance and scalability
4. Client compatibility
Then give me a comparison table and your recommendation.
Claude의 비교 결과는 다음과 같을 수 있어요.
All three subagents have completed analysis. Summary comparison:
| Evaluation Dimension | WebSocket | SSE | Polling |
|----------|-----------|-----|------|
| Architecture Compatibility | Need to add WebSocket routes | Can reuse existing HTTP routes | Fully compatible |
| Implementation Complexity | High (~8 files) | Medium (~4 files) | Low (~2 files) |
| Real-time Capability | Best (full duplex) | Good (server push) | Average (depends on polling interval) |
| Scalability | Needs WebSocket load balancing | Can use CDN | Simplest |
| Celery Integration | Needs additional message bridge | Can directly consume Celery events | Poll database |
**Recommendation**: Considering you're already using Celery + Redis, SSE is the best choice.
It can directly subscribe to Redis channels to get Celery events, with moderate implementation complexity,
and doesn't require additional infrastructure.
예제 3: 백그라운드 서브에이전트로 테스트 실행하기¶
코드를 수정하는 동시에 테스트 결과도 알고 싶어요.
Please run pytest in the background and run the full test suite. I'll continue modifying code. Tell me when it's done.
Claude는 백그라운드 서브에이전트를 띄워 테스트를 실행해요. 계속 Claude와 대화하며 코드를 수정할 수 있어요. 테스트가 완료되면 결과 알림을 보게 돼요.
Background tests completed. Results:
- Total: 247 tests
- Passed: 241
- Failed: 4
- Skipped: 2
Failed tests:
1. test_order_service.py::test_calculate_total_with_discount
AssertionError: 99.99 != 100.0
2. test_user_service.py::test_create_user_duplicate_email
IntegrityError: Test database not properly cleaned up
3. ...
Would you like me to analyze these failing tests?
서브에이전트 구성¶
커스텀 서브에이전트: 파일에서 모델과 도구 선택하기¶
2026-10-15 기준 Claude Code 문서에 따르면, 커스텀 서브에이전트는 YAML frontmatter가 있는 Markdown 파일이에요. .claude/agents/(이 프로젝트에서만) 또는 ~/.claude/agents/(모든 프로젝트에서)에 두거나, Claude에게 그냥 작성해 달라고 요청하면 돼요. name과 description만 필수예요:
---
name: code-reviewer
description: Reviews code for quality and best practices
tools: Read, Glob, Grep
model: sonnet
---
You are a code reviewer. When invoked, analyze the code and provide
specific, actionable feedback on quality, security, and best practices.
자주 쓰는 필드는 tools(허용할 도구), model(사용할 모델), effort(사고 강도), maxTurns(최대 턴 수), isolation: worktree(임시 git worktree에서 실행)예요.
model은 sonnet / opus / haiku / fable 별칭, 전체 모델 ID(예: claude-opus-5-5 또는 claude-sonnet-5-5), 또는 메인 대화의 모델을 쓰도록 하는 inherit을 받아요. Claude Code는 다음 순서로 서브에이전트의 모델을 선택해요(앞에 있는 항목이 우선):
- 해당 호출에 전달된
model파라미터 - 서브에이전트 정의의
model필드 - 환경 변수
CLAUDE_CODE_SUBAGENT_MODEL - 메인 대화의 현재 모델
서브에이전트가 실제로 어느 모델에서 실행 중인지 확인하려면 /tasks를 실행하세요(Claude Code v2.1.242 이상 필요). 검색 계열 서브에이전트는 haiku로 두고 메인 대화는 더 강력한 모델에 맡기는 것이 사용량을 관리하는 흔한 방법이에요.
CLAUDE.md로 서브에이전트 동작 안내하기¶
위의 서브에이전트 파일 외에도 CLAUDE.md를 사용해 Claude에게 서브에이전트를 언제, 어떻게 사용할지 안내할 수 있어요:
## Subagent Usage Guidelines
### When to Use Subagents
- Tasks analyzing more than 10 files should use subagents
- When comparing multiple solutions, launch independent subagents for each
- Running tests should be executed in background subagents
### Subagent Task Description Template
When launching subagents, the task description should include:
1. Clear objectives (what to do)
2. Scope limitations (what not to do)
3. Output format (what kind of results to return)
### Subagent Result Handling
Subagent results must include:
- Analysis summary (no more than 200 words)
- Key findings list
- Related file paths
- Potential risks or issues
서브에이전트가 사용할 수 있는 도구 이해하기¶
서브에이전트가 어떤 도구를 쓸 수 있는지는 메인 세션의 권한 부여에 달려 있어요. 실제로는 다음과 같아요:
- 읽기 전용 작업: 보통 Read, Grep, Glob 같은 검색 도구만 부여돼요
- 실행 작업: Bash, Write, Edit 같은 쓰기 도구가 부여돼요
- 네트워크 작업: WebSearch, WebFetch 같은 네트워크 도구가 부여돼요
자연어로 도구 범위를 암시할 수 있어요:
Please use a subagent to analyze (read-only) the relationships of all models in the src/models/ directory.
“read-only” 힌트를 추가하면 Claude는 검색과 읽기 기능만 가진 서브에이전트를 만드는 경향이 있어요.
백그라운드 실행¶
서브에이전트는 메인 세션과의 상호작용을 막지 않고 백그라운드에서 실행될 수 있어요. “백그라운드에서…” 또는 “비동기로…”라고 말하면 Claude가 run_in_background 파라미터를 사용해요:
Please help me with two things in the background:
1. Run the complete lint check
2. Check all dependencies for known security vulnerabilities
I'll continue modifying code and let me know when done.
백그라운드 서브에이전트가 완료되면 시스템이 Claude에게 알리고, Claude가 결과를 전달해 줘요.
모범 사례¶
1. 서브에이전트에게 명확한 작업 설명 제공하기¶
서브에이전트의 컨텍스트는 완전히 새것이라서, 이전에 메인 세션과 무엇을 논의했는지 몰라요. 그래서 작업 설명은 그 자체로 완결되어야 해요:
나쁜 예:
Use a subagent to check the issue mentioned earlier.
(서브에이전트는 “앞서 언급한 문제”가 무엇인지 몰라요)
좋은 예:
Use a subagent to check whether the process_refund() method in src/services/payment_service.py correctly handles concurrent refund requests.
Need to pay attention to database transaction isolation levels and use of optimistic locking.
2. 병렬 서브에이전트로 효율 높이기¶
여러 작업이 서로 의존하지 않을 때는 병렬로 실행하게 하세요:
Please execute the following tasks in parallel:
1. [Subagent A] Analyze all API call points in the frontend code
2. [Subagent B] Analyze backend API endpoints and parameter definitions
3. [Subagent C] Check if API documentation is consistent with actual interfaces
After all three tasks are complete, summarize the API inconsistencies.
3. 서브에이전트를 과도하게 쓰지 않기¶
서브에이전트가 만능 해결책은 아니에요. 다음 상황은 메인 세션에서 직접 처리하는 게 더 효율적이에요:
- 단순한 파일 확인: 파일 한두 개를 읽을 때는
@로 참조하면 돼요 - 단순한 검색: 키워드 하나를 검색할 때는 메인 세션이 더 빨라요
- 지속적인 상호작용이 필요한 작업: 서브에이전트는 “일회성”이라 여러 차례 대화가 필요한 작업에 적합하지 않아요
- 이전 결과에 의존하는 순차 작업: 서브에이전트를 쓰면 복잡성만 늘어나요
경험칙: 작업을 한두 문장으로 설명할 수 있고 많은 파일을 읽을 필요가 없다면 메인 세션에서 직접 하세요.
4. 서브에이전트 결과 전달 메커니즘 이해하기¶
서브에이전트가 작업을 완료하면 그 결과는 요약 형태로 메인 세션에 전달돼요. 즉:
- 서브에이전트가 읽은 원본 파일 내용은 전부 전달되지 않아요(너무 커요)
- 서브에이전트의 분석 결론과 핵심 정보만 전달돼요
- 서브에이전트가 발견한 특정 파일을 보고 싶다면 메인 세션에서 직접 다시 읽어야 해요
The subagent told me there's an issue on line 127 of payment_service.py.
Please show me lines 120-140 of that file.
5. “탐색적” 작업에 서브에이전트 사용하기¶
어떤 접근 방식이 실현 가능한지 확실하지 않나요? 메인 브랜치에서 위험을 감수하는 대신 서브에이전트로 실험해 보세요:
Please use a subagent to run an experiment:
1. Create a temporary directory /tmp/experiment
2. Copy src/models/user.py into it
3. Try replacing SQLAlchemy's declarative models with dataclasses
4. See what problems arise
Don't touch any project files.
고급: 서브에이전트를 다른 기능과 결합하기¶
서브에이전트 + Plan 모드¶
Plan 모드에서도 서브에이전트를 사용할 수 있어요. 강력한 조합이에요 — 계획 단계에서 서브에이전트로 심층 조사를 하세요:
(In Plan mode)
Please use subagents to help me research the following questions, then formulate a migration plan based on the research results:
1. List of all current REST API endpoints and their call frequencies
2. Which endpoints already have equivalent GraphQL implementations
3. How much the client code depends on REST APIs
서브에이전트 + MCP 도구¶
MCP 서버(예: 데이터베이스 쿼리 도구)를 구성했다면 서브에이전트도 이를 사용할 수 있어요:
Please use a subagent to connect to the database and analyze the following:
1. Data volume for each table
2. Top 10 slow queries
3. Missing indexes
Use the database MCP tool to execute queries.
서브에이전트 + Hooks¶
Hooks를 사용해 서브에이전트가 특정 작업을 실행할 때 커스텀 로직을 트리거할 수 있어요. 예를 들어 서브에이전트가 테스트를 완료하면 자동으로 알림을 보낼 수 있어요:
{
"hooks": {
"Notification": [
{
"hooks": [
{
"type": "command",
"command": "curl -X POST https://hooks.slack.com/... -d '{\"text\": \"$MESSAGE\"}'"
}
]
}
]
}
}
자주 묻는 질문¶
Q: 서브에이전트가 메인 세션과의 대화 기록을 볼 수 있나요?
A: 아니요. 서브에이전트의 컨텍스트는 완전히 새것이며 Claude가 전달한 작업 설명만 포함해요. 그래서 작업 설명이 그 자체로 완결되어야 하는 거예요. 다만 서브에이전트는 CLAUDE.md를 읽을 수 있으므로 프로젝트 수준의 규칙과 협약은 서브에이전트에도 적용돼요.
Q: 서브에이전트가 “서브-서브에이전트”를 실행할 수 있나요?
A: 네, 하지만 너무 깊게 중첩하는 것은 권장하지 않아요. 보통 서브에이전트 한 계층이면 충분해요.
Q: 여러 서브에이전트가 서로 통신할 수 있나요?
A: 아니요, 직접적으로는 안 돼요. 서브에이전트 B가 서브에이전트 A의 결과에 의존해야 한다면 A가 완료되기를 기다린 뒤 메인 세션이 결과를 B에 전달하는 방법밖에 없어요.
Q: 서브에이전트가 추가 API 한도를 소비하나요?
A: 네. 서브에이전트는 독립적인 컨텍스트 창을 사용하고, 각 서브에이전트의 입력과 출력 모두 토큰을 소비해요. 다만 서브에이전트의 컨텍스트는 보통 더 작아서(특정 작업만 포함) 총 소비량은 같은 작업을 메인 세션에서 하는 것보다 적은 경우가 많아요.
Q: 서브에이전트가 무엇을 하는지 어떻게 알 수 있나요?
A: Claude가 메인 세션에 서브에이전트 실행 상태를 표시해요. 어떤 서브에이전트를 실행했는지, 각 서브에이전트가 무엇을 하는지, 완료되었는지를 볼 수 있어요.
QCode 시작하기
Claude Code, Codex 등에 API 키 하나를 쓰세요. 토큰 단위로 과금하며 모델별 가격은 qcode.cc/models에 있어요