mcpField
G
Gemini CLI

Gemini CLI

github.com/ovachieverエージェントワークフロー5659 回インストール48 週間前に更新
リポジトリ

Gemini CLI について

Gemini CLI は、Claude Code から Google の Gemini CLI を利用するためのスキルです。モデル選択やコマンド例を示し、設計の相談、セキュリティレビュー、デバッグ、コード分析に活用できます。

主な機能

  1. 01設計判断へのセカンドオピニオン
  2. 02セキュリティ監査
  3. 03デバッグ相談
  4. 04コードとリファクタリングのレビュー
  5. 05Flash と Pro のモデル選択

活用シーン

  1. 01技術選択肢の比較
  2. 02認証関連の変更のレビュー
  3. 03繰り返すエラーの調査
  4. 04大規模なリファクタリング計画の評価

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/ovachiever/droid-tings --skill gemini-cli

インストール後、Claude Code で/gemini-cliを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

README.md
.claude-plugin/
plugin.json
references/
models-guide.md
prompting-strategies.md
scripts/
setup-slash-command.sh
test-connection.sh

詳細

Gemini CLI

Claude Code のワークフローで、Gemini の 100 万以上のコンテキストウィンドウを AI ペアプログラマーとして活用できます。

このスキルでは、公式の Google Gemini CLI(gemini コマンド)を使用して、セカンドオピニオン、アーキテクチャに関するアドバイス、デバッグの支援、包括的なコードレビューを得る方法を Claude Code に教えます。公式 CLI ツールを本番環境でテストした結果に基づいています。


目次

  1. クイックスタート
  2. Gemini に相談するタイミング
  3. インストール
  4. Gemini CLI の使用方法
  5. モデルの選択:Flash と Pro
  6. 積極的に相談するパターン
  7. AI 間のプロンプト作成に関するベストプラクティス
  8. 一般的なユースケース
  9. 統合例
  10. トラブルシューティングと既知の問題

クイックスタート

前提条件:

  • Gemini CLI がインストールされていること(npm install -g @google/gemini-cli)
  • Google アカウントで認証済みであること(認証するには、gemini を一度実行します)

基本的な使用パターン:

# Quick question (non-interactive with -p flag)
gemini -p "Should I use D1 or KV for session storage?"

# Code review with file context (using --all-files)
gemini --all-files -p "Review this auth implementation for security issues"

# Architecture advice using Pro model
gemini -m gemini-2.5-pro -p "Best way to handle WebSockets in Cloudflare Workers?"

# Pipe file content for review
cat src/auth.ts | gemini -p "Review this authentication code for security vulnerabilities"

# Interactive mode for follow-up questions
gemini -i "Help me debug this authentication error"

Gemini に相談するタイミング

必ず相談するケース(重要なシナリオ)

Claude Code は、次の状況で自動的に Gemini を呼び出す必要があります。

  1. 重要なアーキテクチャ上の決定

    • 例:「セッションストレージには D1 と KV のどちらを使うべきですか?」
    • 例:「長時間実行されるタスクには Durable Objects と Workflows のどちらを使うべきですか?」
    • 理由:Gemini は補完的な視点を提供し、異なる懸念事項を優先する場合があります
    • パターン:gemini -m gemini-2.5-pro -p "[architectural question]"
  2. セキュリティに関わるコード変更

    • 認証システム
    • 決済処理
    • データの取り扱い(PII、機密データ)
    • API キー/シークレットの管理
    • 理由:Gemini 2.5 Pro はセキュリティ監査に優れています
    • パターン:cat [security-file] | gemini -m gemini-2.5-pro -p "Security audit this code"
  3. 大規模なリファクタリング

    • 5 ファイル以上に影響する場合
    • コアアーキテクチャの変更
    • データベーススキーマの移行
    • 理由:新たな視点により、視野が狭くなるのを防げます
    • パターン:gemini --all-files -m gemini-2.5-pro -p "Review this refactoring plan"
  4. デバッグに行き詰まった場合(2 回以上失敗)

    • デバッグを 2 回試みてもエラーが解消しない
    • スタックトレースが不明瞭
    • 断続的に発生するバグ
    • 理由:異なる推論アプローチで根本原因を発見できる場合があります
    • パターン:gemini -p "Help debug: [error message]" < error.log
  5. コンテキストウィンドウの圧迫(70% 以上使用)

    • トークン上限に近づいている
    • 分析を Gemini に任せる必要がある
    • 理由:Gemini の 100 万コンテキストウィンドウは、大きなコードファイルを扱えます
    • パターン:cat large-file.ts | gemini -p "Analyze this code structure"
