Prompt examples

This article provides example prompts for chat in Visual Studio Code across common development workflows. Use these examples as templates to adapt to your own repository, goals, and verification commands.

If you are new to chat in VS Code, start with the chat overview or review best practices for using AI.

Adapt an example to your project

The Chat view examples use the Copilot harness. Select Ask for read-only explanations and general coding questions without edits, Agent to make and verify changes, or enter /plan to create an implementation plan before editing code.

Tip

If you don't see the agent picker, look under Add Context (+) > Agent. To restore the separate picker, uncheck the experimental sessions.chat.experimental.agentsPickerInAttachContextMenu Open in VS Code Open in VS Code Insiders setting.

Before sending a prompt:

  • Add focused context. Type # in the chat input and select a file, folder, or #selection, or use Add Context to attach files, images, or GitHub issues and pull requests. Replace sample filenames such as user-service.ts and styles.css with files in your project. Paste URLs, stack traces, or terminal output directly into the prompt. See Add context to chat.
  • State the goal, constraints, and verification. Name the expected behavior, the files or scope to keep unchanged, and the test or build command that proves the result works. Remove secrets from copied logs or output.
  • Break large tasks into steps. Plan complex changes first and iterate with follow-up prompts instead of asking for everything in one message.
  • Review before keeping changes. Check tool approval requests, inspect the diff, and run the relevant checks. Treat tests that weren't run as unverified.

Understand and explore your codebase

Use the Ask agent to understand how your project works, trace a behavior across files, or locate configuration without editing files. Agents search your workspace automatically when you describe what to look for.

For a guided investigation with source references and verification checks, see Explore a codebase with an agent.

Explain how request authentication works in this repository.
Start from the route or middleware entry point and cite the relevant files
and functions. Separate verified facts from open questions.
Where is the database connection configured, and how do local and production
environments differ? Cite the configuration files without printing secret values.
How do I build and run the unit tests for this repository?
Cite the scripts or configuration files that define those commands.
Which testing framework and helpers are used in #user-service.test.ts,
and how are external dependencies mocked?

Plan a feature before implementing

Use /plan when a change spans multiple files or has open design decisions. Review and refine the plan before the agent edits code.

For the full planning and review workflow, see Plan work with agents.

/plan Add cursor-based pagination to the product-list API.
Follow the existing route and validation conventions and keep the current
response shape for callers that omit pagination parameters.
Include test cases for invalid cursors and empty results, and list any open
decisions I should confirm before implementation.

After reviewing the proposed plan, send focused feedback to adjust the scope before approving:

Keep the existing response format unchanged and exclude UI changes.
Split the implementation into independently testable steps and add a
compatibility check for requests without pagination parameters.

Edit, generate, and refactor code

Use Agent for targeted single-file changes that benefit from tool calls or test verification, as well as scoped multi-file changes. Use inline chat (⌘I (Windows, Linux Ctrl+I)) with #selection for quick, in-place edits without leaving the editor.

For end-to-end workflows in an existing repository, see Add a feature and Refactor without changing behavior.

With a function selected in the editor, use inline chat (⌘I (Windows, Linux Ctrl+I)):

Refactor #selection to use async and await instead of chained promises.
Preserve the return type and error-handling behavior, and change only this function.

For a targeted single-file change with test verification in Agent:

In #auth-middleware.ts, return HTTP 401 when the session token is expired
instead of throwing an unhandled error.
Change only this file and its tests, run the auth test suite, and report
the test command and results.

For a bounded feature change in Agent:

Add an empty-state message to the search results component in #search-results.tsx
using the existing styles in #styles.css.
Limit changes to this component and its tests, run the component test suite,
and summarize what you verified.

For a behavior-preserving refactor in Agent:

Extract the request validation logic from #orders-controller.ts into a dedicated
helper module so it can be reused across routes.
Preserve existing API responses and status codes. Run the existing order tests
to confirm behavior is unchanged.

Test and verify quality

Use Agent to generate tests or diagnose failing tests. Provide the expected behavior and use the project's existing test framework. For a complete workflow, see Add tests to existing code.

Add unit tests for #user-service.ts using the existing test framework.
Cover normal inputs, empty inputs, and error cases without changing implementation
code. Run the tests and report the command, results, and anything you couldn't run.
Investigate this test failure before changing code:
<paste test output>

Explain whether the cause is test setup, an incorrect expectation, or an
implementation bug. Propose a fix and wait for my approval before applying it.
Do not delete assertions, skip tests, or change expected results only to make
the tests pass.

After you agree on the cause and fix:

Apply the agreed fix without changing unrelated code.
Run the relevant tests and report the command, results, and any tests not run.

Debug and fix issues

Use Agent to diagnose and fix issues across files, or Ask to trace the root cause before making edits. For pairing chat with breakpoints and logpoints, see Debug a runtime failure.

Investigate this runtime failure without editing any files:
<paste stack trace or log excerpt>

