Claude Code 토큰 사용량 최적화 7가지 실전 기법
검증된 7가지 토큰 최적화 기법으로 Claude Code 비용을 절감하세요. /compact, 프롬프트 캐싱, 서브에이전트 전략, 모델 전환을 배웁니다.
The more you use Claude Code, the more you start watching your token usage and costs. This article shares 7 practical techniques that reduce costs while improving speed.
How Token Consumption Works
Claude Code includes the entire conversation history in context. The longer the session, the more tokens each turn consumes. Controlling this consciously is the first step to cost reduction.
Technique 1: Compact the context with /compact
The most basic move. When the conversation grows, run /compact.
> /compact
It summarizes the past conversation and dramatically reduces context size. The context is preserved in summary form, so you can keep working without breaking flow.
Rule of thumb: Run /compact once after 50 turns.
Technique 2: /clear when no longer needed
When a task fully switches, use /clear instead of /compact.
> /clear
Wipes history completely and starts from scratch. No previous task context remains, so you can focus on the new one.
See also Claude Code Getting Started Guide.
Technique 3: Shorten prompts with CLAUDE.md
Repeating the same setup in every prompt is a token waste. Put project info into CLAUDE.md and your instructions get shorter.
# CLAUDE.md
## Project Overview
TypeScript + Next.js 15 e-commerce site. Tailwind CSS, Prisma + PostgreSQL.
## Coding Conventions
- Use async/await (avoid Promise.then)
- Use absolute imports (@/...)
- Tests in Vitest
## Common Commands
- npm run dev
- npm run test
- npm run build
Just having this cuts each prompt to about 1/3 of its previous length. See CLAUDE.md Best Practices for more.
Technique 4: Pass only what’s needed via pipe
Don’t have Claude Code read the entire file. Pipe only the relevant slice.
# Bad: pass the entire file
claude -p "Improve formatDate in src/utils/helpers.ts"
# Good: extract just the function
sed -n '/^export function formatDate/,/^}/p' src/utils/helpers.ts | claude -p "Improve this function"
Same with error logs.
# Pass only the last 100 lines
tail -n 100 production.log | claude -p "Identify the cause of errors"
Technique 5: Save main context with subagents
Delegate long research and large file exploration to subagents.
Spawn 3 subagents in parallel and investigate:
1. List of endpoints in src/api/
2. Main components in src/components/
3. Coverage status in tests/
Each agent should return a summary.
Only summaries return to the main context, saving significant tokens. See Subagent Activation Patterns for more.
Technique 6: Choose the right model for the job
Switch models based on task complexity.
# Simple work with Haiku
claude --model claude-haiku-4-5 -p "Translate the comments in this file"
# Complex design with Sonnet
claude --model claude-sonnet-4-5 -p "Redesign this architecture"
# Critical tasks with Opus
claude --model claude-opus-4-6 -p "Diagnose the root cause of this performance issue"
Haiku runs at about 1/4 the cost of Sonnet, so using it for simple tasks delivers serious savings. See Claude Code Pricing Guide for more.
Technique 7: Check /cost frequently
Run /cost mid-session to see current token usage and cost.
> /cost
Total tokens: 45,231
Estimated cost: $0.42
When you notice “wait, that’s more than I expected”, reset immediately with /compact or /clear.
Daily Workflow Example
A daily routine combining all of these.
# Morning: start a new task
$ claude
> Read CLAUDE.md and confirm today's tasks
# Mid-day: after 50 turns
> /compact
# Noon: switch to a different task
> /clear
> Starting refactoring on a different feature
# Evening: check costs
> /cost
> /compact
# Night: continue tomorrow
> Use /resume to pick up where you left off
Conclusion
- Reset context periodically with
/compactand/clear - Shorten prompts with CLAUDE.md
- Pipe only the relevant data
- Parallelize and save context with subagents
- Match the model to the task
- Check
/costfrequently
Making these habits cuts monthly costs in half or better. See the Anthropic official docs for further best practices.
Claude Code 워크플로우를 한 단계 업그레이드하세요
지금 바로 Claude Code에 복사해 쓸 수 있는 검증된 프롬프트 템플릿 50선.
무료 PDF: 5분 완성 Claude Code 치트시트
이메일 주소만 등록하시면 A4 한 장짜리 치트시트 PDF를 즉시 보내드립니다.
개인정보는 엄격하게 관리하며 스팸은 보내지 않습니다.
이 글을 작성한 사람
Masa
Claude Code를 적극 활용하는 엔지니어. 10개 언어, 2,000페이지 이상의 테크 미디어 claudecode-lab.com을 운영 중.
관련 글
Claude Code로 대규모 코드베이스를 빠르게 파악하는 방법
10만 줄 이상의 프로젝트도 Claude Code로 몇 분 만에 전체 그림을 파악할 수 있습니다.
Claude Code로 에러를 순식간에 해결하는 디버깅 기법 5선
에러 메시지를 붙여넣기만 하면 원인 파악부터 수정까지. Stack Overflow 검색을 없애는 5가지 기법.
Claude Code 커스텀 슬래시 커맨드 만들기 — 나만의 개발 워크플로우
Claude Code에서 커스텀 슬래시 커맨드를 만드는 방법을 설명합니다. 파일 배치, 인수 전달, 반복 작업 자동화까지 실용적인 코드 예제와 함께 소개합니다.