GitHub Copilot CLI: Install and Key Commands
30-second answer
GitHub Copilot CLI is an AI agent in your terminal, run with the copilot command. It reads the repo you're in, answers questions, edits files and runs commands after asking you. Install it with npm install -g @github/copilot (Node.js 22+), brew install --cask copilot-cli, winget install GitHub.Copilot or the install script. On first run it asks you to trust the folder, then you sign in with /login (or a fine-grained token in COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN). Inside a session, slash commands like /model, /mcp, /usage and /help control it, @path adds a file and !cmd runs a shell command.
Exam objective: 2.2.1 Define GitHub Copilot CLI and how it benefits developers. 2.2.2 Identify the steps for installing GitHub Copilot CLI. 2.2.3 Describe key GitHub Copilot CLI features and commands. (Skills measured as of August 7, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Copilot CLI needs <strong>Node.js 22</strong> or later. Install it with <code>npm install -g @github/copilot</code>, or with <code>brew install --cask copilot-cli</code>, <code>winget install GitHub.Copilot</code> or the install script.
👆 Click the glowing item on screen to continue
Read the steps as text
- Copilot CLI needs Node.js 22 or later. Install it with npm install -g @github/copilot, or with brew install --cask copilot-cli, winget install GitHub.Copilot or the install script.
- Run copilot. It first asks whether you trust the files in this folder, because it can read them and, with your approval, edit them and run commands.
- Type /login and approve the device code on github.com. In scripts you can use a token in COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN instead.
- /model picks a model. @path adds a file to the context, !cmd runs a shell command, and /help lists the rest: /mcp, /agent, /delegate, /usage, /context, /compact, /clear, /exit.
🧪 Simulation for learning. Screens are simplified versions of Visual Studio Code and github.com with GitHub Copilot; names, files and suggestions are examples. Not affiliated with GitHub or Microsoft, and nothing here touches your real account.
🖱️ Drag to rotate · scroll or pinch to zoom
Copilot CLI
The same agent in the terminal: copilot for a session with slash commands, copilot -p "…" for one prompt, and --allow-tool / --deny-tool to control what it may run.
🤔 What happens if…
Read this tour as text
- Ask mode. Ask answers questions about code and concepts and can suggest code blocks. It doesn’t change your files by itself.
- Edit mode (Copilot Edits). Edit applies changes to the files you choose, across several files at once. You see each diff and Keep or Undo it.
- Agent mode. Agent works out which files to touch, edits them, runs commands and tests, reads errors and keeps going until the task is done. It asks before running terminal commands unless you’ve approved them.
- MCP servers add tools. The Model Context Protocol (MCP) lets Copilot use external tools: the GitHub MCP server, a browser, a docs search or your own API. Configure servers in
.vscode/mcp.json(VS Code) or with/mcp(CLI). Organizations can restrict which servers are allowed. - Sessions and sub-agents. Long tasks fill the context window. Agent sessions keep work separate, and a sub-agent can do a side task in its own context and hand back only a summary.
- Copilot coding agent. Assign an issue to Copilot on github.com (or
/delegatefrom the CLI). The coding agent works in a GitHub Actions environment on its own branch and opens a draft pull request with its changes. - Review stays human. You review the agent’s PR like any other. Copilot code review can comment and suggest changes, but its review doesn’t count as an approval. A person merges.
- Copilot CLI. The same agent in the terminal:
copilotfor a session with slash commands,copilot -p "…"for one prompt, and--allow-tool/--deny-toolto control what it may run.
Get Copilot into your terminal. Check Node.js, install the CLI, trust the folder, sign in, pick a model and ask your first question about the code in front of you.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
You keep copying terminal errors into a browser to ask about them.
😊 THE SOLUTION
Bring Copilot into the terminal with Copilot CLI.
- Switching windows✓ copilot in the terminal
- Unsure how to install✓ npm install -g @github/copilot
- Too many options✓ /help, /model, /mcp
Start with a question
If you're already in the kitchen with your hands dirty, do you want to walk to another room to ask for help?
No. You want the helper right there at the counter. Plenty of developers spend half their day in a terminal: running tests, using git, logged in to a server. Switching to an editor’s chat window to ask “what does this script do?” breaks the flow.
GitHub Copilot CLI puts the helper at the counter. Type copilot in your repo and you can ask about the code, have it write a file or run a command, and it asks before it touches anything.
Explain it like I’m 10
The technical explanation
What it is and why it helps
Copilot CLI is the copilot command. It’s an agent: it can read files in the folder, search them, edit them, run shell commands and call MCP tools, and it checks with you before using a tool it hasn’t been allowed yet. That makes it useful when:
- you work over SSH or mostly in the terminal,
- you want to ask about a repo you just cloned,
- you want to script a prompt (
copilot -p "…") in a shell script or CI job, - you want to hand a task to Copilot coding agent with
/delegate.
It needs a Copilot plan (Free, Pro, Pro+, or a Business or Enterprise seat), and an organization can turn the CLI off by policy. It replaces the older gh copilot extension.
Install it
| Method | Command |
|---|---|
| npm (any OS, Node.js 22+) | npm install -g @github/copilot |
| Homebrew (macOS, Linux) | brew install --cask copilot-cli |
| WinGet (Windows) | winget install GitHub.Copilot |
| Install script (macOS, Linux) | curl -fsSL https://gh.io/copilot-install | bash |
Check it with copilot version and keep it current with copilot update.
First run: trust, then sign in
$ cd contoso-shop
$ copilot
Confirm folder trust: ~/contoso-shop
1. Yes
2. Yes, and remember this folder for future sessions
3. No (Esc)
It asks because it can read every file here and, with your approval, change them and run commands. Only trust folders whose contents you trust.
Then sign in:
/logininside the session uses the device flow: copy a one-time code and approve it on github.com.- For automation, set a fine-grained personal access token with the Copilot Requests permission in
COPILOT_GITHUB_TOKEN,GH_TOKENorGITHUB_TOKEN. Classic tokens aren’t supported.
-
1 Install
npm, Homebrew, WinGet or the script. Node.js 22+ for npm.
-
2 Trust
Run copilot in the repo and trust the folder.
-
3 Sign in
/login with a device code, or a fine-grained token.
-
4 Ask
explain @src/cart.js, and approve any tool it needs.
Inside a session
Type a request in plain English. Three bits of syntax are worth knowing:
copilot ❯ explain @src/cart.js # @path adds a file to the context
copilot ❯ !git status # ! runs a shell command directly
copilot ❯ /model # / is a slash command
| Slash command | What it does |
|---|---|
/login, /logout | Sign in or out |
/model | Pick a model (your plan and organization decide the list) |
/mcp | List, add or show MCP servers |
/agent | Pick a custom agent |
/delegate | Hand the task to Copilot coding agent on GitHub, which opens a draft PR |
/usage | See what the session used, including premium requests |
/context, /compact | See what fills the context window, and summarise history to free space |
/session, /resume | Session details, and switch back to an earlier session |
/init, /plan, /review | Create instructions for the repo, plan before coding, review changes |
/clear, /help, /exit | Start over, list commands, leave (the session is saved) |
Settings, MCP servers (mcp-config.json) and personal custom agents (agents/) live in ~/.copilot/.
Architect level What trust and approvals actually protect
Trusting a folder means Copilot CLI may read files there. It still asks before each new kind of action, such as writing a file or running shell(npm). You can answer yes once, or yes for the rest of the session. When you launch it you can pre-approve or block tools with --allow-tool and --deny-tool, and a deny always wins, which matters most in non-interactive runs (covered in the next lesson). A cloned repo can contain instructions files and scripts written by someone else, so be careful trusting folders you haven’t read, and never pre-approve all tools there.
Real-world business scenario
Contoso (fictional)
- The problem
- Contoso's operations engineers fix production issues over SSH and never open an editor. They were copying error messages into a browser chat and pasting answers back into the terminal.
- What they used
- GitHub Copilot CLI installed with npm on their jump boxes, signed in with /login, trusted only for the service repositories, and kept up to date with copilot update. The organization's CLI policy is on for the operations team.
- Why that choice
- The agent sees the repo and the command output where they already work, and asks before running anything.
- The result
- Engineers stopped copying logs between windows, and every command Copilot ran was one they had approved.
When to use it and when not to
✓ Use it when…
- You work mostly in the terminal or over SSH.
- You want to ask questions about a repo you just cloned.
- You want to script a prompt or hand a task to the coding agent with /delegate.
✕ Think twice when…
- Trusting folders whose contents you haven't checked.
- Signing in on shared machines with a long-lived token in a plain environment variable. Use a secret store.
- Using the old gh copilot extension for new work.
↔ Alternatives to consider
- Copilot Chat in VS Code when you want diffs, inline suggestions and the editor around you.
- Copilot coding agent on github.com when nobody needs to watch the work happen.
Test yourself with exercises
5 original practice questions in the GH-300 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What is GitHub Copilot CLI and why would you use it instead of chat in the editor?
Model answer
It's Copilot as an agent in the terminal. I start it with copilot in a repo, ask about the code, and let it edit files or run commands after I approve them. It's handy when I'm already in the terminal, on a server over SSH, or when I want to script a prompt with copilot -p.
Intermediate How do you sign in to Copilot CLI on a build agent where nobody can open a browser?
Model answer
I don't use /login there. I create a fine-grained personal access token with the Copilot Requests permission and put it in COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN as a secret. Classic tokens don't work for this.
Experienced developer A teammate still runs gh copilot suggest. What do you tell them?
Model answer
That extension has been replaced by GitHub Copilot CLI. Install the new CLI, run copilot, and you get a full agent with sessions, tools and MCP instead of one-off suggestions. For a quick one-shot answer, copilot -p does the job.
Scenario Copilot CLI starts but won't do anything in a repo, and someone says it's blocked. Where do you look?
Model answer
First whether I trusted the folder when it asked. Then whether my account has a Copilot plan or seat, and whether my organization's Copilot policy allows the CLI, because admins can turn it off. /login and /usage show who I'm signed in as.
Quick revision
Key points
- Copilot CLI is the copilot command: an agent in the terminal that asks before it edits or runs anything new.
- Install: npm install -g @github/copilot (Node.js 22+), brew install --cask copilot-cli, winget install GitHub.Copilot, or curl -fsSL https://gh.io/copilot-install | bash.
- copilot update and copilot version keep it current.
- First run asks you to trust the folder; then /login with the device flow.
- Tokens go in COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN; fine-grained PAT with Copilot Requests, no classic PATs.
- Key slash commands: /model, /mcp, /agent, /delegate, /usage, /context, /compact, /clear, /help, /exit.
- @path adds a file, !cmd runs a shell command. Config lives in ~/.copilot/.
Important terminology
- GitHub Copilot CLI
- The copilot command, an agent in the terminal that can read your files, edit them and run commands with your permission.
- Trusted folder
- A directory you've allowed Copilot CLI to work in. It asks on first run (Yes, Yes and remember, or No).
- Device flow
- The /login sign-in where you copy a one-time code and approve it on github.com.
- Copilot Requests permission
- The fine-grained personal access token permission Copilot CLI needs when you sign in with a token. Classic tokens aren't supported.
- @path
- Syntax in a Copilot CLI prompt that adds a file to the context, such as @src/cart.js.
- !command
- Syntax in a Copilot CLI session that runs a shell command directly, such as !git status.
Common mistakes
- Installing on Node.js 20 and wondering why npm fails. It needs 22 or later.
- Using a classic personal access token.
- Installing the old gh copilot extension instead of Copilot CLI.
Exam tips
- "Install Copilot CLI with npm" = npm install -g @github/copilot.
- "Sign in without a browser" = fine-grained PAT with Copilot Requests in COPILOT_GITHUB_TOKEN.
- "Switch the model in a session" = /model.
Five quick revision questions
-
1.Which command starts Copilot CLI?Show
copilot
-
2.Which Node.js version does the npm install need?Show
22 or later
-
3.Which slash command shows usage for the session?Show
/usage
-
4.How do you add src/cart.js to a prompt?Show
Type @src/cart.js in the prompt.
-
5.Where does Copilot CLI keep its configuration?Show
In ~/.copilot/ (for example mcp-config.json and agents/).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Copilot CLI Sessions, Scripts and Files
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.