GitHub Copilot

Run GitHub Copilot CLI with copilot -p in scripts and CI (2026)

How do I run GitHub Copilot CLI non-interactively with copilot -p in shell scripts and GitHub Actions?

Pass a prompt with -p or --prompt and Copilot CLI runs it and exits. Add -s to print only the response, --no-ask-user so it never stops for input, and --allow-tool to grant only the tools the task needs. In CI, set COPILOT_GITHUB_TOKEN to a fine-grained personal access token with the Copilot Requests permission, or in an organization-owned repository use the built-in GITHUB_TOKEN with the copilot-requests: write permission.

Compare: headless mode for scripts and CI in every AI coding agent →

GitHub Copilot settings change often

Get one email a week when a setting, flag or permission rule changes, checked against the vendor docs.

Run a single prompt

Use -p or --prompt to run a prompt in non-interactive mode. The CLI runs the prompt and exits when done. You can also pipe a prompt in. Piped input is ignored if you also pass -p.

Prompt flag or pipe

copilot -p 'Explain this file: ./complex.ts'
echo 'Explain this file: ./complex.ts' | copilot

GitHub suggests single quotes around prompts so the shell does not interpret special characters, and setting --model explicitly for consistent behavior across environments.

Clean output and no questions

  • -s (--silent): suppresses stats and decoration so only the agent's response is printed. Use it when piping or capturing output.
  • --no-ask-user: stops the agent from pausing to ask clarifying questions.
  • --model=MODEL: picks the model. COPILOT_MODEL also works, but a custom agent's model and the --model flag take precedence.
  • --secret-env-vars=VAR: redacts that variable's value in output. GITHUB_TOKEN and COPILOT_GITHUB_TOKEN are redacted by default.

Capture the answer in a variable

result=$(copilot -p 'What version of Node.js does this project require? Give the number only. No other text.' -s)

The programmatic reference does not document a JSON output format or exit codes for copilot -p. It points to copilot help for the full option list.

Grant only the tools the task needs

  • --allow-tool: grant specific tools. For several, use a quoted, comma-separated list.
  • --deny-tool: block specific tools, useful in a locked-down workflow.
  • --allow-all-tools: let every tool run without per-tool approval.
  • --allow-all or --yolo: equals --allow-all-tools --allow-all-paths --allow-all-urls.
  • Tool kinds: shell, write, read, url, memory, and MCP server names. Narrow them with filters such as shell(git:*), write(README.md), url(github.com) or github(create_issue).

Commit message with git access only

copilot -p 'Write a commit message in plain text for the staged changes' -s \
  --allow-tool='shell(git:*)'

GitHub advises against overly permissive options such as --allow-all unless you are in a sandbox environment.

Save the session transcript

  • --share=PATH: exports the transcript to a Markdown file after a non-interactive run. The default is ./copilot-session-<ID>.md.
  • --share-gist: publishes the transcript as a secret GitHub gist. Gists are not available to Enterprise Managed Users or to GitHub Enterprise Cloud with data residency.
  • Transcripts can contain sensitive information, so check before sharing.

Keep an audit report

copilot -p '/review' -s --allow-tool='shell(git:*)' --share='./audit-report.md'

Authenticate in CI

Copilot CLI reads COPILOT_GITHUB_TOKEN first, then GH_TOKEN, then GITHUB_TOKEN. Supported tokens include fine-grained personal access tokens with the Copilot Requests permission. Classic personal access tokens (ghp_) are not supported.

  • Create a fine-grained token with the Copilot Requests permission and save it as a repository secret.
  • Set COPILOT_GITHUB_TOKEN from that secret so Copilot CLI uses it instead of the built-in GITHUB_TOKEN.
  • For organization-owned repositories GitHub recommends the built-in GITHUB_TOKEN, so no PAT or stored secret is needed. Grant the workflow copilot-requests: write, pass GITHUB_TOKEN: ${{ github.token }} to the step, and make sure the organization's Copilot CLI policy allows use of Copilot CLI billed to the organization.
  • Use a PAT instead when the organization has not enabled that policy or you want usage billed to a specific user's Copilot seat.

GitHub Actions example

This is GitHub's documented daily summary workflow. It installs the CLI from npm, runs one prompt with git and write access, and appends the result to the job summary.