必要に応じて相談するケース
  1. 不慣れな技術

    • ライブラリやフレームワークを初めて使う場合
    • 新しいパターンを試す場合
    • 理由:Gemini のほうが新しい学習データを持っている可能性があります
    • パターン:gemini -p "Best practices for [new technology]"
  2. コードレビュー

    • 大きな変更をコミットする前
    • プルリクエストの準備
    • 理由:エッジケースや改善点を見つけられます
    • パターン:git diff | gemini -p "Review these changes"

インストール

1. Gemini CLI をインストールする
npm install -g @google/gemini-cli
2. 認証する
gemini

認証のプロンプトに従って、Google アカウントをリンクしてください。

3. インストールを確認する
gemini --version

バージョン 0.13.0 以上が表示されるはずです。

4. 接続をテストする
gemini -p "What is 2+2?"

Gemini CLI の使用方法

基本的なコマンドパターン
非対話モード(-p フラグ)

Claude Code との統合に最適です。

# Direct question
gemini -p "Your question here"

# With model selection
gemini -m gemini-2.5-flash -p "Quick debugging question"
gemini -m gemini-2.5-pro -p "Complex architectural decision"

# With file context via pipe
cat src/auth.ts | gemini -p "Review this code"

# With all files in current directory
gemini --all-files -p "Analyze project structure"

# With stdin input
echo "Error: Cannot connect to database" | gemini -p "Help debug this error"
対話モード(-i フラグ)

会話を続ける場合に使用します。

# Start interactive session with initial prompt
gemini -i "Let's discuss the architecture"

# Interactive with model selection
gemini -m gemini-2.5-pro -i "Help me design a database schema"
YOLO モード(-y フラグ)

すべての操作を自動的に承認します(使用には注意してください)。

# Dangerous: Auto-executes suggested commands
gemini -y -p "Fix all linting errors"

⚠️ 警告:YOLO モードでは、確認なしでコマンドが実行される場合があります。信頼できる環境でのみ使用してください。


モデルの選択:Flash と Pro

gemini-2.5-flash(デフォルト)

特徴:

  • 応答時間が短い:約5~25秒
  • ほとんどのタスクで十分な品質
  • 低コスト
  • 一般的な質問に安全に使用できます

用途:

  • コードレビュー
  • デバッグ
  • 一般的な質問
  • 迅速な相談
  • 速度が重要な場合

例:

gemini -m gemini-2.5-flash -p "Review this function for performance issues"
gemini-2.5-pro

特徴:

  • 応答時間:約15~30秒
  • 優れた品質と詳細な分析
  • 高コスト
  • 重要な意思決定に最適

用途:

  • アーキテクチャの意思決定(重要)
  • セキュリティ監査(詳細な調査)
  • 複雑な推論タスク
  • 大規模なリファクタリング計画
  • 速度より正確性が重要な場合

例:

gemini -m gemini-2.5-pro -p "Security audit this authentication system"
gemini-3-pro-preview(プレビュー版 — 2025年11月)

特徴:

  • Google の最新かつ最も高性能な AI モデル(2025年11月18日発表)
  • 最先端の推論能力とマルチモーダル理解
  • 主要なすべての AI ベンチマークで Gemini 2.5 Pro を上回ります
  • テキスト、画像、動画、音声、PDF の入力に対応
  • 応答時間:未定(テスト中)
  • 高コスト(プレビュー版の料金)

用途:

  • 詳細な分析を必要とする、最も複雑な推論タスク
  • 最先端のプロジェクトにおける重要なアーキテクチャの意思決定
  • 高度なマルチモーダル分析(図、動画、複雑なドキュメント)
  • ベンチマークの結果が重要なアプリケーション
  • 最高品質が絶対に必要な場合(コストは二次的な要素)

例:

gemini -m gemini-3-pro-preview -p "Deep architectural analysis of this distributed system"
cat architecture-diagram.png | gemini -m gemini-3-pro-preview -p "Analyze this system design"

⚠️ プレビュー版について:モデルはプレビュー版です。本番環境に関わる重要な意思決定では、Gemini 3 が一般提供されるまで、gemini-2.5-pro(安定版)の使用を検討してください。

選び方
Quick question? → Flash
Security/architecture? → 3-Pro-Preview (cutting-edge) or 2.5-Pro (stable)
Debugging? → Flash (try Pro if stuck)
Code review? → Flash
Refactoring 5+ files? → 3-Pro-Preview or 2.5-Pro
Multimodal analysis? → 3-Pro-Preview

先回りして相談するパターン

パターン 1:アーキテクチャの意思決定

トリガー:ユーザーが技術の選択について質問する Claude の動作:セカンドオピニオンを得るため Gemini に自動的に相談する

