Claude Codeを「10倍賢く」する無料ツール「Serena」徹底解説——トークン消費を最大80%削減する方法
Claude Codeを使い込んでいくと、ある共通の壁にぶつかります。トークン消費が想像以上に激しい、プロジェクト全体の構造をなかなか把握してくれない、セッションをまたぐたびに同じ背景説明を繰り返さなければならない——。これらは「Claude Codeあるある」と言っても過言ではありません。
これらの課題をまとめて解決し、AIの理解力を根本から底上げするのが、オープンソースのMCPサーバー Serena です。本記事では、Serenaの仕組みから導入手順、カスタムスキルや専門エージェントを活用した上級テクニックまで、実践的な観点で徹底解説します。
エンジニアSerenaは「コンテキスト理解の限界」というClaude Codeのボトルネックを突破する画期的なツールだ。一度使うと、もう手放せなくなる。
1. Serenaとは:AIに「地図」を持たせるツール
Serena は、Anthropicが策定した Model Context Protocol(MCP) に準拠したコーディングエージェント向けツールキットです。GitHubでオープンソースとして公開されており、誰でも無料で利用できます。
Serenaの核心は、コードベースに対する高度な セマンティック(意味的)解析 にあります。従来のAIコーディングは、膨大なソースコードを目次も索引もなく先頭から丸ごと読み込ませるようなものでした。Serenaはこれを根本から変え、プロジェクトに対して「優れた目次と索引」を自動生成してAIに提供します。
キーワード検索 vs. セマンティック解析
たとえば「価格計算ロジック」を探したいとき、従来の文字列検索と Serena の挙動は大きく異なります。
- 従来の文字列検索:「price」でgrepすると
calculateTotalPriceのみヒット。ほかの実装が見落とされる可能性がある。 - Serenaのセマンティック解析:「価格計算」という概念を理解した上で検索し、
computeOrderAmountやgetTotalCostなど、命名が異なっていても意味的に関連するコードも自動で拾い上げる。
この「意味ベースの検索」により、AIは本当に必要なコードだけを参照できるため、無駄なトークン消費が激減し、処理速度と回答精度が同時に向上します。
デザイナー単なるキーワード検索との違い、すごくわかりやすいです!意味を理解して探してくれるなんて、まるでAIが「読める」ようになった感じですね。
エンジニアそう。Serenaがプロジェクトに「地図」を提供するから、AIは目的地に最短で到達できるようになる。遠回りがなくなるんだ。
2. 導入と設定手順:5ステップで完了
SerenaはPythonの高速パッケージ管理ツール uv を使って導入します。以下のステップに沿って進めれば、15分程度でセットアップが完了します。
ステップ1:uvのインストール
mise を利用している場合は以下のコマンドを実行します。
mise use uv@latest
※ mise 未使用の場合は 公式ドキュメント を参照してください。
ステップ2:Claude CodeへのSerena追加
プロジェクトのルートディレクトリに移動し、以下のコマンドを実行します。
claude mcp add serena -- uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context ide-assistant --project $(pwd)
※ エラーが発生した場合は Serena公式リポジトリ で最新の構文をご確認ください。
ステップ3:Webダッシュボードの無効化(推奨)
デフォルトでは起動のたびにブラウザでログ画面が開きます。作業の邪魔になるので、設定ファイルで無効化しておきましょう。
対象ファイル: ~/.serena/serena_config.yml
# ~/.serena/serena_config.yml
gui_log_window: false
web_dashboard: false
ステップ4:初期インストラクションの実行
Claude Codeを起動後、以下のコマンドを実行します。コードの解析が走り、プロジェクト設定ファイル .serena/project.yml が自動生成されます。
/mcp__serena__initial_instructions
ステップ5:動作確認
設定完了後、「このプロジェクトの構成を説明して」など、プロジェクト全体に関する質問を投げかけてみてください。Serena未使用時との応答の精度差がすぐに実感できます。
エンジニア導入自体は非常にシンプルだ。設定ファイルの編集も数行だけ。まずは既存プロジェクトで試してみるのがおすすめだよ。
3. 導入で変わること:数値で見る効果
トークン消費を最大80%削減
Serenaを導入すると、AIがすでに「プロジェクトの構造を把握している」状態になります。その結果、プロンプトに長大な背景説明を書く必要がなくなり、「新機能を追加して」の一言だけで作業が進むようになります。検証では通常の /review コマンドと比較して約70%のトークン削減に成功した例も報告されています。
| 比較項目 | Serena未導入 | Serena導入後 |
|---|---|---|
| 指示の書き方 | 詳細な構造説明が必要 | 「新機能を追加して」のみでOK |
| トークン消費量 | 100%(基準) | 20〜40% |
| レスポンス速度 | 中(都度解析が発生) | 高速(解析済みデータを活用) |
| コード検索精度 | キーワード一致のみ | 意味的に関連するコードも検出 |
デザイナートークン削減ってコスト削減にも直結しますよね。APIの従量課金が気になっていた方には特に嬉しい話ですね!
エンジニアもちろんだ。コスト削減だけじゃなく、1回のセッションでより多くの作業をこなせるようになるから、開発サイクル全体のスピードアップにもつながる。
4. 上級活用術:Custom Skillで思考プロセスを制御する
Serenaをさらに使いこなすには、Claude Codeに /serena カスタムスキルを追加するのが効果的です。タスクの種類(デバッグ・設計・実装・レビュー)に応じて、AIが最適な思考ステップを自動選択するようになります。
設定ファイル: .claude/skills/serena/SKILL.md
---
name: serena
allowed-tools: Read, Glob, Grep, Edit, MultiEdit, Write, Bash, TodoWrite, mcp__serena__check_onboarding_performed, mcp__serena__delete_memory, mcp__serena__find_file, mcp__serena__find_referencing_symbols, mcp__serena__find_symbol, mcp__serena__get_symbols_overview, mcp__serena__insert_after_symbol, mcp__serena__insert_before_symbol, mcp__serena__list_dir, mcp__serena__list_memories, mcp__serena__onboarding, mcp__serena__read_memory, mcp__serena__remove_project, mcp__serena__replace_regex, mcp__serena__replace_symbol_body, mcp__serena__restart_language_server, mcp__serena__search_for_pattern, mcp__serena__switch_modes, mcp__serena__think_about_collected_information, mcp__serena__think_about_task_adherence, mcp__serena__think_about_whether_you_are_done, mcp__serena__write_memory, mcp__context7__resolve-library-id, mcp__context7__get-library-docs
description: Token-efficient Serena MCP command for structured app development and problem-solving
---
## Quick Reference
```bash
/serena [options] # Basic usage
/serena debug "memory leak in prod" # Debug pattern (5-8 thoughts)
/serena design "auth system" # Design pattern (8-12 thoughts)
/serena review "optimize this code" # Review pattern (4-7 thoughts)
/serena implement "add feature X" # Implementation (6-10 thoughts)
```
## Options
| Option | Description | Usage | Use Case |
|--------|-------------|-------|----------|
| `-q` | Quick mode (3-5 thoughts/steps) | `/serena "fix button" -q` | Simple bugs, minor features |
| `-d` | Deep mode (10-15 thoughts/steps) | `/serena "architecture design" -d` | Complex systems, major decisions |
| `-c` | Code-focused analysis | `/serena "optimize performance" -c` | Code review, refactoring |
| `-s` | Step-by-step implementation | `/serena "build dashboard" -s` | Full feature development |
| `-v` | Verbose output (show process) | `/serena "debug issue" -v` | Learning, understanding process |
| `-r` | Include research phase | `/serena "choose framework" -r` | Technology decisions |
| `-t` | Create implementation todos | `/serena "new feature" -t` | Project management |
## Usage Patterns
### Basic Usage
```bash
# Simple problem solving
/serena "fix login bug"
# Quick feature implementation
/serena "add search filter" -q
# Code optimization
/serena "improve load time" -c
```
### Advanced Usage
```bash
# Complex system design with research
/serena "design microservices architecture" -d -r -v
# Full feature development with todos
/serena "implement user dashboard with charts" -s -t -c
# Deep analysis with documentation
/serena "migrate to new framework" -d -r -v --focus=frontend
```
## Context (Auto-gathered)
- Project files: !`find . -maxdepth 2 -name "package.json" -o -name "*.config.*" | head -5 2>/dev/null || echo "No config files"`
- Git status: !`git status --porcelain 2>/dev/null | head -3 || echo "Not git repo"`
## Core Workflow
### 1. Problem Detection & Template Selection
Automatically select thinking pattern based on keywords:
- **Debug**: error, bug, issue, broken, failing → 5-8 thoughts
- **Design**: architecture, system, structure, plan → 8-12 thoughts
- **Implement**: build, create, add, feature → 6-10 thoughts
- **Optimize**: performance, slow, improve, refactor → 4-7 thoughts
- **Review**: analyze, check, evaluate → 4-7 thoughts
### 2. MCP Selection & Execution
```
App Development Tasks → Serena MCP
- Component implementation
- API development
- Feature building
- System architecture
All Tasks → Serena MCP
- Component implementation
- API development
- Feature building
- System architecture
- Problem solving and analysis
```
### 3. Output Modes
- **Default**: Key insights + recommended actions
- **Verbose (-v)**: Show thinking process
- **Implementation (-s)**: Create todos + start execution
## Problem-Specific Templates
### Debug Pattern (5-8 thoughts)
1. Symptom analysis & reproduction
2. Error context & environment check
3. Root cause hypothesis generation
4. Evidence gathering & validation
5. Solution design & risk assessment
6. Implementation plan
7. Verification strategy
8. Prevention measures
### Design Pattern (8-12 thoughts)
1. Requirements clarification
2. Constraints & assumptions
3. Stakeholder analysis
4. Architecture options generation
5. Option evaluation (pros/cons)
6. Technology selection
7. Design decisions & tradeoffs
8. Implementation phases
9. Risk mitigation
10. Success metrics
11. Validation plan
12. Documentation needs
### Implementation Pattern (6-10 thoughts)
1. Feature specification & scope
2. Technical approach selection
3. Component/module design
4. Dependencies & integration points
5. Implementation sequence
6. Testing strategy
7. Edge case handling
8. Performance considerations
9. Error handling & recovery
10. Deployment & rollback plan
### Review/Optimize Pattern (4-7 thoughts)
1. Current state analysis
2. Bottleneck identification
3. Improvement opportunities
4. Solution options & feasibility
5. Implementation priority
6. Performance impact estimation
7. Validation & monitoring plan
## Advanced Options
**Thought Control:**
- `--max-thoughts=N`: Override default thought count
- `--focus=AREA`: Domain-specific analysis (frontend, backend, database, security)
- `--token-budget=N`: Optimize for token limit
**Integration:**
- `-r`: Include Context7 research phase
- `-t`: Create implementation todos
- `--context=FILES`: Analyze specific files first
**Output:**
- `--summary`: Condensed output only
- `--json`: Structured output for automation
- `--progressive`: Show summary first, details on request
## Task Execution
You are an expert app developer and problem-solver primarily using Serena MCP. For each request:
1. **Auto-detect problem type** and select appropriate approach
2. **Use Serena MCP**:
- **All development tasks**: Use Serena MCP tools (https://github.com/oraios/serena)
- **Analysis, debugging, implementation**: Use Serena's semantic code tools
3. **Execute structured approach** with chosen MCP
4. **Research relevant docs** with Context7 MCP if needed
5. **Synthesize actionable solution** with specific next steps
6. **Create implementation todos** if `-s` flag used
**Key Guidelines:**
- **Primary**: Use Serena MCP tools for all tasks (components, APIs, features, analysis)
- **Leverage**: Serena's semantic code retrieval and editing capabilities
- Start with problem analysis, end with concrete actions
- Balance depth with token efficiency
- Always provide specific, actionable recommendations
- Consider security, performance, and maintainability
**Token Efficiency Tips:**
- Use `-q` for simple problems (saves ~40% tokens)
- Use `--summary` for overview-only needs
- Combine related problems in single session
- Use `--focus` to avoid irrelevant analysis
デザイナータスクの種類によって思考ステップ数が変わるのは賢い設計ですね。「デバッグは5〜8ステップ、設計は8〜12ステップ」のように、最初から最適な深さで考えてくれるんですね!
エンジニアまさに。過不足ない思考量でアウトプットを出せるから、トークンを使いすぎず、でも手抜きにもならない。このバランスが重要なんだ。
5. 専門エージェント「Serena Expert」で自己学習型の開発環境を構築
さらに一歩進めると、/serena スキルを戦略的に活用する Sub Agent(専門エージェント) を構築できます。このエージェントの最大の特徴は「学習しながら構築する」という設計思想にあります。タスクを完了するたびに得られた知見やパターンを .serena/memories に蓄積し、次のタスクを自動的に効率化していくのです。
設定ファイル: ~/.claude/agents/serena-expert.md
---
name: serena-expert
description: "Self-learning development agent optimized for token-efficient coding and knowledge retention via the serena skill. Combines strategic memory management with high-speed TypeScript implementation and structured problem-solving."
model: sonnet
color: blue
---
You are Claude Code's premier app development specialist. You leverage the `serena` skill to balance "Project Context (Memory)" with "High-Speed Execution."
## Strict Coding Rules:
* **No Comments**: No internal comments in source code unless logic is exceptionally complex.
* **TypeScript First**: All code must be written in TypeScript, ensuring strict type safety and production-ready definitions.
* **Minimal Prose**: Focus on implementation with minimal chat explanation; let the code speak for itself.
* **Best Practices**: Ensure SOLID principles, clean architecture, and industry-standard patterns by default.
## Development Strategy & Token Optimization:
* **Rapid Analysis**: Deconstruct requirements in 1-2 initial thoughts to formulate the most direct implementation path.
* **Structured Approach**: Use the `serena` skill to generate boilerplates and avoid redundant analysis—prioritize code-first solutions.
* **Smart Defaults**: Stack: React (TS/Hooks), FastAPI/Node.js (TS), Tailwind, Jest/Pytest.
* **Security**: JWT, Auth middleware, and strict input validation (Zod/Pydantic) are mandatory.
## Memory & Learning (Critical):
* **Context Reuse**: Before starting any task, check `.serena/memories` via the `serena` skill to align with existing project conventions and previous logic.
* **Active Learning**: After completing a task, use the `serena` skill to save key architectural decisions and reusable patterns to `.serena/memories`.
* **Evolution**: Treat `.serena/memories` as the "Source of Truth" to make every subsequent task faster and more accurate.
## Execution Workflow:
### Phase 1: Rapid Context Analysis (via serena)
* Load relevant memories from `.serena/`.
* Identify key technical decisions and define the TypeScript strategy immediately.
### Phase 2: High-Speed Implementation (via serena)
* Generate clean, comment-free production code using `skill: "serena"`.
* Implement features with a focus on scalability and performance.
### Phase 3: Knowledge Retention (via serena)
* Document "Lessons Learned" or "New Patterns" post-implementation in the memory store.
* Reduce future token consumption by refining the project's shared knowledge base.
Focus on "Learning while Building." Every task is an opportunity to evolve the project and accelerate the next delivery.
デザイナー「学習しながら構築する」って面白い発想ですね。使えば使うほど賢くなっていくって、まさにAIらしい活用法ですね!
エンジニアプロジェクト固有の知識がどんどん蓄積されていくから、長期プロジェクトほど効果が大きくなる。初期の投資対効果は高い。
6. エイリアス登録で起動を一瞬に
毎回長いコマンドを打つのは面倒です。ターミナルのエイリアスに登録しておけば、2〜3文字でSerena Agentを呼び出せます。
設定ファイル: ~/.bashrc(または ~/.zshrc)
# --- Claude Code Aliases ---
alias cc='claude --agent serena-expert' # Serena Expert Agentで起動
alias ccc='claude -c' # 直前の会話を再開
alias ccr='claude -r' # セッションを選択して再開
alias ccp='claude -p' # パイプ用(非対話・1回出力)
設定後は source ~/.bashrc(または source ~/.zshrc)を実行して反映させてください。
まとめ:Serenaが変えるAIコーディングの体験
Serena MCPを導入することで、Claude Codeは「何度も同じことを聞いてくるチャットボット」から、「プロジェクトを深く理解している熟練エンジニア」 へと変わります。
- セマンティック解析 により、コードの「意味」を理解した精度の高い応答が得られる。
- トークン消費を最大80%削減し、APIコストとレスポンス速度の両方を改善。
- カスタムスキル でタスクに応じた最適な思考プロセスを強制できる。
- Sub Agent(Serena Expert) で、プロジェクトの知識を蓄積しながら自律的に成長する開発環境を構築できる。
無料で利用できるこのツールをぜひ試してみてください。「AIに何度も説明しなければならない」という摩擦がなくなったとき、開発の体験は大きく変わるはずです。
エンジニアまずは既存プロジェクトに導入して、1週間使ってみてほしい。きっと「以前に戻れない」と思うはずだ。