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?

Gemini CLI チートシート

0
Posted at

Gemini CLI チートシート


基本コマンド

起動・終了

gemini                          # 対話モード起動
gemini --help                   # ヘルプ表示
gemini --version                # バージョン確認
/quit                          # 終了(Ctrl+Dも可)

認証

gemini auth login              # ブラウザ認証
gemini auth login --api-key    # APIキー認証
gemini auth login --service-account  # サービスアカウント認証
gemini auth logout             # ログアウト
gemini auth status             # 認証状態確認

ファイル操作

ファイル参照(@コマンド)

> @ファイル名 を確認して           # ファイル内容を参照
> @src/**.ts のバグを修正         # ワイルドカード使用
> @folder/ 全体を解析             # ディレクトリ参照

ファイルシステムツール

read_file                      # ファイル読み込み
write_file                     # ファイル書き込み
replace                        # 文字列置換
list_directory                 # ディレクトリ一覧
search_file_content           # ファイル内検索
move_file                      # ファイル移動・リネーム

シェルコマンド実行

基本実行

> npm test を実行して            # コマンド実行
> git status を確認             # Git操作

特殊モード

> !npm install                 # !モード:直接シェル実行
> docker ps                    # インタラクティブコマンド対応

バックグラウンド実行

> npm run dev をバックグラウンドで  # 長時間実行タスク

コンテキスト管理

GEMINI.md

# プロジェクトルートに配置
# 階層的に適用される(global → workspace → project)

Memport

> /memory save project-overview   # メモリ保存
> /memory list                     # メモリ一覧
> /memory load project-overview    # メモリ読み込み
> /memory delete old-context       # メモリ削除

.geminiignore

# 無視するファイル・ディレクトリを指定
node_modules/
.env
*.log
dist/

セッション管理

セッション操作

gemini --resume                # 最新セッション復元
gemini --resume 1              # インデックス指定
gemini --resume abc123         # ID指定
gemini --list-sessions         # セッション一覧

CLI内コマンド

> /resume                      # セッションブラウザ起動
> /chat save session-name      # 名前付きで保存
> /chat resume session-name    # 名前で復元
> /chat list                   # セッション一覧
> /chat share                  # Markdown出力

セッションブラウザ

/          検索モード
↑/↓        選択移動
Space      プレビュー表示
Enter      復元
x          削除
q          終了

設定とカスタマイズ

設定ファイル

~/.gemini/config.json          # グローバル設定
./.gemini/config.json          # プロジェクト設定

主要設定項目

{
  "model": "gemini-2.5-flash",
  "contextWindow": "auto",
  "tokenCaching": {
    "enabled": true,
    "ttl": 3600
  },
  "theme": "dark",
  "vimMode": false,
  "editor": "code"
}

モデル選択

gemini --model gemini-2.5-flash    # Flash(高速)
gemini --model gemini-2.5-pro      # Pro(高精度)

Web検索とTodo

Web検索

> Next.js 15の新機能を調べて       # Web検索実行
> https://example.com を取得      # 特定URL取得

Todoツール

> Todoリストを作成してください
☐ タスク1
☐ タスク2
  ☐ サブタスク2-1

> 最初のタスクを完了
✓ タスク1

カスタムコマンド

コマンド定義(.gemini/commands.toml)

[[command]]
name = "test"
description = "テスト実行"
prompt = "npm testを実行し、結果を要約してください"

[[command]]
name = "deploy"
description = "デプロイ実行"
prompt = """
git statusを確認
変更があればコミット
mainブランチにマージ
デプロイコマンド実行
"""

使用方法

> /test                        # カスタムコマンド実行
> /deploy                      # デプロイ実行

チェックポイント

チェックポイント操作

> /checkpoint save before-refactor    # 保存
> /checkpoint list                     # 一覧
> /restore before-refactor             # 復元

Extensions・Skills・MCP

Extensions

# .gemini/extensions/my-extension.js
module.exports = {
  name: "my-extension",
  version: "1.0.0",
  activate: (context) => {
    // 拡張機能の実装
  }
}

Skills

~/.gemini/skills/my-skill/SKILL.md   # スキル定義

MCPサーバー設定

{
  "mcpServers": {
    "github": {
      "transport": "stdio",
      "command": "mcp-github"
    }
  }
}

Hooks

フック定義(.gemini/hooks/pre-tool.js)

module.exports = async (context) => {
  const { toolName, args } = context;
  
  if (toolName === 'run_shell_command') {
    console.log(`実行: ${args.command}`);
  }
  
  return { shouldProceed: true };
};

利用可能なフック

pre-session-start      セッション開始前
post-session-start     セッション開始後
pre-turn               ターン開始前
post-turn              ターン終了後
pre-tool               ツール実行前
post-tool              ツール実行後
pre-prompt             プロンプト送信前
post-response          応答受信後
on-error               エラー発生時
pre-session-end        セッション終了前
post-session-end       セッション終了後

セキュリティと運用

Trusted Folders

gemini --trust /path/to/project    # フォルダを信頼
gemini --untrust /path/to/project  # 信頼解除
gemini --list-trusted              # 信頼フォルダ一覧

Sandbox

gemini --sandbox                   # Sandbox モード起動

Policy Engine

# ~/.gemini/policies/security.toml
[[rule]]
priority = 3000
name = "Block dangerous commands"
decision = "deny"

[rule.conditions]
toolName = "run_shell_command"
argsPattern = "(rm -rf|dd if=)"

IDE統合

> /ide enable                      # IDE統合有効化
> /ide install                     # VS Code拡張インストール
> /ide status                      # 統合状態確認

ヘッドレスモード

JSON出力

gemini --headless --format json "src/app.tsを解析"

Markdown出力

gemini --headless --format markdown "READMEを生成"

プレーンテキスト

gemini --headless --format text "テスト実行"

トラブルシューティング

ログとデバッグ

gemini --verbose                   # 詳細ログ
gemini --debug                     # デバッグモード
tail -f ~/.gemini/logs/gemini.log  # ログ監視

キャッシュクリア

rm -rf ~/.gemini/cache/*           # キャッシュ削除

設定リセット

rm ~/.gemini/config.json           # 設定削除
gemini                             # 初回起動で再設定

よくあるエラー

# 認証エラー
gemini auth login

# ツール実行失敗
> /policies list    # ポリシー確認

# トークン超過
# config.json で model を flash に変更

ショートカットキー

デフォルトバインド

Ctrl+C         コマンド中断
Ctrl+D         終了
Ctrl+R         履歴検索
Ctrl+A         行頭移動
Ctrl+E         行末移動
Ctrl+U         行クリア
Ctrl+K         カーソル以降削除

Vimモード(有効時)

ESC            ノーマルモード
i              挿入モード
:q             終了
:w             保存(該当する場合)

便利なワークフロー

1. コードレビュー

> @src/**.ts をレビューして、問題点を指摘
> 指摘された箇所を修正
> git diff を確認

2. ドキュメント生成

> @src/api/ のAPIドキュメントを生成して docs/api.md に保存

3. テスト作成

> @src/utils/helper.ts のテストを作成
> tests/utils/helper.test.ts に保存

4. バグ修正

> エラーログを解析: @logs/error.log
> 原因を特定して修正案を提示
> 修正を適用

5. リファクタリング

> /checkpoint save before-refactor
> @src/legacy.js をTypeScriptに変換
> テスト実行して確認
# 問題があれば: /restore before-refactor
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?