# Claude runs:
gemini -m gemini-2.5-pro -p "Compare D1 vs KV for session storage in Cloudflare Workers. Consider: read/write patterns, cost, performance, complexity."

# Then synthesizes both perspectives
パターン 2:セキュリティレビュー

トリガー:認証、決済、機密性の高いコードを扱っている Claude の動作:Gemini にセキュリティ監査を依頼する

# Claude runs:
cat src/auth/verify-token.ts | gemini -m gemini-2.5-pro -p "Security audit this authentication code. Check for: token validation, timing attacks, injection vulnerabilities, error handling."
パターン 3:デバッグ支援

トリガー:2回試してもエラーが解消しない Claude の動作:Gemini の見解を得る

# Claude runs:
echo "[error message and stack trace]" | gemini -p "Help debug this error. What's the likely root cause?"
パターン 4:コードレビュー

トリガー:大規模な変更をコミットできる状態になった Claude の動作:包括的なレビューを依頼する

# Claude runs:
git diff HEAD | gemini --all-files -p "Review these changes for: correctness, edge cases, performance, security, best practices."

AI から AI へのプロンプト作成のベストプラクティス

Claude から Gemini に送るプロンプトの形式

✅ 良い例:豊富なコンテキストと具体性

gemini -m gemini-2.5-pro -p "I'm building a Cloudflare Worker with user authentication. Should I use D1 or KV for storing session data? Consider: 1) Session reads on every request, 2) TTL-based expiration, 3) Cost under 10M requests/month, 4) Deployment complexity."

❌ 悪い例:曖昧でコンテキストがない

