0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Android エンジニア、Claude Code を使う![サブエージェント編]

0
Last updated at Posted at 2026-03-14

シリーズ記事

はじめに

今回は Claude Code のサブエージェントについて学んでいきます。まずは公式の説明を引用します。

サブエージェントは、特定の種類のタスクを処理する特化した AI アシスタントです。各サブエージェントは、カスタムシステムプロンプト、特定のツールアクセス、および独立した権限を備えた独自のコンテキストウィンドウで実行されます。Claude がサブエージェントの説明に一致するタスクに遭遇すると、そのサブエージェントに委譲され、サブエージェントは独立して動作し、結果を返します。

? よくわかりませんね💦 もうやってみるしかないです!

本シリーズの記事は基本的に Claude Code と会話しながら Claude Code をカスタマイズしていきますが、同時に公式ドキュメントも参考にしています。本記事を読んだ後に、公式ドキュメントも合わせて読むと Claude Code の理解がより深まると思います。

参考

サブエージェントを作る

Claude Code を起動し、以下のコマンドを実行します。

/agents 

Create new agent を選択します。

  Agents                                                    
  No agents found                            
  
  ❯ Create new agent 

  No agents found. Create specialized subagents that Claude can delegate to.
  Each subagent has its own context window, custom system prompt, and specific tools.
  Try creating: Code Reviewer, Code Simplifier, Security Reviewer, Tech Lead, or UX Reviewer.

保存場所を選ぶ画面が出るのでとりあえず「1. Project」を選びます。

  Create new agent
  Choose location

  ❯ 1. Project (.claude/agents/)
    2. Personal (~/.claude/agents/)
          
   ↑↓ to navigate · Enter to select · Esc to cancel

作成方法は推奨の「1. Generate with Claude」を選択します。

  Create new agent
  Creation method

  ❯ 1. Generate with Claude (recommended)
    2. Manual configuration        
                                                                            
   ↑↓ to navigate · Enter to select · Esc to go back

どんなサブエージェントを作りたいかを入力します。しかし、サブエージェントって何?という人にフリー入力させるのはかなり酷な話です。

  Create new agent
  Describe what this agent should do and when it should be used (be comprehensive for best results)

  e.g., Help me write unit tests for my code...
                                   
   Enter to submit · ctrl+g to open in editor · Esc to go back  

では、どんなサブエージェントを作るか検討してみましょう。例として Code、UX、セキュリティのレビューアーを挙げている記事を見かけますね。例えば Code レビューアーを作りたいと思ったとしても、レビュー観点を指定しないといけないはずです。レビュー観点の内容によってサブエージェントの良し悪しが決まるなら怖くて生半可なものを入力できません。

こういうときは Claude Code に助けてもらいましょう。私は、予め既存プロジェクトをターゲットにして Claude Code を起動し、 以下の相談をしていました。

Claude Code のサブエージェントを作りたいが、どのようなサブエージェントを作れば良いかわからない。
とりあえずUI/UX デザイナーを作ろうと思う。
今のプロジェクトの UI/UXをより魅力あるものにし、ユーザビリティーを向上させるなら、
サブエージェント作成時に何と入力すれば良いですか?

Claude Code が提案した UI/UX デザイナー

メモっておいた Claude Code にもらったサブエージェントの提案内容を入力します。

  Create new agent
  Describe what this agent should do and when it should be used (be comprehensive for best results)

    名前(Name):                              
    ui-ux-designer                 
                                                              
    説明(Description / System Prompt):                        
    あなたは Compose Multiplatform(Android / iOS)アプリの UI/UX
  デザイナーです。   
  
  (省略) 

  Enter to submit · ctrl+g to open in editor · Esc to go back

