Skip to main content

Domain 4: Apply Prompt Engineering and Context Crafting

Domain 4 facts verified 26 August 2026. This page is current as of August 2026 and covers prompt structure, context, examples, chat history, custom instructions, prompt files, and VS Code chat references.

GitHub Docs — Prompt engineering · GitHub Docs — Chat cheat sheet · Verified 26 August 2026.

What Domain 4 tests
#

Domain 4 is about improving Copilot output by improving the request and the context around it. GitHub defines a prompt as your request, and says Copilot also uses additional context such as current-file code and chat history. GitHub Docs — Prompt engineering

The official subskills boil down to this: make the task clear, attach the right context, use examples when behavior is subtle, keep chat history useful, and move repeated guidance into reusable customizations.

Key point: prompt engineering is wording plus context selection.

What makes a good prompt
#

GitHub’s official guidance: start general, get specific, give examples, break complex tasks down, avoid ambiguity, indicate relevant code, iterate, keep history relevant, and follow good coding practices. GitHub Docs — Prompt engineering

A strong prompt usually names the task, scope, constraints, and expected output: “Refactor calculateInvoiceTotal in billing.ts to make tax handling testable. Keep the public signature unchanged, preserve rounding behavior, and show updated unit tests.”

Weak prompt

"Fix this." The word "this" could mean the current file, selected code, the last answer, or the whole project.

Better prompt

"Fix the null-reference bug in `formatUserDisplayName` in #file:src/users/display.ts. Preserve missing-middle-name behavior and add tests for anonymous users."

Prompting behaviors behind the "4S" shortcut

The required GitHub Docs support the underlying behaviors: break work down, be specific, keep reusable instructions short and self-contained, and surround the prompt with relevant files, selections, examples, and open context.

Zero-shot, one-shot, and few-shot prompting
#

Zero-shot means no example. Use it for common, low-ambiguity tasks.

Write a TypeScript function named isStrongPassword that returns true when a password is at least 12 characters and contains an uppercase letter, lowercase letter, number, and symbol.

One-shot means one example. Use it when the output shape matters.

Write a JavaScript function that converts API error objects into user-facing messages.
Example: { code: "CARD_DECLINED" } -> "Your payment method was declined. Please use a different card."
Now support NETWORK_TIMEOUT, INVALID_COUPON, and UNKNOWN_ERROR.

Few-shot means several examples. GitHub explicitly recommends examples of input data, outputs, and implementations, and says unit tests can also serve as examples. GitHub Docs — Give examples

Create a Python function normalize_status(raw: str) -> str.
"In Progress" -> "in_progress"
"in-progress" -> "in_progress"
"DONE" -> "done"
" blocked " -> "blocked"
Return "unknown" for empty or unrecognized values. Include pytest tests.

The GitHub Copilot Cookbook provides task recipes for tests, failures, refactoring, and documentation. GitHub Docs — Copilot Cookbook

Comment-driven development
#

GitHub’s best-practices page says inline suggestions work well for generating code from inline comments, repetitive code, and tests for test-driven development. GitHub Docs — Best practices

// Return newest orders first. Exclude cancelled orders. Default limit is 20.
// Throw RangeError when limit is less than 1 or greater than 100.
export function getVisibleOrders(orders: Order[], limit = 20): Order[] {
  // Copilot suggestion starts here
}

Good comments include behavior, boundaries, defaults, and errors. Vague comments like // process orders do not give Copilot enough structure.

How Copilot determines context
#

In the IDE, GitHub tells you to open relevant files and close irrelevant files. In Chat, open or highlight the code you want referenced, and use chat variables to manually supply context. GitHub Docs — Indicate relevant code

Repository context can also come from semantic indexing. GitHub documents that Copilot Chat can use a repository index to improve answers about code structure and logic, and that excluded content is filtered before being passed to Chat. GitHub Docs — Repository indexing

GitHub does not publish one universal priority order for every context source. Safe exam model: explicit references and selected code are clearest; active/open files and repository context help discovery; chat history carries decisions; custom instructions add standing guidance. If history gets noisy, start a new thread or delete irrelevant requests. GitHub Docs — Keep history relevant

Current VS Code chat references

Current variables are #block, #class, #comment, #file, #function, #line, #path, #project, #selection, and #sym. Current VS Code chat references use #project for project context. The VS Code cheat sheet does not list @workspace, #editor, or #terminalLastCommand. Participants are @github, @terminal, @vscode, and preview @azure. GitHub Docs — Chat cheat sheet for VS Code

Chat history and prompt process flow
#

