This rewrite started at a PowerShell user group meeting I attended recently, where Frank Lesniak talked about his own repo, PSStyleGuide. It’s a PowerShell style guide written for human developers and AI agents alike, and the Copilot instruction files in it are generated from the guide, with a CI check that rejects a generated file that doesn’t match its source.
The user group was the Pacific PowerShell User Group on November 11. It took all my self-control not to drop a link to my own in their chat and say “Hey, me too, let’s compare right now!”
Afterward I took a hard look at mine. Up to then, my PowerShell standards for AI coding agents were fourteen instruction files I’d written by hand, plus a 33 KB core file that GitHub Copilot loaded on every request. Claude Code read the same files through imports. Codex didn’t read them at all.
Mine was originally created back in June of 2025, specifically for Copilot for GitHub in VS Code. Over time I did update some things for Pester and PowerShell version changes, and again when I started using Claude Code more. There were quite a lot of legacy instruction sets that I never got around to updating. I was a huge fan of how concise the PSStyleGuide was, both from a token perspective and for human readability. Plus his examples for Codex showed me how I’d structure them for that agent, even though I personally don’t use it.
When I went through the files properly, I found the same rule stated in two or three files, sometimes with different details. Some rules contradicted each other. Some described behavior that PowerShell and Pester don’t have. An agent working on one .ps1 file loaded about 123 KB of instructions and had no way to tell which of two conflicting statements applied.
Version 2.0 of ai-powershell-standards fixes that by borrowing the format of Frank’s guide. Every rule is written once, under a standards folder, with an ID and a MUST or SHOULD level. A script generates the files that Copilot, Claude Code and Codex each read. The tests fail when a generated file drifts from its source, when a code sample stops parsing, or when the instructions grow past a size budget. This post walks through the new layout and the generator, and what I found when I made every claim about PowerShell behavior run before it went back in.
If you’re coming from Keeping Copilot Instructions in Sync Across Repositories, the repo has been renamed since then. It started as Powershell-Copilot-Standards and became ai-powershell-standards in September, when Claude Code support went in.
Fourteen files of prose
The old .github/instructions folder had files like analyze, architecturedesign, community-standards, errorsandlogs, securitycompliance and style-enforcement, plus a futureTODO.md that every agent could see. Each one had an applyTo pattern, and VS Code loaded the ones that matched the file you were working on.
For a plain src/Get-Thing.ps1, eight files matched, plus the core:
| File | Bytes |
|---|---|
copilot-instructions.md (core) | 33,355 |
securitycompliance.instructions.md | 30,197 |
powershell-version.instructions.md | 13,857 |
errorsandlogs.instructions.md | 13,261 |
comments.instructions.md | 11,558 |
pull-requests.instructions.md | 7,502 |
community-standards.instructions.md | 5,968 |
analyze.instructions.md | 3,961 |
style-enforcement.instructions.md | 2,870 |
Those nine files come to 122,529 bytes of guidance for one function file, and most of it was prose. A rule like “use $PSCmdlet.ThrowTerminatingError()” might sit in the core, again in errorsandlogs with a slightly different example, and a third time in a template that used throw instead. An agent reading all three gets three answers.
The prose also made review hard. When an agent did something I didn’t like, I couldn’t point at a rule. I could only say “the instructions say somewhere that…” and go looking.
There were prompt files too: ten .prompt.md files under .github/prompts, and the same ten as Claude Code slash commands. VS Code documents that prompt files run only in a chat mode that’s being removed, so those had a shelf life anyway.
Rules that have names
Every rule in 2.0 is a list item that starts with an ID in bold. This is ERR-10 and ERR-11, from the error handling topic:
| |
The prefix belongs to one topic file: STY for style, FUN for functions, ERR for errors, SEC for security, DOC for help, VER for versions, MOD for modules, TST for Pester, PLT for PlatyPS, CIC for CI, RDM for README files and PRQ for pull requests. There are 260 rules across the twelve files today. MUST and MUST NOT are requirements. SHOULD is the default, and an agent departs from it only for a reason it states.
The IDs change how review works. An agent’s review now says “ERR-11: throw in Get-Widget” and I can open the rule, read its reason, and decide. When I disagree with an agent, I can name the rule I think it broke, or find out there isn’t one.
The numbers have gaps. Most topic files start each section at a new ten, so the style rules run STY-01 to STY-08 for layout and STY-10 to STY-16 for naming, and there’s no STY-09. The core lists a selection of rules from the topic files under their own IDs, so it jumps from STY-03 to STY-06. The README and the core both say outright that a gap isn’t a missing rule, and that a rule only in a topic file counts as much as one in the core.
That sentence was added for human readability, if someone went straight to copilot-instructions.md and wondered why the numbers skipped.
The format is Frank’s. I took the parts of his guide I liked and built my rules the same way: requirement keywords, rules short enough to check, reasons kept apart from the rules, and agent files generated from one source. That’s why he’s in the README’s acknowledgments. After the rewrite I compared the two rule sets and took six rules from his as well (STY-07, STY-23, STY-34, STY-35, ERR-32 and VER-10), each tested on 7.6 and 5.1 first. If I were starting a rule set from nothing, I’d look at his repo first.
Recording a departure
A rule set that agents enforce needs a way to say “not here, and I meant it.” DOC-22 is that way. A comment directly above the statement names the rule and the reason:
| |
The core tells an agent to leave a recorded exception alone and never to write one the user hasn’t decided. Test-StandardsCompliance.ps1 drops an excused finding to the severity Information so it doesn’t fail the check. Security rules can’t be excused that way. A SEC finding keeps its severity, and the exception comment gets reported as well.
The standards folder
Everything an agent reads comes from one folder:
The manifest is a PowerShell data file. Each topic entry gives the file, the ID prefix it owns, a description and the globs it applies to:
The pull request rules are the odd one out. They load in every session, because opening a pull request doesn’t always involve reading a file:
To change a rule, edit the file under standards/, run ./Tools/Build-AgentInstructions.ps1, then run ./Tools/Invoke-QualityGate.ps1. Nobody edits a generated file, and every generated file says so at the top.
What the generator writes
Build-AgentInstructions.ps1 reads the manifest and writes the files each agent reads.
For GitHub Copilot, each topic becomes .github/instructions/<Id>.instructions.md with front matter built from the manifest:
The description lands inside a quoted YAML string, so the generator refuses one with a double quote in it. One stray quote would end the YAML string early, and Copilot would skip the file without a word to anyone.
For Claude Code, each topic gets a rule under .claude/rules/powershell-standards/ with paths: in place of applyTo. The rule doesn’t repeat the text. It imports the Copilot file:
A rule whose only glob is ** gets no paths at all, so Claude Code loads it when the session starts:
| |
For Codex, there’s AGENTS.md. Copilot also reads AGENTS.md, so if both files held the core, Copilot would load it twice. Wherever the Copilot file holds the core, AGENTS.md is a short pointer:
| |
The rule IDs double as a signal. An agent that already sees ERR-10 in its context knows the core is loaded. The installer writes the full core into AGENTS.md only when you install for Codex alone, or when your project already has its own copilot-instructions.md.
Each skill is copied into .github/skills, .claude/skills and .agents/skills, one folder for each agent.
The rules and include directives
The core lists IDs where the rule text would go:
The generator replaces that line with the text of each rule, taken from the topic files it has already parsed. A rule exists in one place, and the core can’t drift from the topic file because it never had its own copy. An ID that no topic defines stops the build:
The include directive brings in real files. A line like <!-- include: standards/examples/Get-ConfigValue.ps1 --> is replaced by that file in a code fence:
| |
The function template in the core used to be text I’d typed into a Markdown file. Now it’s Get-ConfigValue.ps1, a real file with its own Pester tests that run on PowerShell 7.6 and Windows PowerShell 5.1. If the template breaks, a test fails before an agent ever copies it. The fence check handles a file that itself contains a Markdown fence, by switching to four backticks.
The generator also parses every rule as it goes, and it refuses a rule whose ID doesn’t match its file’s prefix, and an ID defined twice.
Checking the generated files
-Check runs the whole build without writing anything. It compares what it would write with what’s on disk and fails when a file is out of date, or when a file under a managed location starts with powershell- and nothing produces it any more:
Every comparison converts line endings to LF first. The first version of one content check didn’t, and on the Windows runner, where Git checks files out with CRLF, no code sample matched its own text and a link inside a sample showed up as broken. The repo now has a .gitattributes that checks every text file out with LF, and a rule (CIC-11) asking projects for the same.
The quality gate runs the Pester suite on Windows, Linux and macOS, with a coverage floor of 80 percent. Besides the tools’ own tests, the suite checks that every generated file matches its source, that every PowerShell sample in the instructions parses, that every file the instructions mention exists, and that the repo’s own PowerShell passes Test-StandardsCompliance.ps1.
A budget for what loads
One test adds up what an agent loads for a sample path and fails above a limit:
| |
Another keeps the core at 16,000 bytes or less. It’s 15,453 today, down from 33,355.
The total is a different story. The first cut of 2.0 brought src/Get-Thing.ps1 down from 122,529 bytes to 78,602. Then I went back through the old files and found about 345 cautions and prescriptions that the rewrite had dropped: what help has to contain, code signing, release cautions for the Gallery, the multi-job CI workflow, test cases for performance and security. They came back as rules with IDs. PowerShell 7.7 shipped and added a section to the version rules, and SEC-09 added a tested paging function. The same file now loads 142,148 bytes, more than before the rewrite.
I’m OK with it being a higher size afterward, as there are multiple additions that the original didn’t have.
The difference is what’s in those bytes. Each statement is stated once, has an ID, and was run before it went in. And the budget is a test, so every increase is a decision someone made in a pull request, with the reason in the commit. Every pull request that added to the version rules raised the budget by a stated amount (“The three load budgets rise by 4,000 bytes”) in its description.
Skills in place of prompt files
The ten prompt files became skills. A skill is a folder with a SKILL.md that has a name, a description and a procedure, and all three agents load one when a request matches its description. You can also name one directly, like /powershell-review.
| Before 2.0 | In 2.0 |
|---|---|
new-function.prompt.md | powershell-new-function |
create-module, scaffold-project | powershell-new-module and powershell-ci-pipeline |
create-test | powershell-write-tests |
code-analysis, validate-standards | powershell-review |
security-review | powershell-security-review |
optimize-performance, performance-analysis | powershell-performance-review |
create-workflow | Removed |
powershell-module-help builds help with PlatyPS and came with the rewrite. powershell-logging and powershell-credential-scan arrived afterward and get posts of their own.
Skills can use the include directive too. That came with the logging skill, because I wanted its example function to be the tested file itself.
Installing it in a project
The installer does the work for all three agents:
What each agent gets:
| Agent | Core rules | Topic rules | Skills |
|---|---|---|---|
| GitHub Copilot | .github/copilot-instructions.md | .github/instructions/powershell-*.instructions.md | .github/skills/ |
| Claude Code | A rule that imports the Copilot file | .claude/rules/powershell-standards/ | .claude/skills/ |
| Codex | AGENTS.md | Read on demand from .github/instructions/ | .agents/skills/ |
-Agent limits it to the ones you name. Change that list later and the installer removes what it wrote for an agent you dropped. It never replaces a file your project wrote itself, and it never touches CLAUDE.md. If your project already has its own AGENTS.md, you get a warning naming the line to add so it points at the standards. -WhatIf shows what would change before anything does.
Coming from a version before 2.0, run it once with -RemoveLegacyFiles. Otherwise the old errorsandlogs.instructions.md and its friends stay behind and keep contradicting the new rules. A sync workflow from the earlier post keeps working until you replace it, because the folders it copies still exist.
Your name on new files
The installer also creates .github/powershell-attribution.md: name, company, copyright holder, blog, LinkedIn and Bluesky. Agents write the lines that have a value into the .NOTES of new help and into the Author, CompanyName and Copyright keys of a new manifest (DOC-18). Its first content comes from a profile under standards/attribution/profiles, picked by the GitHub owner of your origin remote, or an empty template.
That file belongs to you. The installer creates it once and never changes it again, -Force included. Everything else it installs is generated and gets replaced on the next update.
Running the claims
The rule I set for the rewrite was that any statement about how PowerShell or Pester behaves gets run first, on PowerShell 7.6 and Windows PowerShell 5.1. Most of the old statements held. A good number didn’t, and the CHANGELOG lists every one that was corrected. A few that surprised me:
Join-Pathwith several child paths was described as new in 7.6. It has worked since PowerShell 6.Test-Json -Options IgnoreComments, AllowTrailingCommasis the real syntax. The old text named switches that don’t exist..Counton a[PSCustomObject]is1on PowerShell 7 and$nullon 5.1. The old text said the two versions agree.- An old sample added
Tls12toSecurityProtocolon every import. When the value isSystemDefault, that restricts the session to TLS 1.2. - A mandatory collection parameter rejects an empty array as well as
$null, so wrapping a call in@()doesn’t help without[AllowEmptyCollection()]. - The
foreachstatement beat the pipeline for a collection in memory: 291 ms against 2,518 ms for 200,000 objects on 7.6 (STY-44). +=on an array still copies the whole array on every append in 7.5 and 7.6. It keeps pace withList.Add()up to about 10,000 elements and is more than ten times slower by 40,000.
The rule applies to the CHANGELOG itself. One fix in that file says the earlier note on Pester 6.0 and 6.1 failing to import on PowerShell 7.4.0 to 7.4.5 had come from a statement nobody ran. Measured on Linux, macOS and Windows, the range is 7.4.0 to 7.4.4.
Some samples didn’t run at all: a deny-list check that a backtick defeated, a secret pattern that didn’t parse, a test runner that didn’t parse, and a signing check that let a file with only critical findings through. The example module’s tests failed 22 times on Linux and macOS, because the CIM commands they mock don’t exist there. The quality gate runs on all three systems now, so that kind of thing shows up in CI.
Trying it on your own projects
ai-powershell-standards is public, and I’d like it used in more places than my own repos. Clone it, run the installer against one of your projects, and see what your agent does with the rules. If something doesn’t work, open an issue and tell me what went wrong: the command you ran, which agent you were using, and what happened.