ツール選択は、全てお任せということで「All tools 」を選択しておきます。

  Create new agent
  Select tools

  
  ❯ [ Continue ]                   
  ────────────────────────────────────────
    ☒ All tools                                  
    ☒ Read-only tools                             
    ☒ Edit tools                                  
    ☒ Execution tools                             
    ☒ MCP tools                                   
    ☒ Other tools                                 
  ────────────────────────────────────────        
    [ Show advanced options ]
    
  All tools selected
  
   Enter to toggle selection · ↑↓ to navigate · Esc to go back    

モデルの選択は、デフォルトの「1. Sonnet」にしておきます。

  Create new agent
  Select model

  Model determines the agent's reasoning capabilities and speed.
                                   
  ❯ 1. Sonnet ✔             Balanced performance - best for most agents     
    2. Opus                 Most capable for complex reasoning tasks                                            
    3. Haiku                Fast and efficient for simple tasks                                                 
    4. Inherit from parent  Use the same model as the main conversation
                                          
   ↑↓ to navigate · Enter to select · Esc to go back 

背景色選択は、デフォルトの「Automatic color」にします。

  Create new agent
  Choose background color
  
  ❯ Automatic color
      Red                          
      Blue    
      Green                                       
      Yellow                                      
      Purple                                      
      Orange                                      
      Pink                                        
      Cyan

      
  Preview:  @ui-ux-designer
  
   ↑↓ to navigate · Enter to select · Esc to go back    

メモリの保存場所は、プロジェクトをスコープとする「1. Enable」を選択します。メモリ保存場所について詳しく知りたい方は 永続メモリを有効にするを参照ください。

  Create new agent
  Configure agent memory
  
  ❯ 1. Enable (.claude/agent-memory/) (Recommended)
    2. None (no persistent memory) 
    3. User scope (~/.claude/agent-memory/)
    4. Local scope (.claude/agent-memory-local/)
      
   ↑↓ to navigate · Enter to select · Esc to go back   

完成しました。

  Create new agent
  Confirm and save
  
  Name: ui-ux-designer
  Location: .claude/agents/ui-ux-designer.md
  Tools: All tools
  Model: Sonnet                                   
  Memory: Project (.claude/agent-memory/)
  
  Description (tells Claude when to use this agent):
  
    Use this agent when you want to analyze, improve, or implement UI/UX for Compose Multiplatform screens in   
    the 〇〇 project. This includes Material Design 3 compliance reviews, usability improvements,         
    accessibility checks, and Composa…
    
 (省略)

   
  Press s or Enter to save, e to save and edit
  
   s/Enter to save · e to edit in your editor · Esc to cancel

上記プロンプトで Enter キーを押すとサブエージェント作成完了です。
サブエージェントは作成されましたが、/agents コマンド実行後のプロントがまた表示されています。今度は先ほど作成した「ui-ux-designer」が表示されています。Esc キーでプロンプトを抜けましょう。

  Agents
  6 agents


  Created agent: ui-ux-designer

    Create new agent

    Project agents
  ❯ ui-ux-designer · sonnet · project memory

    Built-in agents (always available)
    claude-code-guide · haiku
    Explore · haiku
    general-purpose · inherit
    Plan · inherit
    statusline-setup · sonnet

  Press ↑↓ to navigate · Enter to select · Esc to go back

設定ファイルを見る

今回作ったサブエージェントの設定ファイルは .claude/agents/ui-ux-designer.md に作られます。

ui-ux-designer.md をみる

ui-ux-designer.md の最後に「Persistent Agent Memory」と「MEMORY.md」の章が存在するので存在理由を Claude Code に聞いてみました。

⏺ ui-ux-designer.md のフロントマターに memory: project が設定されているためです(5行目):

  memory: project
  
  この設定により Claude Code が自動的に以下を付加しました:
  
  - エージェント専用の永続メモリディレクトリ(.claude/agent-memory/ui-ux-designer/)        
  - メモリの使い方ガイドライン
  - 空の MEMORY.md(初回起動時)

  目的: ui-ux-designer がセッションをまたいで UI パターンや画面固有の知見を蓄積できるようにするためです。例えば「このプロジェクトでは ActionButton
  が自作実装」「_xxx StateFlow パターンを使用」などを記憶し、次回以降のレビューに活かせます。

  memory: none に変更するとこの機能は無効化されます。

