Using the Terminal

Using the Terminal


Check out the ai-training-debugging branch to follow along with this section

git fetch git checkout ai-training-debugging

Copilot's Toolbox

Copilot has access to a set of tools it can use while working. You can view these by clicking the tools icon in the chat window, which opens the tool panel.

Tools fall into three categories:

  • Built-in tools: Reading and writing files, searching the codebase, and other core capabilities built into Copilot

  • MCP tools: External tools connected via MCP servers (for example, an Atlassian server for accessing Jira and Confluence)

  • Terminal tools: The most powerful category — they let Copilot run any script or program on your machine

The key terminal tools are:

  • run_in_terminal

  • send_to_terminal

  • kill_terminal

  • get_terminal_last_command

  • terminal_selection.

Of these, run_in_terminal is the most important: once Copilot can execute commands in the terminal, it can use any program, language, or script available on your system — effectively giving it an unlimited toolbox.

Running Commands in the Terminal

You don't need to explicitly tell Copilot to "run a command" — just ask in plain English and it will figure out what to run. For example, asking "What git branch am I on?" causes Copilot to run git branch on its own.

Copilot runs commands in hidden terminals managed from within the chat. You can see how many are running by looking at the bottom of the VS Code terminal panel — it shows a count of hidden terminals. Clicking that indicator opens them in the terminal panel.

The chat terminal and the VS Code terminal panel are the same terminal — they're connected. If you open a hidden terminal and run something manually, Copilot can see it too.

When Copilot runs a command, it reads the output and can summarize or respond to it:

  • Short-lived commands (like git status, npm run lint, npm test) terminate, and Copilot reads their result immediately

  • Long-running processes (like dev servers) stay running in the background and Copilot monitors them asynchronously

Reading the Terminal

Interaction between Copilot and the terminal is bi-directional. Copilot can run commands and read their output, but you can also select text in the terminal and ask Copilot about it.

The #terminalSelection tool lets Copilot read whatever text you have highlighted in the terminal. This is useful when you want to ask a targeted question about part of the output — for example, selecting a block of test results and asking "How many tests passed?" or highlighting a stack trace and asking "What's causing this error?"

✏️ Exercise: Test Out the Terminal

  1. Ask Copilot to run commands in the chat and inspect them in the “Hidden Terminalˮ

    1. What is my current directory
      1. pwd

    2. List all the files at my location
      1. ls

    3. What is my current branch
      1. git branch

    4. Run the tests
  2. Use the #terminalSelection tool to pinpoint a specific selection in the terminal

Using Skills to Teach Commands

When you have a complex application with many scripts and commands, you can create skills that teach Copilot how to use them. Skills are instruction files stored in .github/skills/ that describe how to perform specific workflows in your project.

Carton Case Management includes several skills:

  • setup-project: Instructs Copilot to kill any running servers (using pkill), then start the backend and frontend. This prevents "port already in use" errors when Copilot loses track of previously spawned terminals.

  • commit: Instructs Copilot to run tests, the type checker, and the linter before committing, and provides example commit message formats for this codebase.

  • database: Teaches Copilot how to reset the database, push schema changes, and seed demo data.

  • next-step: A utility skill for this workshop that detects the current branch and checks out the next one.

The key idea:

rather than explaining your project's conventions every time, encode them once in a skill file and Copilot will follow them automatically. This is especially useful for project-specific scripts that Copilot wouldn't otherwise know how to use.

Managing Multiple Terminals

Copilot can manage multiple terminals simultaneously. This is essential for apps that require several processes running at the same time — for example, a frontend dev server, a backend API server, and a one-off cleanup script.

When you ask Copilot to start the app using the setup-project skill, it spawns three hidden terminals:

  1. A short-lived terminal that kills any already-running processes

  2. A persistent terminal running the backend server

  3. A persistent terminal running the frontend client

You can open these from the Hidden Terminals indicator in the terminal panel. It's good practice to label your terminals (e.g., "backend", "frontend") so both you and Copilot can tell them apart at a glance.

 

Important: The current chat "owns" the terminals it starts. If you open a new chat, those terminals are no longer connected — Copilot won't be able to read their output. When starting a new debugging session, always restart your servers from the current chat. This ensures Copilot has full visibility into server logs, which is critical for multi-environment debugging.

✏️ Exercise: Start the Development Servers

  1. Ask Copilot to run the dev servers and then add them to the terminal a. “Run the dev serversˮ

  2. Click on the “Hidden Terminalsˮ button

  3. Add the terminals to the terminal window

    1. localhost:5173 is the frontend

    2. localhost:3001 is the backend


Next: Debugging Loops