Skip to main content

Getting started with prompts for Copilot Chat

Get an overview of ways to use Copilot Chat.

You can ask Copilot Chat specific questions about your project or general software questions. You can also ask Copilot Chat to write code, fix errors, write tests, and document code.

Use the tabs above to select the environment where you are using Copilot Chat.

Ask general software questions

You can ask Copilot Chat general software questions. For example:

  • tell me about nodejs web server frameworks
  • how to create an express app
  • how to update an npm package

Ask questions about your project

You can ask Copilot Chat questions about your project. To give Copilot the correct context, try some of these strategies:

  • Highlight relevant lines of code.
  • Open the relevant file.
  • Use #file to tell Copilot to reference specific files.
  • Use #solution to tell Copilot to reference the active file.

For example:

  • what sorting algorithm does this function use
  • #file:gameReducer.js what happens when a new game is requested

Write code

You can ask Copilot to write code for you. For example:

  • write a function to sum all numbers in a list
  • add error handling to this function

When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output.

Ask questions about alerts from GitHub Advanced Security features

You can ask Copilot about security alerts in repositories in your organization from GitHub Advanced Security features (code scanning, secret scanning, and Dependabot alerts). For example:

  • How would I fix this alert?
  • How many alerts do I have on this pull request?
  • Which line of code is this code scanning alert referencing?
  • What library is affected by this Dependabot alert?

Fix, improve, and refactor code

If your active file contains an error, use the /fix slash command to ask Copilot to fix the error.

You can also make general requests to improve or refactor your code.

  • how would you improve this code?
  • translate this code to C#
  • add error handling to this function

Write tests

Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:

  • /tests
  • /tests using the Jest framework
  • /tests ensure the function rejects an empty list

The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:

  • Add tests for a JavaScript function that should sum a list of integers