### Example Copilot Setup Steps Workflow Source: https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment This is a basic example of a `copilot-setup-steps.yml` file for a TypeScript project. It demonstrates cloning the repository, installing Node.js, and downloading/caching project dependencies. Customize this file according to your project's specific language and dependency requirements. ```YAML name: "Copilot Setup Steps" jobs: copilot-setup-steps: runs-on: ubuntu-latest steps: - name: "Checkout code" uses: actions/checkout@v3 - name: "Setup Node.js" uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - name: "Install dependencies" run: npm ci ``` -------------------------------- ### Quick Start Filesystem MCP Server Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/features/mcp Example demonstrating how to create a session with a local filesystem MCP server using the Copilot SDK. This setup allows the model to interact with the filesystem. ```typescript import { CopilotClient } from "@github/copilot-sdk"; async function main() { const client = new CopilotClient(); // Create session with filesystem MCP server const session = await client.createSession({ mcpServers: { filesystem: { type: "local", command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"], tools: ["*"], }, }, }); console.log("Session created:", session.sessionId); // The model can now use filesystem tools const result = await session.sendAndWait({ prompt: "List the files in the allowed directory", }); console.log("Response:", result?.data?.content); await session.disconnect(); await client.stop(); } main(); ``` -------------------------------- ### Initialize and Use Copilot Client in Go Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/setup/bundled-cli This Go example demonstrates initializing the Copilot client, starting it, creating a session, sending a prompt, and logging the response content. Note that the Go SDK does not bundle the CLI and requires separate installation or configuration. ```go package main import ( "context" "fmt" "log" copilot "github.com/github/copilot-sdk/go" ) func main() { ctx := context.Background() client := copilot.NewClient(nil) if err := client.Start(ctx); err != nil { log.Fatal(err) } defer client.Stop() session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"}) response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"}) if d, ok := response.Data.(*copilot.AssistantMessageData); ok { fmt.Println(d.Content) } } ``` ```go client := copilot.NewClient(nil) if err := client.Start(ctx); err != nil { log.Fatal(err) } defer client.Stop() session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"}) response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"}) if d, ok := response.Data.(*copilot.AssistantMessageData); ok { fmt.Println(d.Content) } ``` -------------------------------- ### Start Fleet Mode in Go (Full Example) Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/features/fleet-mode A complete Go example demonstrating how to initialize the Copilot client, create a session, and start fleet mode with a prompt. This binding is experimental; pin the SDK and Copilot CLI runtime. ```go package main import ( "context" "fmt" copilot "github.com/github/copilot-sdk/go" "github.com/github/copilot-sdk/go/rpc" ) func main() { ctx := context.Background() client := copilot.NewClient(nil) session, err := client.CreateSession(ctx, &copilot.SessionConfig{}) if err != nil { return } prompt := "Update each package independently, then report validation results." result, err := session.RPC.Fleet.Start(ctx, &rpc.FleetStartRequest{ Prompt: &prompt, }) if err != nil { return } if result.Started { fmt.Println("Fleet mode started") } } ``` -------------------------------- ### Basic Copilot Setup Steps Workflow Source: https://docs.github.com/en/copilot/customizing-copilot/customizing-the-development-environment-for-copilot-coding-agent A simple example of a `copilot-setup-steps.yml` file for a TypeScript project. This workflow clones the project, installs Node.js, and downloads/caches project dependencies. Customize this file to match your project's specific language and dependency requirements. ```yaml name: "Copilot Setup Steps" ``` -------------------------------- ### Install Go Copilot SDK Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/setup/choosing-a-setup-path Install the Go SDK using go get. Note that this requires a separate CLI installation. ```bash go get github.com/github/copilot-sdk/go ``` -------------------------------- ### Install a Copilot Skill from GitHub Awesome Copilot Source: https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agent/add-skills Example of installing the 'documentation-writer' skill from the 'github/awesome-copilot' repository. ```bash gh skill install github/awesome-copilot documentation-writer ``` -------------------------------- ### Initialize and Use Copilot Client in Java Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/setup/bundled-cli This Java example demonstrates initializing the Copilot client with a specified CLI path, starting the client, creating a session with automatic permission approval, sending a prompt, and printing the response. The CLI must be installed and its path configured. ```java import com.github.copilot.CopilotClient; import com.github.copilot.rpc.*; var client = new CopilotClient(new CopilotClientOptions() // Point to the CLI binary installed on the system .setCliPath("/path/to/vendor/copilot") ); client.start().get(); var session = client.createSession(new SessionConfig() .setModel("gpt-4.1") .setOnPermissionRequest(PermissionHandler.APPROVE_ALL) ).get(); var response = session.sendAndWait(new MessageOptions() .setPrompt("Hello!")).get(); System.out.println(response.getData().content()); client.stop().get(); ``` -------------------------------- ### Quick Start: Azure AI Foundry (.NET) Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/auth/byok Example of setting up and using the Copilot SDK with Azure AI Foundry using .NET. Requires setting the FOUNDRY_API_KEY environment variable. ```csharp // .NET code snippet placeholder ``` -------------------------------- ### Initialize Go Module and Install SDK Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/sdk-getting-started Create a new directory, initialize it as a Go module, and then install the Copilot SDK for Go. ```bash mkdir copilot-demo && cd copilot-demo go mod init copilot-demo ``` ```bash go get github.com/github/copilot-sdk/go ``` -------------------------------- ### Initialize Go Project and Install SDK Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/getting-started Create a new Go module for your project and install the GitHub Copilot SDK. ```bash mkdir copilot-demo && cd copilot-demo go mod init copilot-demo ``` ```bash go get github.com/github/copilot-sdk/go ``` -------------------------------- ### Configure GitHub Actions for Copilot Setup Source: https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment Define steps in your GitHub Actions workflow to set up the environment before the Copilot agent starts. This includes checking out code, setting up Node.js, and installing dependencies. ```yaml jobs: copilot-setup-steps: # You can define any steps you want, and they will run before the agent starts. # If you do not check out your code, Copilot will do this for you. steps: - name: Checkout code uses: actions/checkout@v6 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: "20" cache: "npm" - name: Install JavaScript dependencies run: npm ci ``` -------------------------------- ### Main entry point with service initializations Source: https://docs.github.com/en/copilot/tutorials/copilot-cookbook/refactor-code/handle-cross-cutting This Python script initializes various services and demonstrates their usage. It sets up logging via `setup_logging` before proceeding with service calls. ```python import logging from logging_config import setup_logging from payment_service import PaymentService from order_service import OrderService from shipping_service import ShippingService from inventory_service import InventoryService from notification_service import NotificationService def main(): setup_logging() payment_service = PaymentService() order_service = OrderService() shipping_service = ShippingService() inventory_service = InventoryService() notification_service = NotificationService() # Example usage payment_service.process_payment({"amount": 100, "currency": "USD"}) order_service.place_order({"item": "Book", "quantity": 1}) shipping_service.ship_order({"item": "Book", "quantity": 1}) inventory_service.update_inventory("Book", -1) notification_service.send_notification("Order has been placed and shipped.") if __name__ == "__main__": main() ``` -------------------------------- ### Preinstalling Tools and Dependencies for Copilot Agent Source: https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/customize-the-agent-environment Use a `copilot-setup-steps` job in your workflow to define steps for installing tools and dependencies before the Copilot agent starts. This ensures deterministic setup and can handle private dependencies. ```yaml # ... jobs: copilot-setup-steps: # ... # You can define any steps you want, and they will run before the agent starts. # If you do not check out your code, Copilot will do this for you. steps: - name: Checkout code uses: actions/checkout@v6 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: "20" cache: "npm" - name: Install JavaScript dependencies run: npm ci ``` -------------------------------- ### Example Repository Instructions Source: https://docs.github.com/en/copilot/how-tos/copilot-cli/cli-best-practices This is a sample `.github/copilot-instructions.md` file demonstrating how to define build commands, code style preferences, and workflow guidelines for Copilot CLI within a repository. ```markdown ## Build Commands - `npm run build` - Build the project - `npm run test` - Run all tests - `npm run lint:fix` - Fix linting issues ## Code Style - Use TypeScript strict mode - Prefer functional components over class components - Always add JSDoc comments for public APIs ## Workflow - Run `npm run lint:fix && npm test` after making changes - Commit messages follow conventional commits format - Create feature branches from `main` ``` -------------------------------- ### Example Repository Custom Instructions File Source: https://docs.github.com/en/copilot/concepts/about-customizing-github-copilot-chat-responses?tool=webui This example `.github/copilot-instructions.md` file demonstrates how to provide specific instructions to Copilot regarding dependency management, coding conventions, and project tracking tools. ```markdown We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel. We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions. Our team uses Jira for tracking items of work. ``` -------------------------------- ### Example GitHub Actions Workflow for Daily Summary Source: https://docs.github.com/en/copilot/how-tos/copilot-cli/automate-with-actions This workflow demonstrates how to install Copilot CLI, run it to get details of changes made today in the default branch, and use that output as the workflow run summary. ```yaml name: Daily summary on: workflow_dispatch: ``` -------------------------------- ### Configure Copilot Setup Steps Job Source: https://docs.github.com/en/copilot/customizing-copilot/customizing-the-development-environment-for-copilot-coding-agent Defines a GitHub Actions job named `copilot-setup-steps` that can include custom steps to run before the Copilot agent starts. This example shows basic job structure and comments on checkout behavior. ```yaml jobs: copilot-setup-steps: # ... # You can define any steps you want, and they will run before the agent starts. # If you do not check out your code, Copilot will do this for you. steps: - name: Checkout code uses: actions/checkout@v6 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: "20" cache: "npm" - name: Install JavaScript dependencies run: npm ci ``` -------------------------------- ### Session Start Hook Example Source: https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-hooks This example demonstrates how to use the `sessionStart` hook to log the session start date to a file. It includes commands for both bash (Linux/macOS) and PowerShell (Windows). ```json "sessionStart": [ { "type": "command", "bash": "echo \"Session started: $(date)\" >> logs/session.log", "powershell": "Add-Content -Path logs/session.log -Value \"Session started: $(Get-Date)\"", "cwd": ".", "timeoutSec": 10 } ], ``` -------------------------------- ### Quick Start: Azure AI Foundry (Go) Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/auth/byok Example of setting up and using the Copilot SDK with Azure AI Foundry using Go. Requires setting the FOUNDRY_API_KEY environment variable. ```go package main import ( "context" "fmt" "os" copilot "github.com/github/copilot-sdk/go" ) func main() { ctx := context.Background() client := copilot.NewClient(nil) if err := client.Start(ctx); err != nil { panic(err) } defer client.Stop() session, err := client.CreateSession(ctx, &copilot.SessionConfig{ Model: "gpt-5.2-codex", // Your deployment name Provider: &copilot.ProviderConfig{ Type: "openai", BaseURL: "https://your-resource.openai.azure.com/openai/v1/", WireAPI: "responses", // Use "completions" for older models APIKey: os.Getenv("FOUNDRY_API_KEY"), }, }) if err != nil { panic(err) } response, err := session.SendAndWait(ctx, copilot.MessageOptions{ Prompt: "What is 2+2?", }) if err != nil { panic(err) } if d, ok := response.Data.(*copilot.AssistantMessageData); ok { fmt.Println(d.Content) } } ``` -------------------------------- ### Initialize Node.js Project Source: https://docs.github.com/en/copilot/tutorials/modernizing-legacy-code-with-github-copilot Use 'npm init -y' to create a package.json file for your Node.js project. Install dependencies with 'npm install' and start the application using 'npm start'. ```shell npm init -y ``` ```shell npm install ``` ```shell npm start ``` -------------------------------- ### Project setup slash commands Source: https://docs.github.com/en/copilot/get-started/getting-started-with-prompts-for-copilot-chat Use the /new and /newNotebook commands to initialize projects or Jupyter notebooks. ```text /new react app with typescript ``` ```text /new python django web application ``` ```text /new node.js express server ``` ```text /newNotebook retrieve the titanic dataset and use Seaborn to plot the data ``` -------------------------------- ### Load Skills in Go Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/features/skills This Go example shows how to set up a Copilot client and create a session, including specifying skill directories and handling permission requests with `rpc.PermissionDecisionApproveOnce`. ```go package main import ( "context" "log" copilot "github.com/github/copilot-sdk/go" "github.com/github/copilot-sdk/go/rpc" ) func main() { ctx := context.Background() client := copilot.NewClient(nil) if err := client.Start(ctx); err != nil { log.Fatal(err) } defer client.Stop() session, err := client.CreateSession(ctx, &copilot.SessionConfig{ Model: "gpt-4.1", SkillDirectories: []string{ "./skills/code-review", "./skills/documentation", }, OnPermissionRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (rpc.PermissionDecision, error) { return &rpc.PermissionDecisionApproveOnce{}{}, nil }, }) if err != nil { log.Fatal(err) } // Copilot now has access to skills in those directories _, err = session.SendAndWait(ctx, copilot.MessageOptions{ Prompt: "Review this code for security issues", }) if err != nil { log.Fatal(err) } } ``` -------------------------------- ### Example copilot-setup-steps.yml workflow Source: https://docs.github.com/en/copilot/tutorials/cloud-agent/improve-a-project This YAML snippet shows the basic structure of a `copilot-setup-steps.yml` file, including triggers and the required job name for the Copilot cloud agent. ```yaml on: workflow_dispatch: push: paths: - .github/workflows/copilot-setup-steps.yml pull_request: paths: - .github/workflows/copilot-setup-steps.yml jobs: copilot-setup-steps: runs-on: ubuntu-latest ``` -------------------------------- ### Example: Schedule a skill to create a file Source: https://docs.github.com/en/copilot/how-tos/copilot-cli/automate-copilot-cli/schedule-prompts This example demonstrates scheduling a skill using `/after` to create a new file that summarizes recent repository changes after a 2-hour delay. ```copilot /after 2h Use the docx skill to create a new file summarizing recent changes to this repo ``` -------------------------------- ### Request a Go date extraction function with examples Source: https://docs.github.com/en/copilot/using-github-copilot/prompt-engineering-for-github-copilot A prompt providing specific date format requirements and an example function call to guide the output. ```text Write a Go function that finds all dates in a string and returns them in an array. Dates can be formatted like: * 05/02/24 * 05/02/2024 * 5/2/24 * 5/2/2024 * 05-02-24 * 05-02-2024 * 5-2-24 * 5-2-2024 Example: findDates("I have a dentist appointment on 11/14/2023 and book club on 12-1-23") Returns: ["11/14/2023", "12-1-23"] ``` -------------------------------- ### Create .NET Project and Add SDK Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/getting-started Initialize a new .NET console application and add the GitHub Copilot SDK package using the dotnet CLI. ```bash dotnet new console -n CopilotDemo && cd CopilotDemo ``` ```bash dotnet add package GitHub.Copilot.SDK ``` -------------------------------- ### Example Repository-Wide Custom Instructions for Copilot Source: https://docs.github.com/en/copilot/how-tos/copilot-on-github/use-copilot-agents/copilot-code-review This example demonstrates how to configure repository-wide custom instructions in a `.github/copilot-instructions.md` file. These instructions guide Copilot's code review behavior across the entire repository. ```text When performing a code review, respond in Spanish. When performing a code review, apply the checks in the `/security/security-checklist.md` file. When performing a code review, focus on readability and avoid nested ternary operators. ``` -------------------------------- ### Start Fleet Mode in .NET (Full Example) Source: https://docs.github.com/en/copilot/how-tos/copilot-sdk/features/fleet-mode Demonstrates starting fleet mode in .NET using `CopilotClient` and `CreateSessionAsync`. The fleet mode binding is experimental; pin the SDK and Copilot CLI runtime. ```csharp using GitHub.Copilot; await using var client = new CopilotClient(); await using var session = await client.CreateSessionAsync(new SessionConfig()); var result = await session.Rpc.Fleet.StartAsync( "Audit each project independently, then summarize the findings."); if (result.Started) { Console.WriteLine("Fleet mode started"); } ``` -------------------------------- ### Example Plan Output Source: https://docs.github.com/en/copilot/tutorials/copilot-cookbook/generate-code/implement-a-feature GitHub Copilot CLI provides a detailed plan, outlining steps for implementation, routing, schema updates, and testing. ```text 1. Add a `getPlanForSubscription` method in `src/services/subscriptionService.ts` that reuses the existing billing client, throws `NotFoundError` when the subscription or plan does not exist, and throws `CancelledSubscriptionError` when the subscription has been cancelled. 1. Add a `GET /subscriptions/:id/plan` route in `src/routes/subscriptions.ts`, mirroring the error handling in the sibling `GET /subscriptions/:id` route and mapping `CancelledSubscriptionError` to a `410` response. 1. Update `openapi/subscriptions.yaml` with the new path, response schema, and `404` and `410` responses. 1. Add unit tests in `test/services/subscriptionService.test.ts` and `test/routes/subscriptions.test.ts` covering the success case, missing subscription, cancelled subscription, and missing plan. 1. Run the test suite and update the changelog entry. ```