What this prompt does
This template works by front-loading everything Copilot needs before it writes a single line: project name, language, framework, design pattern, and dependencies all appear as structured comments before the task description. Copilot's suggestion engine treats surrounding file context as a strong prior — the more specific that prior, the more constrained and accurate the completion.
The // Example of desired output style: block is the highest-leverage part. Copilot is a next-token predictor at its core. Showing it a concrete style sample — your naming conventions, indentation, error-handling approach — steers the completion away from its average training distribution and toward your actual codebase patterns. The explicit // Implementation: terminator signals where generation should begin, reducing the chance Copilot fills space with additional header comments instead of code.
When to use it
- Generating a new service class that must match your repository's existing architecture (e.g., Repository pattern with dependency injection in Laravel)
- Scaffolding framework-specific boilerplate where defaults would be wrong (e.g., Livewire component vs. plain PHP class)
- Working across multiple languages in a monorepo where Copilot needs an explicit signal about which runtime context applies
- Producing test stubs that match your project's assertion style and factory usage
- Onboarding a new module where no sibling file exists yet to give Copilot implicit context
Example output
For a Laravel service class using the Repository pattern:
<?php
namespace App\Services;
use App\Repositories\Contracts\OrderRepositoryInterface;
use App\Models\Shop\Order;
class OrderFulfillmentService
{
public function __construct(
private readonly OrderRepositoryInterface $orders
) {}
public function fulfill(int $orderId): Order
{
$order = $this->orders->findOrFail($orderId);
$order->markFulfilled();
$this->orders->save($order);
return $order;
}
}
Copilot inferred constructor injection, readonly properties, and the findOrFail + save pattern from the header context — none of which it would produce with a bare // Task: comment alone.
Pro tips
- Be specific in
[design_pattern]: writeRepository + Service Layernot justMVC. Vague patterns produce vague code. - The
[code_example]field should be 5-15 lines from your actual codebase, not invented. Copy-paste a real sibling method — Copilot matches style precisely. - List only the dependencies directly relevant to the task in
[dependencies]. Adding the entire composer.json is noise;illuminate/database, spatie/laravel-medialibraryis signal. - Pair this with Copilot Chat's
#filereferences for complex tasks — the header primes inline completions, while#filegives Chat deeper cross-file awareness. - For multi-file tasks, repeat the header in each new file rather than assuming Copilot carries context across buffers.