Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 8 of 30
❮Prev Next❯

GitHub Copilot CLI: Install and Key Commands

Module 2: Copilot Features ⏱ 10 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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.

    Simulate it » No Azure account needed

    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.

    VS Code & GitHub: Install and start GitHub Copilot CLI Install the CLI, trust the folder, sign in and pick a model.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading…

    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
    1. 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.
    2. 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.
    3. 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.
    4. /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.

    😟 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
    🛠️ Solved with: GitHub Copilot CLI

    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

    MethodCommand
    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:

    • /login inside 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_TOKEN or GITHUB_TOKEN. Classic tokens aren’t supported.
    1. 1 Install

      npm, Homebrew, WinGet or the script. Node.js 22+ for npm.

    2. 2 Trust

      Run copilot in the repo and trust the folder.

    3. 3 Sign in

      /login with a device code, or a fine-grained token.

    4. 4 Ask

      explain @src/cart.js, and approve any tool it needs.

    From install to your first answer

    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 commandWhat it does
    /login, /logoutSign in or out
    /modelPick a model (your plan and organization decide the list)
    /mcpList, add or show MCP servers
    /agentPick a custom agent
    /delegateHand the task to Copilot coding agent on GitHub, which opens a draft PR
    /usageSee what the session used, including premium requests
    /context, /compactSee what fills the context window, and summarise history to free space
    /session, /resumeSession details, and switch back to an earlier session
    /init, /plan, /reviewCreate instructions for the repo, plan before coding, review changes
    /clear, /help, /exitStart 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

    Online retail

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    A developer has Node.js 22 installed and wants to install GitHub Copilot CLI by using npm. Which command should the developer run?

    Question 2

    Question 2 of 5

    You need to run GitHub Copilot CLI in an automated job where no interactive sign-in is possible. Which credential should you provide?

    Question 3

    Question 3 of 5 · Select 2

    Which TWO statements describe GitHub Copilot CLI? Each correct answer presents a complete solution.

    Question 4

    Question 4 of 5

    During an interactive Copilot CLI session, a developer wants to include the file src/cart.js in the next prompt. What should the developer type?

    Question 5

    Question 5 of 5

    A developer starts GitHub Copilot CLI in a newly cloned repository for the first time. What does Copilot CLI ask the developer to do before it works with the files?

    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. 1.Which command starts Copilot CLI?Show

      copilot

    2. 2.Which Node.js version does the npm install need?Show

      22 or later

    3. 3.Which slash command shows usage for the session?Show

      /usage

    4. 4.How do you add src/cart.js to a prompt?Show

      Type @src/cart.js in the prompt.

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.