Text of code.visualstudio.com › docs › agents › guides › prompt-examples as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Prompt examples

AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. Join VS Code at Microsoft Ignite or catch the sessions online. A year of VS Code, wrapped. Explore the highlights. Prompt examples View as Markdown Ask in VS Code Ask in VS Code Insiders This article provides example prompts for chat in Visual Studio Code across different scenarios and agents.

Use these examples as inspiration to craft effective prompts for your own development tasks. If you are new to using chat in VS Code, learn more about getting started with chat or review best practices for prompt crafting . Adapt an example to your project The Chat view examples use the Copilot harness. Select Ask for an explanation without edits, or Agent when you want the agent to make and verify changes. 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: Select your context. Type # in the chat input and choose a file, folder, or other item from the picker, or use Add Context . Replace sample filenames such as calculator.test.js and styles.css with files in your project. Available context items depend on your session.

See Add context to chat . State the expected result. Adapt the task to your project. For a failure, include the input, expected behavior, and relevant error or test output. Remove secrets from copied output. Review before keeping changes. Check tool approval requests, inspect the diff, and run the relevant checks. Treat tests that weren't run as unverified. General coding and technology questions Use the Ask agent to get quick answers about coding concepts, technology topics, and general programming questions.

What is a linked list? Provide 3 ways to implement a search feature in React. Explain the difference between async/await and promises. Understanding and exploring your codebase Use the Ask agent with #codebase to understand how your project works, locate specific functionality, or explore code relationships. For a guided investigation with source references and verification steps, see Explore a codebase with an agent .

Explain how authentication works in #codebase Where is the database connection string configured? #codebase How do I build this #codebase? Which testing framework is used for #calculator.test.js? Code generation and editing Use Agent for multi-file creation and inline chat ( ⌘I (Windows, Linux Ctrl+I ) ) for targeted, in-place edits. For complete workflows in an existing project, see Add a feature and Refactor without changing behavior .

Add a login button and style it based on #styles.css Create a meal-planning web app using React and Node.js Refactor this code to use async/await Testing and quality assurance Use Agent to generate tests or fix 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 the attached user service 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 the attached test failure before changing code. 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 just 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. Debugging and fixing issues Use Agent for fixing issues across files, or Ask to understand the root cause first. Investigate the attached compiler or lint errors. Fix the root cause without suppressing diagnostics or changing unrelated code. Rerun the command that reported the errors and summarize the remaining failures.

Explain why the selected function returns undefined for the input I provided. Trace the return path without changing files. Working with source control Attach the diff you want to discuss. Use Ask to summarize changes, draft release documentation, or choose a recovery action before changing Git history. Summarize the attached diff. Group the changes by behavior and flag anything that needs further review. Draft release notes from the attached diff.

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. Working with external resources Use #fetch to reference content from the web or use the GitHub MCP server to search for code examples in public GitHub repositories. How do I use the 'useState' hook in react 18? #fetch https://18.react.dev/reference/react/useState#usage Build an API endpoint to fetch address info, use the template from GitHub repo contoso/api-templates Recommend extensions for the languages used in this workspace.

Explain what each adds and do not install anything. Terminal and command-line tasks Use terminal inline chat to get help with shell commands and terminal operations. How do I install npm packages? List the top 5 largest files in the src directory Multi-turn conversation examples Chat supports follow-up prompts within the same session. Use multi-turn conversations to iterate on results and refine the AI's output. First prompt: Create a REST API with Express.js that has endpoints for users and products Follow-up prompts: Add input validation and error handling to both endpoints Now add unit tests for the validation logic By building on earlier responses, the AI maintains context from the previous steps and generates more coherent code.

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. Tips for crafting effective prompts Be specific : Include details about what you want to accomplish, the technologies to use, and the expected output format.

Add context : Select relevant files and symbols with the # picker or Add Context . Include error output and expected behavior when investigating a failure. Iterate : Start with a simple prompt and refine it based on the response. Ask follow-up questions to improve the results. Break down complex tasks : Instead of asking for everything at once, break large tasks into smaller, manageable steps. Learn more about best practices for crafting prompts and adding context to your prompts .

Related resources Chat overview Add context to your chat prompt Inline chat Copilot Chat Cookbook in the GitHub docume

The rest of this page is on the live site.