On this page#
What changes when an agent does this#
GitHub Copilot API keys do not turn repository work into a hands-off operation. They move the bottleneck from producing code to proving that the change respects repository invariants. The scarce resource is no longer typing speed; it is a reviewable chain from credential scope to prompt, diff, validation evidence, and rollback.
“API key” is often used loosely here. Copilot access and GitHub API access are separate concerns, and the supported authentication path should come from the GitHub Copilot documentation, not from a copied token pattern or an unofficial endpoint.
In a real repository, the agent should receive only the capabilities required for the current task:
| Capability | Default | |---|---| | Read repository files | Allow | | Edit files inside the worktree | Allow when required | | Run named local checks | Allow | | Read unrelated secrets | Deny | | Push branches or tags | Deny | | Merge changes | Deny | | Change repository settings | Deny |
The wrong configuration gives the agent a broad token because broad access is convenient. That destroys the distinction between generating a patch and publishing it.
OAuth 2.0 is an authorization framework for granting limited access without handing an application the resource owner’s credentials; its roles and token model are defined in the OAuth 2.0 specification. Whether the integration uses OAuth or another supported mechanism, the engineering rule is the same: scope the credential to the smallest resource set and shortest operational path available.
Keep the repository configuration explicit and reviewable:
agent:
workspace: repository
allowed_paths:
- src/**
- tests/**
denied_paths:
- .env*
- .github/workflows/**
- infra/production/**
commands:
- npm test
- npm run lint
network: deny
git:
commit: deny
push: denyTreat this as policy documentation, not universal syntax. The exact keys vary by agent, but the decisions must survive tool replacement and a second engineer’s handoff.
Photo by Christina Morillo on Pexels.
The prompt chain#
Do not ask an agent to “fix the issue” in one prompt. Split the work into discovery, plan, implementation, and verification so each stage produces an artifact a reviewer can reject before the next stage expands the blast radius. The chain matters more than clever wording because it prevents hidden assumptions from becoming code.
Stage 1: Map the constraints#
The first prompt should prohibit edits and require the agent to identify invariants, affected surfaces, and unknowns. This creates a shared problem statement before code generation starts and exposes whether the agent actually understands the repository or is merely matching the issue description to a familiar pattern.
Do not edit files.
Read the relevant implementation, tests, configuration, and repository
instructions. Return:
1. The current behavior.
2. The requested behavior.
3. Invariants that must remain true.
4. Files likely to change, with reasons.
5. Existing tests that constrain the solution.
6. Unknowns that require human confirmation.
Do not propose implementation details until this map is complete.This stage should also identify credential boundaries. The GitHub Copilot documentation can explain supported product behavior, but it cannot tell the agent which internal deployment file must never change or which compatibility behavior your customers rely on. Those facts belong in the repository.
Stage 2: Produce a bounded plan#
The planning prompt should force the agent to connect each proposed edit to an invariant and a validation step. A useful plan is falsifiable: another engineer can point to a missing case, reject an unnecessary file change, or narrow the task before any implementation begins.
Using the approved constraint map, propose the smallest viable change.
For every planned file:
- state the exact responsibility being changed;
- name the invariant protected;
- name the test or inspection that will validate it.
List tempting adjacent changes separately and exclude them from the patch.
Stop after the plan. Do not edit files.The “adjacent changes” line is important. Agents often bundle cleanup, dependency updates, or type refactors into an otherwise narrow fix. That makes review slower and rollback less reliable.
Stage 3: Implement only the approved delta#
The implementation prompt should restate the boundary, forbid opportunistic edits, and require the agent to stop when repository evidence contradicts the plan. Never let the agent silently reinterpret approval as permission to redesign the surrounding subsystem.
Implement only the approved plan.
Constraints:
- Do not modify files outside the approved list.
- Do not change public interfaces unless explicitly approved.
- Do not weaken or delete existing tests.
- Add the smallest test that fails before the fix and passes after it.
- If the plan conflicts with repository behavior, stop and report the conflict.
Return a concise change log and the resulting diff.For reusable prompt and review patterns, the PairFoundry Review and Repair pack is the direct next step. Engineers who want the underlying method before adopting a pack can use the free PairFoundry foundations track.
Stage 4: Verify adversarially#
Verification must ask how the patch can be wrong, not merely whether the happy-path test passes. The agent should inspect the final diff as a reviewer, enumerate untested assumptions, and provide exact evidence without claiming that a command ran when execution was unavailable.
Review the final diff as if you did not write it.
Report:
1. Each changed behavior.
2. Evidence for each behavior.
3. Untested branches and assumptions.
4. Security or credential-scope changes.
5. Compatibility risks.
6. The exact checks run and their results.
7. Anything that still requires human verification.
Do not describe a check as passed unless its output is available.This is where an agent’s fluency becomes dangerous: a polished summary can conceal weak evidence. Require filenames, test names, and observed outputs.
The gate#
The mandatory gate is a human review of the final diff and its evidence before any commit, push, deployment, or credential-scope expansion. The reviewer must be able to reject the patch without undoing external side effects. If the agent can merge its own work, the gate is decorative and the workflow is wrong.
Code review is the systematic examination of source changes by people other than the author; the basic practice and its quality goals are summarized in the code review overview. With an agent, authorship becomes ambiguous, but reviewer responsibility does not.
Stop and inspect five things:
- Scope: Are all changed files named in the approved plan?
- Semantics: Does the diff solve the stated behavior rather than a nearby problem?
- Invariants: Is each repository constraint preserved by code or tests?
- Credentials: Did the patch introduce token access, logging, persistence, or wider permissions?
- Evidence: Do the reported checks correspond to the actual final diff?
Reject generated lockfile churn, unrelated formatting, weakened assertions, and comments that merely repeat code. Also reject secret placeholders that encourage someone to paste a token into tracked configuration.
A clean handoff includes the approved plan, final diff, commands run, unresolved risks, and rollback instructions. More workflow patterns are available in the PairFoundry workflow library, while the PairFoundry packs overview shows the available packaged paths.
Photo by Jakub Zerdzicki on Pexels.
What it gets wrong#
Agents most often fail by producing a locally plausible patch whose permissions, assumptions, or evidence do not match the repository. The dangerous failures are rarely syntax errors. They are changes that look reviewable while quietly broadening scope, bypassing an invariant, or claiming confidence that the available checks cannot support.
Watch for these concrete failure modes:
- Credential conflation: The agent treats Copilot access, GitHub API authentication, and repository permissions as one interchangeable “API key.” Detect it by asking which service accepts the credential and which exact operation requires it.
- Secret material in context: A token appears in a prompt, transcript, fixture, shell history, or generated config. Detect it with secret scanning and direct diff inspection; masking output is not proof that the secret was never persisted.
- Permission drift: The task needs repository reads, but the setup grants write, administration, or workflow access. Compare every granted capability with a required operation.
- Test accommodation: The agent changes an assertion to accept its implementation instead of preserving intended behavior. Inspect test deletions, loosened matchers, and snapshots with large unrelated changes.
- Partial validation: The agent runs a narrow test and summarizes the whole patch as safe. Match every claimed invariant to a specific check.
- Second-engineer failure: The workflow depends on an unnamed local file, personal token, or undocumented approval. Reproduce the handoff from the written configuration alone.
Official product documentation is necessary for supported authentication and features, but it will not encode your repository’s invariants. That missing layer must remain visible in versioned policy, prompts, and review evidence.
Rollback#
Rollback should restore both code and authority. Reverting the diff is insufficient if the workflow also created a token, widened a scope, changed an integration setting, or published a branch. A clean recovery returns the repository and its credentials to the exact pre-change boundary, then verifies that no generated side effect remains.
Use this order:
- Stop the agent and block further writes.
- Preserve the diff and validation output for diagnosis.
- Revert only the task’s approved changes.
- Revoke or rotate any exposed credential.
- Remove newly granted scopes or integration permissions.
- Re-run the pre-change checks.
- Document the failed assumption before retrying.
Do not “fix forward” automatically. When the failure concerns authorization, secret exposure, migrations, or an invariant the agent misunderstood, a second generated patch can compound the damage. Return to the constraint-mapping stage with a narrower boundary.
Photo by Daniil Komov on Pexels.
Related reading#
- Spec-driven development with Claude Code — the workflow, the gate, and the rollback
- Codex CLI changelog, with the guardrails that keep it honest
FAQ#
How do I get a Copilot API key?#
Do not assume Copilot exposes a generic API key that should be copied into an agent configuration. Start with the supported authentication and integration paths in the GitHub Copilot documentation. Identify the precise service and operation first, then grant only the access that operation requires.
Is GitHub Copilot still free?#
Availability and plan terms belong in GitHub’s current product documentation, not in a repository workflow article. Check the official Copilot documentation before making a purchasing or rollout decision. Regardless of plan, access to Copilot does not justify giving an agent broad repository permissions.
Is the GitHub API free to use?#
API availability, authentication, and Copilot entitlement are separate questions. Do not infer one from another. Confirm the applicable GitHub terms and limits in official documentation, then design the integration so credential scope, review gates, and rollback do not depend on a particular billing assumption.
How to get API key for GitHub?#
First name the GitHub capability you need. Repository API access should use GitHub’s supported authentication mechanism, not a made-up “Copilot API key.” Keep credentials outside tracked files, restrict permissions to required operations, and ensure the agent cannot push, merge, or modify settings unless that authority is explicitly necessary.
Why is Copilot shutting down?#
“Shutting down” can describe a product notice, a local agent process, an authentication failure, or an editor integration stopping. Check the exact error and the official Copilot documentation. Do not respond by broadening token permissions; diagnose the failed operation and credential boundary first.