Pular para o conteúdo

Exercise 7 - Slash commands in GitHub Copilot CLI

Este conteúdo não está disponível em sua língua ainda.

Like any good CLI tool, GitHub Copilot CLI includes many slash commands to interact with it. These commands expose advanced functionality, “behind-the-scenes” information, or additional configuration options. You’ve already explored a couple with /clear to clear context and /mcp to inspect MCP servers. Let’s explore a couple of other powerful ones, including /context, /model, /share, and /delegate.

Scenario

You’ve wrapped the core CLI flows. Now let’s look at a few additional capabilities — sharing sessions, switching models, and delegating tasks to Copilot cloud agent.

In this exercise you will use:

  • /share to create a GitHub gist to share your session with the team.
  • /context to see the context Copilot CLI is currently using.
  • /model to explore the list of available models and select a new one if you so desire.
  • /delegate to optionally hand off a task to cloud agent. This requires cloud agent, available on Copilot Student, Pro, Pro+, Business, or Enterprise — every plan except Copilot Free.

Sharing a session

Using any tool, including an AI tool, is a skill. Working together as a team, sharing learnings with each other, is the best way to help improve everyone’s experience and generate higher quality code. To support this, Copilot CLI provides a /share command. The /share command can generate a markdown file or GitHub gist with the details of the session, including the prompts used and logic Copilot followed.

Let’s create a GitHub gist we could share with our team.

Start a Copilot CLI session

Before you start the exercises below, return to your codespace and open a terminal (Ctrl+` if one isn’t already open). Then start Copilot CLI with --yolo and --enable-all-github-mcp-tools:

Terminal window
copilot --yolo --enable-all-github-mcp-tools

To pick up your most recent session for this project instead of starting fresh, run copilot --yolo --enable-all-github-mcp-tools --continue. If Copilot CLI is already running from an earlier exercise, send /clear to start a clean conversation.

--enable-all-github-mcp-tools enables the read/write GitHub MCP tools for the current session, so Copilot can read your backlog and open pull requests during the workshop flow.

--yolo enables full automatic permissions (--allow-all-tools, --allow-all-paths, and --allow-all-urls). Use it only in an isolated environment like a Codespace or VM, and never alias it as your default for day-to-day development. See Allowing and denying tool use for details.

  1. In the prompt window for Copilot CLI, send the following command:

    /share gist
  2. In just a couple of moments, Copilot will create a gist and display the link.

  3. Copy the link text.

  4. In a new browser tab, paste the link to explore the gist. Note how the gist highlights the prompts sent, skills and agents used, Copilot’s thought process, and even the code and results from locally run commands.

The gists and markdown files generated by /share can be used for documentation purposes of how code was generated, or to share with your team about how certain actions were performed that generated the desired results from Copilot.

Exploring Copilot CLI’s context

When working on larger or more complex tasks you may bump into the maximum context window for the model. The exact size of the window will vary based on the model being used and the version of Copilot CLI. When the context window is maxed out, Copilot CLI will automatically compact it, summarizing information and removing anything it deems isn’t relevant to the current task. You can both see the current state of the context and manually compact the context by using slash commands. Let’s explore the context window.

  1. In the prompt window for Copilot CLI, send the following command:

    /context
  2. In just a couple of moments, Copilot CLI will generate a visual representation of its current context:

    Screenshot of context window from Copilot CLI

  3. Note the model displayed (which may be different than the one in the image), and the current percentage of tokens used. The rest of the information highlights:

    TitleDescription
    System/ToolsInstructions files, file contents and tool definitions
    MessagesConversation history between you and Copilot
    BufferReserved space by Copilot CLI for generating responses
    Free spaceRemaining free space
  4. Compact the conversation history by sending the following slash command to Copilot CLI:

    /compact
  5. Once completed, send the following command to display the current context stats again:

    /context
  6. Note the change in context. There might not be a drastic change as the context window is likely relatively small at the moment.

Copilot CLI will automatically compact when it becomes full. As it approaches 100% capacity it will display the percentage just above the prompt window. Normally it will compact asynchronously, allowing you to continue interacting with Copilot while it does its work. It may however block a running operation for several seconds while performing its work.

Best practices with context

In most sessions with Copilot context will be managed efficiently by Copilot itself without any specific guidance. However, there may be instances when you decide to manually instruct Copilot to either clear or compact its history:

  • If you are changing to a different part of the application, or to an unrelated task, you can use /clear to start new to avoid confusing Copilot with older, unrelated context.
  • If you are approaching the maximum context window, you can manually /compact your context to control when it happens.

Again, the majority of the time, Copilot will manage its context without direct interaction from you. If you notice Copilot is a bit confused by older information, or are about to switch to an unrelated task, then you might consider using the manual commands.

Choosing your model

Different models have different strengths, and different developers have different preferences. Copilot CLI allows you to list and select the model you wish to use!

  1. Display the list of models by sending the following slash command to Copilot CLI:

    /model
  2. Note the list of models. Each model will have both its name and cost-per-request modifier listed next to it.

  3. If you wish, select a new model! Or select Esc to exit the model list.

Model selection persists in Copilot CLI.

Delegating to cloud agent (optional)

There are times when you want to keep working in your terminal but hand off a longer-running task to Copilot cloud agent. The /delegate command sends the current Copilot CLI session to GitHub.com, where cloud agent picks it up, works asynchronously, and opens a pull request when done.

/delegate requires cloud agent, available on Copilot Student, Pro, Pro+, Business, or Enterprise — every plan except Copilot Free. If you don’t have access, read through this section and skip the hands-on steps.

  1. Clear the current session first so accumulated workshop context isn’t delegated:

    /clear
  2. Send a small, well-scoped prompt. For example, you could delegate the stretch-goal pagination from your backlog:

    Implement pagination on the games list page so it shows a fixed number of games per page with Previous and Next controls, and add tests.
  3. Send the following slash command to hand the session to cloud agent, and confirm the prompt you want to delegate:

    /delegate
  4. Open Copilot agents in a browser to monitor progress.

  5. You don’t need to wait for the pull request to complete in this harness; you can return to it later. If you want to dig deeper into managing asynchronous agent work, continue with the Cloud agent harness.

Summary and next steps

Using slash commands in Copilot CLI allows you to configure it, share sessions, and get internal information about how Copilot’s working. In this lesson you used or explored:

  • /share to create a GitHub gist to share your session with the team.
  • /context to see the context Copilot CLI is currently using.
  • /model to explore the list of available models and select a new one if you so desire.
  • Learned about /delegate as an optional bridge to cloud agent.

There are of course more slash commands available, and more to explore with Copilot CLI! Let’s close out our journey by reviewing what we’ve learned and some next steps to continue learning.

Resources