.github/workflows/daily-summary.yml

name: Daily summary
on:
  workflow_dispatch:
  schedule:
    - cron: '30 17 * * *'
permissions:
  contents: read
jobs:
  daily-summary:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - name: Set up Node.js environment
        uses: actions/setup-node@v7
      - name: Install Copilot CLI
        run: npm install -g @github/copilot
      - name: Run Copilot CLI
        env:
          COPILOT_GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
        run: |
          copilot -p "Review the git log for this repository and write a bullet point summary of all code changes that were made today, with links to the relevant commit on GitHub. Above the bullet list give a description (max 100 words) summarizing the changes made. Write the details to summary.md" --allow-tool='shell(git:*)' --allow-tool=write --no-ask-user
          cat summary.md >> "$GITHUB_STEP_SUMMARY"

GitHub also recommends GitHub Agentic Workflows for most automation, since they default to GITHUB_TOKEN and add guardrails.

Related guides

Get GitHub Copilot settings changes by email

When a setting, flag or permission rule in this guide changes, it goes in the weekly AgentAtlas update, checked against the vendor docs. One email a week.

Sources

More on GitHub Copilot

More GitHub Copilot guides

Other guides

How to allow Cursor to run all commands: Run Everything, allowlist and sandboxHow to allow Claude Code to run all commands: permission modes, allow rules and skip permissionsClaude Code permissions: allow, ask and deny rules, rule syntax and allowed toolsCodex CLI: approval and sandbox modesGemini CLI: YOLO mode, auto_edit and allowing specific shell commandsCursor Privacy Mode: telemetry, training and data retentionClaude Code telemetry and data retention: what is sent and how to turn it offGemini CLI: turn off usage statistics and telemetryCLAUDE.md: where it goes, how it loads, and how it works with AGENTS.mdClaude Code hooks: format on save, block risky edits, get notifiedClaude Code subagents: create one, limit its tools, and call itAdd MCP servers to Cursor with mcp.json: Keep files out of Cursor with .cursorignore: Configure Codex with config.toml: Configure Gemini CLI with settings.json: Add MCP servers to Claude Code (claude mcp add, .mcp.json, scopes): Claude Code custom slash commands and skills (SKILL.md): Claude Code settings.json: file locations, precedence, and key settingsClaude Code plugins and marketplaces: install, create, and shareGemini CLI extensions and custom commands: Configuring OpenCode with opencode.json: Cline Rules: workspace, global, and conditional rulesKiro steering files: .kiro/steering, inclusion modes, and AGENTS.mdZed agent: instruction files, MCP servers, tool permissions, and ACP agentsCursor CLI: install, headless mode, permissions and CIAider: CONVENTIONS.md, .aider.conf.yml and API keysJunie guidelines, MCP and the Action Allowlist: Amp AGENTS.md, settings.json and MCP: Configure Goose extensions, hints, recipes and permissions: Customize OpenHands with skills, AGENTS.md, setup.sh and MCP: Configure Factory Droid CLI: AGENTS.md, settings.json, autonomy, custom droids and MCPConfigure Qwen Code: settings.json, providers, QWEN.md, MCP and approval modesCursor hooks: hooks.json, beforeShellExecution, afterFileEdit and exit codesCursor sandbox: sandbox.json, network allowlist and run modesCursor settings: settings.json, Cursor Settings and the ~/.cursor config filesCursor browser agent: @browser, browser automation and approval modesCursor subagents: .cursor/agents, frontmatter, built-in Explore and BrowserCursor telemetry and OpenTelemetry export (Privacy Mode, OTLP, Analytics API): Cursor rules setup: project, user and Team Rules, .mdc frontmatter, globs and AGENTS.mdClaude Code headless mode: claude -p, --output-format json, --bare and CI flagsClaude Code statusline: custom status bar in settings.json with context %, cost and git branchClaude Code /model: switch models, aliasesClaude Code /cost and /usage: check token spend, usage limits and reduce costsClaude Code VS Code extension: install, shortcuts, settings and /ideCodex AGENTS.md: global, project and override instruction files explainedCodex MCP servers: codex mcp add and [mcp_servers] in config.tomlCodex sandbox modes: read-only, workspace-write, danger-full-access and network accesscodex exec: run Codex non-interactively in scripts and CI with JSON outputCodex skills: create SKILL.md, skill folder locations and $skill invocationGEMINI.md in Gemini CLI: context file locations, imports and /memoryGemini CLI MCP servers: gemini mcp add and mcpServers in settings.jsonGemini CLI custom slash commands: TOML files, {{args}}, !{shell} and @{file}Gemini CLI headless mode: gemini -p, JSON output and exit codes for scripts and CIGemini CLI sandbox: enable Docker, Podman, macOS Seatbelt or gVisorOpenCode MCP Server Setup: Local and Remote Servers in opencode.jsonOpenCode Permissions: Allow, Ask or Deny Bash, Edit and WebfetchOpenCode Custom Agents and Subagents: Markdown Files, Modes and @ MentionsCline MCP Setup: cline_mcp_settings.json for Local and Remote ServersCline Auto Approve and YOLO Mode: Run Commands and Edits Without PromptsCline Skills: SKILL.md Location, Format and Slash Command UseAmp MCP Setup: amp mcp add, amp.mcpServers and Workspace ApprovalAmp AGENTS.md: File Locations, @ Mentions and Glob-Scoped GuidanceAmp Skills: SKILL.md Folders, amp skill add and Search OrderKiro MCP Setup: .kiro/settings/mcp.json, autoApprove and OAuthKiro Hooks: .kiro/hooks JSON, PreToolUse, PostFileSave and StopKiro Permissions: permissions.yaml Allow, Ask and Deny RulesFactory Droid MCP Setup: droid mcp add, mcp.json Locations and /mcpFactory Droid Hooks: hooks.json, PreToolUse Matchers and Exit CodesFactory Droid Custom Droids (Subagents): .factory/droids Markdown FilesJunie MCP Setup: .junie/mcp/mcp.json for CLI and /mcp CommandJunie Brave Mode and Action Allowlist: Auto-Approve Commands in Junie CLIJunie Custom Slash Commands: .junie/commands Markdown Files and Argumentsgoose .goosehints and AGENTS.md: Global and Project Instructionsgoose Permission Modes: GOOSE_MODE auto, approve, smart_approve and chatgoose Recipes: recipe.yaml Format, Parameters and goose run --recipeZed Agent Tool Permissions: Auto-Approve Terminal Commands with tool_permissionsUse Claude, Codex and Gemini CLI in Zed: External Agents and agent_serversZed with Ollama, LM Studio and llama.cpp: Local Model Setup and Context LengthMCP 2026-07-28 Migration Guide: Stateless Protocol, No Sessions, server/discover, MRTR, and SDK v2 UpgradeSubagents and Custom Agents Compared: Claude Code vs Codex vs Cursor vs Gemini CLI vs GitHub CopilotAllow all commands in any AI coding agent: Cursor, Claude Code, Codex, Gemini CLI, Copilot CLI and 7 moreAdd an MCP server to any AI coding agent: Claude Code, Cursor, Codex, Gemini CLI, VS Code and 8 moreSettings file locations for every AI coding agent: Claude Code, Cursor, Codex, Gemini CLI, OpenCode, Qwen Code, Amp and Factory DroidRules and instruction files in every AI coding agent: .cursor/rules, CLAUDE.md, AGENTS.md, GEMINI.md, Copilot instructions and moreGemini CLI hooks: settings.json, BeforeTool, AfterTool, exit codes and /hooksHooks in every AI coding agent: Claude Code, Cursor, Gemini CLI, GitHub Copilot, Kiro and Factory DroidAgent Skills (SKILL.md) in every AI coding agent: Claude Code, Codex, Cline, Amp and OpenHandsHow to deploy a remote MCP server (Streamable HTTP): Cloudflare Workers, Vercel, Railway and moreHeadless mode in every AI coding agent: claude -p, codex exec, gemini -p, Cursor agent -p and copilot -p for scripts and CIClaude Code sandbox: /sandbox, sandbox.enabled, allowedDomains, excludedCommands and strict modeSandbox modes in every AI coding agent: Claude Code, Cursor, Codex and Gemini CLI comparedCustom slash commands in every AI coding agent: file locations, arguments and examplesMigrate from Gemini CLI to Antigravity CLI (2026): Config, MCP, Skills, Flags

Reviewed Oct 19, 2026. Settings change often; the linked vendor docs are the source of truth.