サブエージェントを使う

公式ドキュメントは以下のようにしてサブエージェントを呼び出しています。

Use the code-improver agent to suggest improvements in this project

ui-ux-designer を呼び出してみます。

ui-ux-designer を使って UI/UX の改善を提案してください

以下の結果となりました。

 ---
  レビュー結果サマリー
  
  対象画面7つ(Home・Note・ShopList・Shop・EditShop・History・Schedule)を分析しました。
  
  高優先度(すぐに対処すべき)
  ┌─────┬──────────────────────────────────────────────────────────┬─────────────────────────┐
  │  #  │                           問題                           │        該当画面         │
  ├─────┼──────────────────────────────────────────────────────────┼─────────────────────────┤
  │ 1   │ タッチターゲットが 48dp 未満(アクセシビリティ違反)     │ Schedule, Shop, Report  │
  ├─────┼──────────────────────────────────────────────────────────┼─────────────────────────┤
  │ 2   │ 削除ボタンと保存ボタンが同一スタイル(誤タップリスク)   │ EditShop                │
  ├─────┼──────────────────────────────────────────────────────────┼─────────────────────────┤
  │ 3   │ 空状態がテキスト1行のみ(初回ユーザーが迷う)            │ Note, History, Schedule │
  ├─────┼──────────────────────────────────────────────────────────┼─────────────────────────┤
  │ 4   │ URL リンクが Color.Blue ハードコード(ダークモード崩れ) │ Shop                    │
  ├─────┼──────────────────────────────────────────────────────────┼─────────────────────────┤
  │ 5   │ 年月ヘッダーが "2024-01" 形式(非日本語)                │ History, Schedule       │
  └─────┴──────────────────────────────────────────────────────────┴─────────────────────────┘

  クイックウィン(変更が小さく効果大)

  1. 年月フォーマットを "2024年1月" に変更
  2. URL カラーを MaterialTheme.colorScheme.primary に変更
  3. ScheduleRow のアイコンを IconButton に置換

  ---
  どの改善から実装しますか?クイックウィン3つをまとめて、または個別に対応できます。

ui-ux-designer.md の「Persistent Agent Memory」「MEMORY.md」にしたがってレビュー結果ファイルが作成されています。

スクリーンショット 2026-03-14 17.02.00.png

review-2026-03-14.md を見る

指摘してもらった事は後日修正します。。。

サブエージェントを自動で呼び出す

サブエージェントをいちいち手動呼び出すは面倒だなと思ったので自動呼び出しができないか Claude Code に聞いてみると ui-ux-designer.md の「description」欄の冒頭に「proactively」や「after implementing」のような自動トリガーの文言を追加すれば良い、とのことでした。
そして以下のような自動トリガーの文言を Claude Code にしてもらいました。

PROACTIVELY use this agent after implementing or significantly modifying any Composable screen, even if the user did not explicitly request a UI/UX review.\

まとめ

今回はサブエージェントの作成を通して、サブエージェントとは何かを理解できました。
サブエージェントを一言で表すなら「特定の仕事を任せられる専門スタッフ」です。UI/UX デザイナーのサブエージェントを例に作成しましたが、コードレビューアーやセキュリティチェッカーなど、プロジェクトの課題に応じて専門家を増やしていけるイメージです。

シリーズを通じて CLAUDE.md → Hooks → メモリ → Skills → サブエージェントと順に積み上げてきました。それぞれ単独でも効果的ですが、組み合わせることで Claude Code がより「わかってる相棒」になっていく感覚があります。次のステップは、複数のサブエージェントを連携させる Agent teams です。引き続き一緒に学んでいきましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?