Skip to content

Add a copilot PowerShell wrapper that pre-approves safe file writes (--allow-tool='write') #637

Description

@DevSecNinja

Context

When using GitHub Copilot CLI in a trusted, git-tracked repo, every file create/edit triggers a manual "accept" prompt. For routine edits this is a lot of clicking, and git already provides the safety net (/diff, /rewind, git restore).

Copilot CLI can pre-approve the non-shell file-modifying tools via the write permission:

copilot --allow-tool='write'

This pre-approves file create/edit only. Shell (shell/bash) stays gated, and MCP tools (e.g. WorkIQ) are unaffected, so it stays least-privilege.

Proposal

Add a copilot wrapper (function + alias) that always passes --allow-tool='write' (optionally plus read-only git), so interactive sessions stop prompting on every edit.

Suggested default:

copilot --allow-tool='write,shell(git status),shell(git diff)'

Where

  • Simple version: a function in home/dot_config/powershell/aliases.ps1.
  • Preferred (matches the existing CopilotSsh.ps1 pattern): an Invoke-Copilot function in home/dot_config/powershell/modules/DotfilesHelpers/Public/Copilot.ps1 with a copilot alias, documented in docs/copilot-cli.md.

Implementation notes

  • Avoid infinite recursion. A function named copilot must call the real executable, not itself. Resolve it explicitly:

    function Invoke-Copilot {
        $exe = Get-Command copilot.exe -CommandType Application -ErrorAction SilentlyContinue |
               Select-Object -First 1
        if (-not $exe) { throw 'copilot CLI not found on PATH' }
        & $exe.Source --allow-tool="$($env:COPILOT_ALLOW_TOOLS ?? 'write')" @args
    }
    Set-Alias copilot Invoke-Copilot
  • Keep an escape hatch. Allow running the raw CLI (e.g. copilot.exe ..., or a -Raw switch) when you deliberately want every prompt.

  • Make the allowed tools configurable via an env var (e.g. $env:COPILOT_ALLOW_TOOLS, default write) so the list can be widened/narrowed without editing the function.

  • Do NOT use --allow-all-tools / --yolo — too broad (grants shell + URLs).

Acceptance criteria

  • Running copilot interactively no longer prompts for each file create/edit.
  • Shell commands still prompt for approval.
  • A documented way to run the unwrapped CLI remains.
  • Allowed-tools list is configurable (env var or variable).
  • Works under PowerShell 7 (home/Documents/PowerShell/profile.ps1).
  • Documented in docs/copilot-cli.md.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions