How to run GitHub Copilot CLI from a script with fixed permissions

Day 3, 30 minutes · beginner

Goal of this lessonRun Copilot CLI with one prompt and fixed tool permissions, see a denied command, and save the run as a weekly notes script.

Why it matters

So far you have sat at the keyboard and answered every approval. That is right for real changes. But some jobs are the same every week, such as a short summary of what changed on the site, and you do not want to open a session and type it again each time.

Copilot CLI can run one prompt and exit, with no conversation and nobody to answer questions. That is called programmatic mode. It is what you use in a script, a scheduled task or a CI job. The catch is that nobody is there to approve commands, so you decide up front which tools Copilot may use and which it may never use.

Today you run Copilot with one prompt and a fixed set of permissions, watch it refuse a command you blocked, and save the run as a small script that writes weekly notes for Roos.

How a one-prompt run works

You give Copilot the prompt with -p (or --prompt). Copilot does the task and exits. A few options make it fit for a script:

  • -s prints only Copilot's answer, without usage statistics, so you can save it to a file.
  • --no-ask-user stops Copilot from pausing to ask you a question, because nobody will answer.
  • --allow-tool lists what Copilot may do without asking. shell(git:*) means every git command.
  • --deny-tool lists what Copilot may never do. shell(git push) blocks pushing, and write blocks creating or changing any file.

Deny always wins. Even with --allow-tool='shell(git:*)', a denied git push stays blocked. That is the pattern GitHub's own reference shows: allow a family of commands, then deny the dangerous one.

What happens to a request you did not mention? In a one-prompt run there is nobody to ask, so a request that needs approval is denied. That is safe, but Copilot may not finish the job. Name what the job needs, and nothing more.

Why not just allow everything

--allow-all-tools (and --yolo, which also opens all paths and URLs) gives Copilot the same reach as you on your computer, without asking. GitHub's docs advise the broad options only inside a sandbox, such as a virtual machine or container, or Copilot's own local sandbox (/sandbox enable in a session, --sandbox for one run). For a weekly summary, Copilot needs to read the git history. It does not need to write files, delete anything or push. So that is exactly what you allow.

The steps

  1. Run one prompt with fixed permissions. Allow git, deny push and file writes, print only the answer.
  2. Check the answer against your git history. Two commits from lessons 1 and 2 should be in it.
  3. Test the lock. Ask the same locked run to push. Copilot cannot, and says so. This is the moment to see that the deny rule really works, before you trust it in a script.
  4. Save the run as a script that writes the answer to weekly-notes.md. The guide has a version for macOS and Linux and one for Windows PowerShell.
  5. Keep the output out of git. The notes change every week; the script is what you keep.
  6. Commit the script.

Follow the guide for GitHub Copilot below for the exact commands.

The script is the building block. Running it every Monday by itself (with cron, Task Scheduler or a GitHub Actions workflow) is the next step, and the Claude Code in action course covers what to think about before you let any agent run unattended. For Copilot in GitHub Actions, the docs sign in with a token stored as a secret, never typed into the workflow file.

Things to know before you rely on it

  • Every run uses AI credits, just like a session. A weekly script is cheap; a script in a loop over every file is not.
  • Do not trust the exit code to tell you the notes are right. GitHub documents a nonzero exit status only when the run is interrupted or the final answer is completely empty. Read the notes yourself, at least the first few weeks.
  • Your prompt is the contract. "Do not change any file" in the prompt is a request; --deny-tool='write' is the rule that holds.

Example: Roos's Monday notes

Roos ran the script on Monday. weekly-notes.md said, in four bullets, that the site went online with three cheeses and that Dune Goat was added at 3.40 per 100 g. When she tried the push prompt, Copilot answered that it was not allowed to run git push. She committed the script and added the notes file to .gitignore.

Common mistakes

  • Leaving out --no-ask-user. Copilot may stop to ask a question that nobody answers.
  • Allowing shell without a filter. That allows every shell command. Name the command family, such as shell(git:*).
  • Quoting the prompt with double quotes in a shell script. Single quotes stop the shell from reading special characters in your prompt.
  • Committing the output. The notes change every week. Commit the script, not its result.

Today's actions

Ticks are not saved without an account

Do it in GitHub Copilot

GitHub Copilot

  1. In the brindlewick-cheese folder, run this line. It gives Copilot one prompt, lets it run git commands, blocks git push and every file write, and prints only the answer.
    copilot -p 'Summarize the commits of the last 7 days for the shop owner in at most five plain bullet points. Mention every cheese or price that changed. Do not change any file.' -s --allow-tool='shell(git:*)' --deny-tool='shell(git push), write' --no-ask-user
  2. Read the answer. It should name the first version of the site and Dune Goat. If Copilot says it could not run git, check that you are inside the repository.
  3. Now ask the same locked run to push. The deny rule wins over the allow rule, so Copilot cannot run git push and should tell you so.
    copilot -p 'Push this repository to its remote.' -s --allow-tool='shell(git:*)' --deny-tool='shell(git push), write' --no-ask-user
  4. On macOS or Linux, create a file called weekly-notes.sh in the project with this text, then run bash weekly-notes.sh.
    copilot -p 'Summarize the commits of the last 7 days for the shop owner in at most five plain bullet points. Mention every cheese or price that changed. Do not change any file.' -s --allow-tool='shell(git:*)' --deny-tool='shell(git push), write' --no-ask-user > weekly-notes.md
  5. On Windows, create a file called weekly-notes.ps1 with this text instead, then run ./weekly-notes.ps1 in PowerShell.
    copilot -p 'Summarize the commits of the last 7 days for the shop owner in at most five plain bullet points. Mention every cheese or price that changed. Do not change any file.' -s --allow-tool='shell(git:*)' --deny-tool='shell(git push), write' --no-ask-user | Out-File -Encoding utf8 weekly-notes.md
  6. Open weekly-notes.md and read it. Keep the notes out of git: add a line weekly-notes.md to a file called .gitignore.
  7. Commit only the script and .gitignore, replacing weekly-notes.sh with weekly-notes.ps1 if you are on Windows.
    git add weekly-notes.sh .gitignore
    git commit -m "Add weekly notes script"

Note: Without any allow options, requests that need approval are denied in a run like this, and Copilot often cannot finish. --allow-all-tools lifts every limit at once: GitHub advises it only inside a sandbox. If PowerShell refuses to run the .ps1 file, paste the line into the terminal instead. --share='./run.md' saves the whole session as a Markdown file.

Checked on 4 December 2026 · Source: GitHub Docs: Running Copilot CLI programmatically (opens in a new tab)

Create a free account to save your progress. Sign in or sign up