今更ながらGithub Copilot CLIを試すので自分用のメモ。
よく使うコマンド
- Copilotを開く プロジェクトフォルダに移動して copilot
- ファイルを参照して回答させる @ファイル
例文
copilot
> Review @samples/book-app-project/utils.py and suggest improvements
> Add type hints to all functions
> Make the error handling more robust
アプリを説明させる。
copilot
> @samples/book-app-project/
> In one paragraph, what does this app do and what are its biggest quality issues?
あとはとえりあえず/を打てばコマンド候補が出てくる。
基本の3つのモード
- Plan
複雑な作業の場合は先に考えさせる。
copilot
> /plan Add a "mark as read" command to the book app
-
Interactive
通常に話しかければこのモードになる -
Programmatic
1回限りでCopilotをコマンドで実行させる
スクリプト内でコミットメッセージ自動生成させたり、DevOps Pipelineなどの中でやるのであればこの形が便利。
# Generate commit messages automatically
$COMMIT_MSG = copilot -p "Generate a commit message for: $(git
diff --staged)"
git commit -m "$COMMIT_MSG"
# Review a file
copilot --allow-all -p "Review @myfile.py for issues"
--allow-allがないとスクリプトでは動かないので注意
# Review all Python files in the book app
Get-ChildItem samples/book-app-project/*.py | ForEach-Object {
$relativePath = "samples/book-app-project/$($_.Name)";
Write-Host "Reviewing $relativePath...";
copilot --allow-all -p "Quick code quality review of @$relativePath - critical issues only"
}
Agent
Github Copilot用の設定ファイル。用途によって使い分ける必要がある。以下のサイトに詳しくまとまっているので、リンクを貼る。
分け方として大きく以下に分かれる。
・copilot-instrunctions.md
・*.instructions.md
以下のリンク先にシェアされている便利なMITライセンスで既存のAgentのテンプレートが数多く公開されている。
C#用、AzureのTerraformなど言語特定やAzureのPrincipal Architectなどプラットフォーム寄りのものもあれば、api-architect-agentなど設計寄りのものもあるので、まずはこれからスタートすればよさそう。
copilot-instructions.md
AgentでAIにカスタムプロンプトを与えられる。
/init を実行すると既存のプロジェクトでもReadMeや既存アプリの構造を読み取ってcopilot-instructions.mdを作ってくれる。デフォルトで作った後に、AIがプロジェクトを見通せるように以下のような内容を記載する。Agentが作業をするときに自動で読み込まれるプロンプト。
copilot-instructions.mdが肥大化してきたら、エージェントは種類によって専門的なinstructionに分ける。
.github/
└── instructions/
├── python-standards.instructions.md
├── security-checklist.instructions.md
└── api-design.instructions.md
Awesome GitHub Copilot MCP Server
ちなみにAwesome GitHub Copilot MCP Serverというのを使うと開発をするうえでの各フェーズで有用なプロンプトなどを見つけることができる。
Agent.md
こっちはもっと特定の作業に特化した指示ファイル。明示的にどのエージェントを使うか指定する必要がある。
デフォルトであるPlanのAgentとかは実はこれで作られている。descriptionは必須。通常はファイル名がエージェント名になる。
以下のように設定すると拡張子でAgentの対象を限定できる。
---
name: python-reviewer
description: Python code quality specialist for reviewing Python projects
tools: ["read", "edit", "search", "execute"]
applyTo: "**/*.py"
---
# Python Code Reviewer
You are a Python specialist focused on code quality and best practices.
**Your focus areas:**
- Code quality (PEP 8, type hints, docstrings)
- Performance optimization (list comprehensions, generators)
- Error handling (proper exception handling)
- Maintainability (DRY principles, clear naming)
**Code style requirements:**
- Use Python 3.10+ features (dataclasses, type hints, pattern matching)
- Follow PEP 8 naming conventions
- Use context managers for file I/O
- All functions must have type hints and docstrings
**When reviewing code, always check:**
- Missing type hints on function signatures
- Mutable default arguments
Agentを置く場所で一時的、プロジェクト単位、自分で恒久的に使うかを分けられる。

- プロジェクト単位であれば、.github/agents/myagent.agent.md
- ユーザー単位であればユーザーフォルダ配下に置く。C:\Users{user}.copilot\agents
試しに作るとユーザー単位のものもちゃんと選択肢に上がるようになった。
Gitのエージェントやドキュメント関連のAgentなんかはユーザー単位で入れておくといいかもしれない。
Skills
「エージェントはコパイロットの思考を変えますが、スキルはコパイロットにタスクの特定の方法を教えます。」

特定の手順で反復が必要なタスクを実行させるにはAgentではなく、Skillを利用する。
以下からコミュニティで作成されたSkillsを参照できるので、自分のプロジェクトのSkillsフォルダに入れればいい。
Sonarlint のような静的解析ツールの代わりにはならないが。
MCP
Copilot CLI用の拡張機能のようなもの、ブラウザに対する拡張機能。
MCPを追加するには
①内臓のレジストリから
②設定ファイルを手動編集

こうやってJsonを追加すればプロジェクトレベルで追加される。
{
"mcpServers": {
"filesystem": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."],
"tools": ["*"]
}
}
}
おすすめのMCP。