List the top two or three root-cause hypotheses with exact files and line numbers.
For each hypothesis, suggest specific breakpoints or logpoints to confirm or rule
it out in the debugger.
Investigate the compiler and lint errors from running `npm run build` and `npm run lint`.
Fix the root cause without suppressing diagnostics or changing unrelated code.
Rerun both commands and summarize any remaining failures.
Explain why #selection returns undefined for an empty array input.
Trace the return path without changing files.

Work with source control and pull requests

Reference uncommitted changes, a branch, a commit SHA, or paste a GitHub pull request URL directly in your prompt. Use Ask or request a read-only pass before making edits or changing Git history.

For a full pull request review and feedback workflow, see Review a pull request.

Review the pull request at <paste GitHub PR URL> without editing files.
Identify logic bugs, missing edge cases, regressions, and missing test coverage.
Cite exact files and line numbers for each finding.
Summarize my uncommitted changes in this repository.
Group the changes by behavior and flag anything that needs further review.
Draft release notes from the commits on this branch compared to main.
Focus on user-visible changes and flag claims that need verification. Do not edit files.

Before undoing a commit, establish whether it has been shared and which changes you want to keep:

Help me choose how to undo my most recent commit while keeping all file changes.
First ask whether it has been pushed or shared and whether I have uncommitted
changes. Explain an option that avoids rewriting shared history.
Do not run commands or change the repository.

Review the Git undo and discard options before taking action.

Validate a web app with browser tools

Use built-in browser tools in Agent so the agent can start your web app, exercise a real user flow in the integrated browser, inspect console errors or visual layout, and verify fixes.

Start the development server and open the app in the integrated browser.
Submit the sign-up form with an invalid email, verify the validation message
appears, then submit valid details and confirm the confirmation screen loads.
Check for console errors. If any step fails, fix the issue and repeat the flow.
Open the running app at http://localhost:3000 in the integrated browser and inspect
the checkout page layout at mobile and desktop widths.
Report any overlapping elements or broken controls without editing files yet.

Delegate focused work to subagents

Use subagents to run bounded research or code reviews in separate contexts so intermediate steps don't crowd your main conversation.

Use a subagent to investigate how caching works in this repository without
changing files. Return the relevant file paths, cache invalidation rules, and
any open questions. Use those findings to propose a plan in the main chat and
wait for my review before making changes.
Use two subagents to review my uncommitted changes without editing files.
Ask one to check correctness and edge cases, and the other to check test coverage.
Combine their findings, remove duplicates, and prioritize actionable issues.

Use web pages and GitHub context

Paste a documentation URL, issue URL, or pull request URL directly into your prompt, or use Add Context (+) > Issue or Pull Request. Review URL approval prompts before allowing external access.

Summarize the breaking changes in https://learn.microsoft.com/en-us/aspnet/core/migration/80-90
and check whether this repository is affected. Cite matching files without editing code.
Read the requirements in <paste GitHub issue URL> and identify which files in this
repository need to change. Summarize your proposed approach and list any missing
acceptance criteria before editing files.

Configure projects, CI workflows, and run commands

Use Agent to update project configuration, refine UI styling or app settings, adjust CI workflows, or run build and test scripts and diagnose failures. Review terminal approval requests before running commands that modify your environment.

Update #.github/workflows/ci.yml to cache dependencies and run the lint check
before unit tests. Keep existing triggers and Node.js versions unchanged,
and validate the workflow YAML syntax.
Run the project build and type-check scripts defined in #package.json.
If a step fails, fix only the configuration or code error causing the failure,
rerun both scripts, and summarize the commands and final exit status.
Update #styles.css so the navigation bar stays on one row at desktop widths
and collapses cleanly below 768px without overlapping the search input.
Keep existing theme colors unchanged and explain which rules changed.

Run terminal tasks

Use terminal inline chat (⌘I (Windows, Linux Ctrl+I)) to generate shell commands tailored to your terminal and operating system. Review generated commands before selecting Run.

List the five largest files in the src directory
Find which process is listening on port 3000

Iterate in multi-turn conversations

Chat retains context within the same session. Use follow-up prompts to refine requirements, add safeguards, and verify behavior step by step.

First prompt:

Create a REST endpoint in Express.js for listing and creating tasks in memory.
Use TypeScript, keep the implementation in a single module, and return JSON
responses with explicit status codes.

Follow-up prompts:

Add request body validation and return 400 with field-level error messages
for missing or invalid fields.
Add unit tests covering valid creation, invalid input, and listing tasks.
Run the test suite and report the results.

Schedule follow-up work

These examples use the Agents window. For a one-time reminder in the same conversation, enable Send Later Send Later in the Agents window is experimental and might change or be removed. with a supported local desktop Agent Host, then ask:

In 30 minutes, remind me in this chat to review the test results.

For work that repeats, create an automation from chat:

/automate Create a local automation for this repository that runs daily
at 9:00 AM in my local time zone.
Summarize commits from the last 24 hours. Do not modify files or publish anything.
Save it disabled so I can review the configuration before enabling it.

Review the proposed configuration before confirming creation, then test the automation before enabling its schedule. Normal tool approvals apply to both examples. Local scheduled work requires your computer to be awake and the Agent Host available.