Copilot CLI: Automation, Programmatic Mode, Scripts, and GitHub Actions

Programmatic Copilot CLI usage patterns for scripts, CI jobs, GitHub Actions, and reusable automation flows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Programmatic mode basics
Capture output in a script
description=$(copilot -p "Describe this file briefly: $file" -s 2>/dev/null)

# Store Copilot output in a shell variable.

Pipe prompt text and redirect the answer
echo "Summarize the changelog impact of this commit" | copilot > summary.txt

# Generate output for downstream steps.

Run a prompt with automatic tools
copilot --allow-all-tools -p "Run the test suite, inspect the failures, and propose the minimal patch."

# Let Copilot use tools during a non-interactive run.

Export a session transcript after a run
copilot -p "Generate release notes from recent commits." --share=./copilot-session.md

# Save the output session to Markdown.

Share programmatic output to a secret gist
copilot -p "Summarize open pull requests assigned to me." --share-gist

# Publish the transcript as a gist.

Analyze a file from CI
copilot -p "Explain the risk profile of this generated migration: ./db/migrations/20260327_add_index.sql"

# Use a one-off prompt to inspect generated artifacts or source files.

## GitHub Actions patterns
Install Copilot CLI in a Linux job with Homebrew
- run: brew install copilot-cli

# Bootstrap Copilot in a GitHub Actions runner.

Install Copilot CLI in a workflow with npm
- run: npm install -g @github/copilot

# Use Node-based installation in CI.

Provide a token in GitHub Actions
env:
  COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}

# Authenticate programmatically in a workflow step.

Run a prompt in a workflow step
- run: copilot -p "Summarize recent repository activity for the release report."

# Execute Copilot in a job step.

Write Copilot output to a file artifact
- run: copilot -p "Generate a brief test report from the logs in this directory." > report.md

# Persist generated text for later workflow steps.

## Script recipes
Describe large files in a shell loop
while IFS= read -r -d "" file; do
  description=$(copilot -p "Describe this file briefly: $file" -s 2>/dev/null)
  echo "$file => $description"
done < <(find . -type f -size +10M -print0)

# Use Copilot inside a `while` loop.

Draft release notes from Git history
git log --oneline -20 | copilot > release-notes.md

# Combine git and Copilot for release automation.

Review generated SQL migrations
copilot -p "Review the SQL files in ./migrations for locking risk, data loss risk, and rollback gaps."

# Use Copilot as a quick reviewer in a script.

Produce an onboarding report automatically
copilot -p "Create a concise onboarding guide for this repository with setup, test, build, and deployment commands." > onboarding.md

# Generate repo setup instructions in Markdown.

Recommended next

No recommendations yet.