Copilot Chat uses chat history as context, so follow-up turns can say “keep the same API,” “add tests for the previous code,” or “explain that tradeoff.” GitHub also warns you to keep history relevant. GitHub Docs — Experiment and iterate

A practical flow is: state the goal, attach context, list constraints, ask for a concrete output, review the result, then follow up with corrections. In the IDE chat view, Copilot responses can show which references were used, including custom instruction files. GitHub Docs — Asking Copilot questions in your IDE

Chat modes: Ask, Plan, and Agent

VS Code modes are Ask, Plan, and Agent. Plan mode drafts a plan with read-only tools until approval; Agent mode can edit code and request terminal commands. GitHub Docs — Copilot Chat agents

VS Code slash commands

The current VS Code commands are /clear, /explain, /fix, /fixTestFailure, /help, /new, and /tests. /doc is not a VS Code command; it appears under Visual Studio and Xcode. GitHub Docs — Chat cheat sheet for VS Code

Custom instructions and prompt files
#

Custom instructions are automatic standing guidance. GitHub says they help avoid repeatedly adding project details, team preferences, tools, standards, frameworks, and folder structure to every prompt. They should be short, self-contained, and broadly applicable within their scope. GitHub Docs — Customizing responses

Use .github/copilot-instructions.md for repository-wide guidance and .github/instructions/NAME.instructions.md for path-specific guidance with applyTo globs. GitHub Docs — Adding repository instructions

---
applyTo: "src/components/**/*.tsx"
---
Use function components.
Use accessible labels for interactive controls.
Prefer existing design-system components.
Add or update tests when behavior changes.

Custom instruction precedence

Custom instruction precedence is personal, then path-specific `.github/instructions/*.instructions.md`, then repo-wide `.github/copilot-instructions.md`, then `AGENTS.md`/`CLAUDE.md`/`GEMINI.md`, then organization instructions. Higher instructions take precedence, but all relevant sets are provided. GitHub Docs — Precedence GitHub Docs — Custom instructions support

Prompt files are manual, reusable task prompts stored as .github/prompts/*.prompt.md. The customization cheat sheet contrasts them with custom instructions: instructions trigger automatically; prompt files are selected directly in chat or through the prompt picker. GitHub Docs — Customization cheat sheet

Prompt file format

The documented path is .github/prompts/*.prompt.md. The GitHub Docs pages cited here show body-only Markdown prompt-file examples and do not publish a complete front-matter schema, so this page does not invent one. GitHub Docs — Prompt files

Review the selected API handler for security and reliability.
Check authentication, authorization, input validation, error handling, rate limits, and failure-path tests.
Return a table with finding, risk, affected code, and recommended fix.

Common anti-patterns
#

Anti-patternBetter approach
Asking for everything at onceBreak the task into smaller prompts
Saying “this” without a referenceName the file, function, symbol, or variable
Leaving irrelevant files openOpen relevant files and close irrelevant ones
Letting irrelevant chat history accumulateStart a new thread or delete irrelevant turns
Hiding requirements in proseUse bullets, examples, acceptance criteria, and tests
Overloading custom instructionsKeep them short, scoped, and non-conflicting

Always check Copilot’s work: understand suggested code, review function and security, and use tests, linting, code scanning, and IP scanning where appropriate. GitHub Docs — Check Copilot’s work

Check yourself
#

Question 1

Which prompt is most likely to produce a useful Copilot answer?

A) Fix this
B) Make it better
C) Refactor `parseInvoiceCsv` in #file:src/billing/import.ts to reject blank rows, preserve existing column names, and add tests for malformed dates
D) Do the billing thing

Show answer

Answer: C. It names the file, behavior, constraints, and validation expectation.

Question 2

What does few-shot prompting add to a prompt?

A) Multiple examples of the desired pattern
B) A larger model
C) A hidden organization policy
D) A slash command

Show answer

Answer: A. Examples clarify the target behavior and reduce ambiguity.

Question 3

Which VS Code chat variable is current for project context?

A) @workspace
B) #project
C) #editor
D) #terminalLastCommand

Show answer

Answer: B. The current VS Code cheat sheet lists `#project`.

Question 4

What should you do when chat turns are irrelevant?

A) Keep prompting in the same thread
B) Start a new conversation or delete irrelevant requests
C) Add vague context
D) Disable all instructions

Show answer

Answer: B. Copilot uses chat history as context, so keep it relevant.

Question 5

Which statement about prompt files is safest based on the cited GitHub Docs?

A) They are automatic repository-wide rules
B) They live in `.github/prompts/*.prompt.md` and are reusable task prompts
C) They replace organization instructions
D) They are supported in every Copilot surface

Show answer

Answer: B. Prompt files are reusable task prompts; custom instructions are the automatic mechanism.