gemini -p "D1 or KV?"
プロンプト構成のテンプレート
[Context: What you're building]
[Question]
[Considerations: Key factors (numbered)]
例:アーキテクチャの意思決定
gemini -m gemini-2.5-pro -p "
Context: Building a real-time collaborative editing app on Cloudflare Workers.

Question: Should I use Durable Objects or Workflows for managing document state?

Considerations:
1. Need to handle WebSocket connections (100+ simultaneous users per document)
2. Document state must be consistent across all clients
3. Need to persist changes every 5 seconds
4. Budget: <\$100/month at 1000 documents
5. Simple deployment preferred
"

一般的なユースケース

1. 技術の選定
# Compare two technologies
gemini -m gemini-2.5-pro -p "Compare Drizzle ORM vs raw SQL for Cloudflare D1. Consider: type safety, performance, query complexity, bundle size."
2. セキュリティ監査
# Audit authentication code
cat src/middleware/auth.ts | gemini -m gemini-2.5-pro -p "
Security audit this authentication middleware. Check for:
1. Token validation vulnerabilities
2. Timing attack risks
3. Error handling leaks
4. CSRF protection
5. Rate limiting
"
3. デバッグでの根本原因の特定
# Analyze error logs
tail -100 error.log | gemini -p "
These errors started appearing after deploying auth changes. What's the likely root cause?

Context:
- Added JWT validation middleware
- Using @cloudflare/workers-jwt
- Errors only on /api/* routes
"
4. コードレビュー
# Review pull request changes
git diff main...feature-branch | gemini --all-files -p "
Review this pull request. Focus on:
1. Breaking changes
2. Edge cases not handled
3. Performance implications
4. Security concerns
"
5. リファクタリング計画
# Plan large refactor
gemini --all-files -m gemini-2.5-pro -p "
I want to refactor this Express app to Cloudflare Workers with Hono. Analyze the codebase and suggest:
1. Migration order (which routes first)
2. Potential blockers (middleware that won't work)
3. Testing strategy
4. Deployment plan
"
6. パフォーマンスの最適化
# Analyze performance
cat src/api/heavy-endpoint.ts | gemini -p "
This endpoint is slow (500ms+ response time). Identify performance bottlenecks and suggest optimizations.

Context:
- Cloudflare Worker
- Fetches data from 3 external APIs
- Processes 1000+ items
"

統合例

例 1:Claude が Gemini に自動的に相談する

シナリオ:ユーザーがアーキテクチャについて質問する

User: "Should I use D1 or KV for storing user sessions?"

Claude (internal): This is an architectural decision. Consult Gemini for second opinion.

[Runs: gemini -m gemini-2.5-pro -p "Compare D1 vs KV for user session storage in Cloudflare Workers..."]

Claude (to user): "I've consulted Gemini for a second opinion. Here's what we both think:

My perspective: [Claude's analysis]
Gemini's perspective: [Gemini's analysis]

Key differences: [synthesis]
Recommendation: [combined recommendation]"
例 2:コミット前のセキュリティレビュー
User: "Ready to commit these auth changes"

Claude (internal): Security-sensitive code. Request Gemini audit.

[Runs: cat src/auth/*.ts | gemini -m gemini-2.5-pro -p "Security audit..."]

Claude (to user): "I've reviewed the code and consulted Gemini for security concerns:

Gemini identified: [security issues]
Additional checks I recommend: [Claude's additions]

Safe to commit after addressing: [list]"
例 3:デバッグ支援
User: "Still getting this error after trying your suggestions: [error]"

Claude (internal): Two failed attempts. Consult Gemini for fresh perspective.

[Runs: echo "[error details]" | gemini -p "Help debug..."]

Claude (to user): "Let me get a second opinion from Gemini...

Gemini suggests: [Gemini's diagnosis]
This makes sense because: [Claude's analysis]
Let's try: [combined solution]"

トラブルシューティングと既知の問題

問題 1:認証されていない

エラー:Error: Not authenticated

解決方法:

gemini
# Follow authentication prompts
問題 2:モデルが見つからない

エラー:Error: Model not found: gemini-2.5-flash-lite

原因:モデルが非推奨になったか、名前が変更された

解決方法:

# Use stable models
gemini -m gemini-2.5-flash -p "Your question"
gemini -m gemini-2.5-pro -p "Your question"
問題 3:レート制限

エラー:Error: Rate limit exceeded

解決方法:1~5分待ってから、再試行してください

予防策:リクエストの間隔を空けてください

問題 4:大きなファイルのコンテキスト

エラー:ファイルがコンテキストに対して大きすぎる

解決方法:--all-files を慎重に使用するか、必要なセクションを指定してパイプで渡してください

# Instead of:
gemini --all-files -p "Review everything"

# Do:
cat src/specific-file.ts | gemini -p "Review this file"
問題 5:コマンドが停止する

原因:非対話型の実行を想定しているのに、対話型モードになっている

解決方法:非対話型コマンドでは、必ず -p フラグを使用してください

# ✅ Correct
gemini -p "Question"

# ❌ Wrong (will hang waiting for input)
gemini "Question"

本番環境でのベストプラクティス

1. 自動化には必ず -p を使用する
# ✅ Good for scripts
gemini -p "Question"

# ❌ Bad for scripts (interactive)
gemini
2. 重要度に応じてモデルを選択する
# Architecture/security → Pro
gemini -m gemini-2.5-pro -p "[critical question]"

# Debugging/review → Flash
gemini -m gemini-2.5-flash -p "[general question]"
3. プロンプトにコンテキストを含める
# ✅ Good
gemini -p "Context: Building Cloudflare Worker. Question: Best auth pattern? Considerations: 1) Stateless, 2) JWT, 3) <100ms overhead"

# ❌ Bad
gemini -p "Best auth?"
4. レビューではファイルの内容をパイプで渡す
# ✅ Good
cat src/auth.ts | gemini -p "Review for security"

# ❌ Inefficient
gemini -p "Review src/auth.ts" # Gemini has to read file separately
5. エラーを適切に処理する
# Add error handling
if output=$(gemini -p "Question" 2>&1); then
  echo "Gemini says: $output"
else
  echo "Gemini consultation failed, proceeding with Claude's recommendation"
fi
6. 転送するだけでなく、統合する

❌ 悪い例:Gemini の回答をそのまま貼り付ける

User: "Should I use D1?"
Claude: [runs gemini] "Gemini says: [paste]"

✅ 良い例:両方の視点を統合する

User: "Should I use D1?"
Claude: [runs gemini]
"I've consulted Gemini for a second opinion:

My analysis: [Claude's perspective]
Gemini's analysis: [Gemini's perspective]
Key differences: [synthesis]
Recommendation: [unified answer]"

バージョン履歴

2.1.0(2025-11-19):

  • Gemini 3 Pro Preview モデル(gemini-3-pro-preview)を追加
  • Gemini 3 のモデル選択に関するガイダンスを更新
  • マルチモーダル分析のユースケースを追加
  • モデル比較マトリックスを更新

2.0.0(2025-11-13):

  • 公式の Gemini CLI 向けに全面改訂(gemini-coach ラッパーを削除)
  • CLI との直接連携パターン
  • 主要なユースケースに絞って簡素化
  • gemini CLI v0.13.0 以降に合わせてコマンド例を更新

1.0.0(2025-11-08):

  • gemini-coach ラッパーとともに初回リリース
  • 本番環境でのテストと実験
  • 8 件以上のエラーを事前に防止したことを記録

関連スキル


ライセンス

MIT - LICENSE を参照


サポート

コメント