目次
こんにちは、エンジニアの有吉です。 6/25に Google 社から Geminiを活用するオープンソースの AI エージェント「Gemini CLI」のプレビュー版がリリースされました。 本記事はそれを早速使ってみたレビューとなります。
1. Gemini CLI とは
- Google が開発した AI モデルの CLI ツール
- Windows で簡単に扱えるのがポイント
- 公式ドキュメント
2. 事前に準備が必要なもの
- Node.js が必要
- 筆者の環境にはインストール済みだったため、 Node.js をインストールしていない環境で導入を進めるとどうういうことが起こるかは確認できませんでした
3. 導入手順
PowerShell でコマンドを実行するのですが。二種類の手段が用意されています。 ひとつは
npx https://github.com/google-gemini/gemini-cli
もうひとつは
npm install -g @google/gemini-cli
です。 両者の違いを以下に示します。
実行するコマンド | 特徴 |
---|---|
npx https://github.com/google-gemini/gemini-cli |
PC にインストールはされず、そのセッションに限り有能 |
npm install -g @google/gemini-cli |
PC にインストールされて、恒常的に使えるようになる |
セッションに限り有効とは、コマンドを実行した PowerShell を開いている間だけ有効ということです。
今回はお試しということで、前者で実行してみます。
PS C:\Users\****> npx https://github.com/google-gemini/gemini-cli
npm error code ENOENT
npm error syscall lstat
npm error path C:\Users\****\AppData\Roaming\npm
npm error errno -4058
npm error enoent ENOENT: no such file or directory, lstat 'C:\Users\****\AppData\Roaming\npm'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: C:\Users\****\AppData\Local\npm-cache\_logs\2025-06-27T02_32_07_552Z-debug-0.log
PS C:\Users\****>
公式ドキュメントは「コマンドを実行するだけ使える」と謳っていますが、どうやら実行に失敗した様子。
npm error enoent ENOENT: no such file or directory, lstat 'C:\Users\****\AppData\Roaming\npm'
という一文から、必要なフォルダがないことが原因とわかります(****はユーザー名です)。
ということで、フォルダを作ります。
PS C:\Users\****> mkdir C:\Users\****\AppData\Roaming\npm
ディレクトリ: C:\Users\****\AppData\Roaming
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2025/06/27 11:53 npm
再度、コマンドを実行すると……。
PS C:\Users\****> npx https://github.com/google-gemini/gemini-cli
███ █████████ ██████████ ██████ ██████ █████ ██████ █████ █████
░░░███ ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
░░░███ ███ ░░░ ░███ █ ░ ░███░█████░███ ░███ ░███░███ ░███ ░███
░░░███ ░███ ░██████ ░███░░███ ░███ ░███ ░███░░███░███ ░███
███░ ░███ █████ ░███░░█ ░███ ░░░ ░███ ░███ ░███ ░░██████ ░███
███░ ░░███ ░░███ ░███ ░ █ ░███ ░███ ░███ ░███ ░░█████ ░███
███░ ░░█████████ ██████████ █████ █████ █████ █████ ░░█████ █████
░░░ ░░░░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.
無事に実行に成功しました。
続くメッセージでテーマを選ぶように促されます。 好みのものをキーボードの上下キーで選んでエンターで決定します。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ > Select Theme Preview │
│ ○ ANSI Dark ┌─────────────────────────────────────────────────────┐ │
│ ○ Atom One Dark │ │ │
│ ○ Ayu Dark │ 1 # function │ │
│ ● Default Dark │ 2 -def fibonacci(n): │ │
│ ○ Dracula Dark │ 3 - a, b = 0, 1 │ │
│ ○ GitHub Dark │ 4 - for _ in range(n): │ │
│ ○ ANSI Light Light │ 5 - a, b = b, a + b │ │
│ ○ Ayu Light Light │ 6 - return a │ │
│ ○ Default Light Light │ │ │
│ ○ GitHub Light Light │ ╭─────────────────────────────────────────────────╮ │ │
│ ○ Google Code Light │ │ │ │ │
│ ○ Xcode Light │ │ No changes detected. │ │ │
│ │ │ │ │ │
│ Apply To │ ╰─────────────────────────────────────────────────╯ │ │
│ ● User Settings │ │ │
│ ○ Workspace Settings └─────────────────────────────────────────────────────┘ │
│ │
│ (Use Enter to select, Tab to change focus) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
続いてログインを促されます。 今回は Google アカウントでログインします。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Select Auth Method │
│ ● Login with Google │
│ ○ Gemini API Key │
│ ○ Vertex AI │
│ │
│ (Use Enter to select) │
│ │
│ Terms of Services and Privacy Notice for Gemini CLI │
│ │
│ https://github.com/google-gemini/gemini-cli/blob/main/docs/tos-privacy.md │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
この辺りは、特に迷うことはないかと思います。
ブラウザ側でログインを済ませて、PowerShell に戻ると対話が可能になっています。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Type your message or @path/to/file │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
> hello world
✦ Hello there! How can I help you today?
応答がありました。
> 日本語で応答を。
✦ はい、承知いたしました。これからは日本語で応答します。何かご用でしょうか?
日本語での問答ができることも確認できました。
4. 動かしてみる
大雑把に命令してみる
お手並み拝見ということで Unity プロジェクトの解析を依頼してみます。 なお、Gemini は実行しているユーザー名のフォルダ(C:\Users****)以下にしか閲覧できないという制約があるようです。 上記の外にあるフォルダを解析させるためには、中にコピーする必要があります。
> @***/Assets/ どのようなアプリケーションなのかの解析を。
✕ [API Error: [{
"error": {
"code": 400,
"message": "The input token count (3342721) exceeds the maximum number of tokens allowed (1048576).",
"errors": [
{
"message": "The input token count (3342721) exceeds the maximum number of tokens allowed
(1048576).",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
]]
トークン数の制限に引っかかってしまいました。
現状、大きなプロジェクトを丸ごと渡して解析という使い方はできないようです。
コンテキストを小さくする
ファイルがひとつだけのフォルダを解析させてみます。なお、プロジェクト名は伏せています。
@****/Assets/Script/ フォルダ内の解析を。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadManyFiles Will attempt to read and concatenate files using patterns: `****/Assets/… │
│ │
│ ### ReadManyFiles Result (Target Dir: `C:\Users\****`) │
│ │
│ Successfully read and concatenated content from **6 file(s)**. │
│ │
│ **Processed Files:** │
│ - `****/Assets/Script/Editor.meta` │
│ - `****/Assets/Script/Editor/PrefabFinder.meta` │
│ - `****/Assets/Script/Editor/PrefabFinder/PrefabScriptFinderWindow.cs` │
│ - `****/Assets/Script/Editor/PrefabFinder/PrefabScriptFinderWindow.cs.meta` │
│ - `****/Assets/Script/Editor/PrefabFinder/ScriptSearchSettings.cs` │
│ - `****/Assets/Script/Editor/PrefabFinder/ScriptSearchSettings.cs.meta` │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ はい、承知いたしました。****/Assets/Script/ フォルダ内のファイルを解析します。
まず、このフォルダの全体像を把握するために、どのようなファイルやサブフォルダが存在するか確認します。
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadFolder ...****\Assets\Script │
│ │
│ Listed 2 item(s). │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Scriptフォルダの下にはEditorというサブフォルダがあるようですね。
では、Editorフォルダの中身も見てみましょう。
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadFolder ****\Assets\Script\Editor │
│ │
│ Listed 2 item(s). │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Editorフォルダの下にはPrefabFinderというサブフォルダがあるようです。
さらにPrefabFinderの中身も見てみましょう。
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadFolder ****\Assets\Script\Editor\PrefabFinder │
│ │
│ Listed 4 item(s). │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ ファイル構造が把握できました。
- Assets/Script/Editor/PrefabFinder/PrefabScriptFinderWindow.cs:
- 指定したMonoScript(C#スクリプト)がアタッチされているプレハブをプロジェクト全体から検索するためのエデ
ィタ拡張ウィンドウです。
- Tools/Find Prefabs With Scriptメニューからウィンドウを開けます。
- 検索結果のプレハブをクリックすると、Projectビューでそのプレハブが選択されます。
- Assets/Script/Editor/PrefabFinder/ScriptSearchSettings.cs:
- PrefabScriptFinderWindow で使用される、検索対象のスクリプトを保存するためのScriptableObjectです。
要約すると、この Assets/Script フォルダには、「指定したスクリプトがアタッチされているプレハブを検索する」
という機能を持つエディタ拡張が含まれています。
この情報について、さらに詳しく知りたいことはありますか?
例えば、特定のスクリプトの処理内容など、ご希望があればお答えします。
PrefabScriptFinderWindow は筆者が作成したファイルで、正確に内容を言い当てています。
もう少し大きなコンテキストはどうか
Unity 公式のサンプルプロジェクトを解析させてみます。サンプルはいわゆる FPS ゲームです。
ファイル数はこのくらいですが、どうでしょうか。
> このフォルダの概要を教えて?
✦ はい、承知いたしました。
C:\Users\****\My project (1)\Assets フォルダの内容から、このプロジェクトの概要を説明します。
このフォルダは、Unityというゲームエンジンを使ったプロジェクトのアセット(素材)を管理する場所です。
フォルダ構成から判断すると、これは一人称視点のシューティングゲーム(FPS)のプロジェクトである可能性が非常
に高いです。
各フォルダの役割は以下のようになっていると推測されます。
* FPS: ゲームのコアとなる機能や、キャラクター、武器などの素材が入っていると思われます。
* NavMeshComponents:
AIキャラクターがマップ内を賢く移動するための経路探索(ナビゲーション)機能に関連するファイルです。
* Rendering: グラフィックスの描画方法(シェーダーやライティングなど)を管理するファイルです。
* TextMesh Pro: ゲーム内のテキストをきれいに表示するための人気の高いアセットです。
* UniversalRenderPipeline...: Unityの最新の描画システムである「Universal Render Pipeline (URP)」を使ってい
ることを示しています。これにより、様々なプラットフォームで高品質なグラフィックスを実現できます。
要約すると、このフォルダはURPを採用したUnity製のFPSゲームプロジェクトのアセット群、ということになります。
正解です。 いわゆる遺跡発掘の能力には期待できそうです。
実務能力は?
実務能力はどうかテストしてみます。
上記のエディタ拡張には、検索履歴がなく若干の不便さを感じていました。 そこで検索履歴を保存する機能の追加を依頼してみます。
> @****/Assets/Script/Editor/PrefabFinder/
機能拡張をしたい。検索したスクリプトの履歴の実装を。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadManyFiles Will attempt to read and concatenate files using patterns: `****/Assets/… │
│ │
│ ### ReadManyFiles Result (Target Dir: `C:\Users\****`) │
│ │
│ Successfully read and concatenated content from **4 file(s)**. │
│ │
│ **Processed Files:** │
│ - `****/Assets/Script/Editor/PrefabFinder/PrefabScriptFinderWindow.cs` │
│ - `****/Assets/Script/Editor/PrefabFinder/PrefabScriptFinderWindow.cs.meta` │
│ - `****/Assets/Script/Editor/PrefabFinder/ScriptSearchSettings.cs` │
│ - `****/Assets/Script/Editor/PrefabFinder/ScriptSearchSettings.cs.meta` │
✦ はい、承知いたしました。検索履歴を呼び出す機能を追加しますね。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ Edit ****\\ScriptSearchSettings.cs: using UnityEditor;... => using System.Collections.Gener.… │
│ │
│ 1 + using System.Collections.Generic; │
│ 2 using UnityEditor; │
│ 3 using UnityEngine; │
│ 4 │
│ 5 public class ScriptSearchSettings : ScriptableObject │
│ 6 { │
│ 6 - public MonoScript targetScript; │
│ 7 + public List<MonoScript> searchHistory = new List<MonoScript>(); │
│ 8 + public const int MaxHistoryCount = 10; │
│ 9 } │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ 次に、PrefabScriptFinderWindow.cs を変更して、履歴機能のUIとロジックを実装します。
- 検索履歴を保存・読み込みするための ScriptSearchSettings のインスタンスを取得する処理を追加します。
- 検索実行時に、検索したスクリプトを履歴の先頭に追加し、履歴が最大件数を超えた場合は古いものから削除します
。
- 履歴を表示するためのドロップダウンメニューを追加し、選択した履歴を検索対象のスクリプトに設定できるように
します。
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? Edit ****\\PrefabScriptFinderWindow.cs: using UnityEngine;... => using UnityEngine;... ← │
│ │
│ ... first 69 lines hidden ... │
│ 72 EditorGUIUtility.PingObject(prefab); │
│ 73 } │
│ 74 } │
│ 75 + EditorGUILayout.EndScrollView(); │
╭────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ Edit ****\\PrefabScriptFinderWindow.cs: using UnityEngine;... => using UnityEngine;... │
│ │
│ 1 using UnityEngine; │
│ 2 using UnityEditor; │
│ 3 using System.Collections.Generic; │
│ 4 + using System.Linq; │
│ 5 │
│ 6 public class PrefabScriptFinderWindow : EditorWindow │
│ 7 { │
│ 8 private MonoScript targetScript; │
│ 9 private System.Type scriptType; │
│ 10 private List<GameObject> foundPrefabs = new List<GameObject>(); │
│ 11 + private ScriptSearchSettings searchSettings; │
│ 12 + private Vector2 scrollPosition; │
│ 13 │
│ 14 [MenuItem("Tools/Find Prefabs With Script")] │
│ 15 public static void ShowWindow() │
│ 17 GetWindow<PrefabScriptFinderWindow>("Prefab Script Finder"); │
│ 18 } │
│ 19 │
│ 20 + private void OnEnable() │
│ 21 + { │
│ 22 + // 検索設定をロード │
│ 23 + var guids = AssetDatabase.FindAssets("t:ScriptSearchSettings"); │
│ 24 + if (guids.Length > 0) │
│ 25 + { │
│ 26 + var path = AssetDatabase.GUIDToAssetPath(guids[0]); │
│ 27 + searchSettings = │
│ AssetDatabase.LoadAssetAtPath<ScriptSearchSettings>(path); │
│ 28 + } │
│ 29 + else │
│ 30 + { │
│ 31 + // 設定ファイルがない場合は作成 │
│ 32 + searchSettings = CreateInstance<ScriptSearchSettings>(); │
│ 33 + AssetDatabase.CreateAsset(searchSettings, │
│ "Assets/Script/Editor/PrefabFinder/ScriptSearchSettings.asset"); │
│ 34 + AssetDatabase.SaveAssets(); │
│ 35 + } │
│ 36 + } │
│ 37 + │
│ 38 private void OnGUI() │
│ 39 { │
│ 40 GUILayout.Label("検索対象のスクリプトを選択", EditorStyles.boldLabel); │
│ 41 │
│ 42 targetScript = (MonoScript)EditorGUILayout.ObjectField("Script", targetScript, │
│ typeof(MonoScript), false); │
│ 43 │
│ 44 + // 検索履歴のドロップダウン │
│ 45 + if (searchSettings.searchHistory.Count > 0) │
│ 46 + { │
│ 47 + var historyNames = searchSettings.searchHistory.Select(s => │
│ s.name).ToArray(); │
│ 48 + int selectedIndex = -1; │
│ 49 + selectedIndex = EditorGUILayout.Popup("検索履歴", selectedIndex, │
│ historyNames); │
│ 50 + if (selectedIndex != -1) │
│ 51 + { │
│ 52 + targetScript = searchSettings.searchHistory[selectedIndex]; │
│ 53 + } │
│ 54 + } │
│ 55 + │
│ 56 if (GUILayout.Button("Find Prefabs")) │
│ 57 { │
│ 58 SearchPrefabs(); │
│ 63 EditorGUILayout.Space(10); │
│ 64 GUILayout.Label($"見つかったプレハブ: {foundPrefabs.Count}個", │
│ EditorStyles.boldLabel); │
│ 65 │
│ 66 + scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); │
│ 67 foreach (var prefab in foundPrefabs) │
│ 68 { │
│ 69 if (GUILayout.Button(AssetDatabase.GetAssetPath(prefab))) │
│ 72 EditorGUIUtility.PingObject(prefab); │
│ 73 } │
│ 74 } │
│ 75 + EditorGUILayout.EndScrollView(); │
│ 76 } │
│ 77 } │
│ 78 │
│ ═════════════════════════════════════════════════════════════════════════════════════════════ │
│ 86 return; │
│ 87 } │
│ 88 │
│ 89 + // 検索履歴に追加 │
│ 90 + if (!searchSettings.searchHistory.Contains(targetScript)) │
│ 91 + { │
│ 92 + searchSettings.searchHistory.Insert(0, targetScript); │
│ 93 + if (searchSettings.searchHistory.Count > │
│ ScriptSearchSettings.MaxHistoryCount) │
│ 94 + { │
│ 95 + │
│ searchSettings.searchHistory.RemoveAt(searchSettings.searchHistory.Count - 1); │
│ 96 + } │
│ 97 + EditorUtility.SetDirty(searchSettings); │
│ 98 + } │
│ 99 + │
│ 100 scriptType = targetScript.GetClass(); │
│ 101 │
│ 102 if (scriptType == null || !scriptType.IsSubclassOf(typeof(MonoBehaviour))) │
╰────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ これで、検索履歴の呼び出し機能が追加されました。
Unityエディタの Tools > Find Prefabs With Script
からウィンドウを開くと、検索履歴がドロップダウンで表示されるようになっているはずです。
何か他に機能追加のご希望はありますか?
ものの数秒で機能が追加されました。
しかし、実際に画面を見てみると、履歴は保存されているものの、どの履歴を呼び出しているかの表示がありません。
修正を依頼してみます。
> 検索履歴のドロップダウンリストに、選択中のアイテムを表示するように。
✦ はい、承知いたしました。ドロップダウンリストに現在選択されているアイテムが表示されるように修正します。
PrefabScriptFinderWindow.csのOnGUIメソッドを以下のように変更します。
- EditorGUILayout.Popupの第二引数に、現在選択されているスクリプトのインデックスを渡すようにします。これによ
り、ドロップダウンに現在の選択状態が反映されます。
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ Edit ****\\PrefabScriptFinderWindow.cs: // 検索履歴のドロップダウン... => // 検… │
│ │
│ 45 if (searchSettings.searchHistory.Count > 0) │
│ 46 { │
│ 47 var historyNames = searchSettings.searchHistory.Select(s => s.name).ToArray(); │
│ 48 - int selectedIndex = -1; │
│ 49 - selectedIndex = EditorGUILayout.Popup("検索履歴", selectedIndex, historyNames); │
│ 48 + int currentIndex = searchSettings.searchHistory.IndexOf(targetScript); │
│ 49 + int selectedIndex = EditorGUILayout.Popup("検索履歴", currentIndex, │
│ historyNames); │
│ 50 if (selectedIndex != -1) │
│ 51 { │
│ 52 targetScript = searchSettings.searchHistory[selectedIndex]; │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ これで、検索履歴のドロップダウンリストに現在選択されているスクリプトが表示されるようになりました。
他に何かご要望はありますか?
バッチリです。
一行もコードを書くことなく、機能の実装が完了しました。
5. 終わりに
というわけで、Gemini のお試しでした。 この手のものは Windows 環境単体で動作するものはまだ少なく、導入が容易であることが大きなメリットであると感じました。
昨今、AI 技術の発展によって、これまでは未知のプロジェクトの保守などは、既存のコードの解析が多くの時間が必要だったりもしましたが、うまく使えば相当な工数削減ができるようになってきています。Gemini にも期待したいところです。
弊社ではAIを積極活用して、効率的な開発体制の実現に取り組んでおります。 また、AI導入やツール選定に関するご相談も承っておりますので、ぜひお気軽にお問い合わせください。