powershell-safe
Skill0 starsChanged 3 months agoMITView on GitHub
Use whenever running powershell.exe/pwsh, writing .ps1 scripts, or doing file I/O via shell on Windows. Prevents blanked files, encoding corruption, and accidental deletion: read-modify-write pipeline trap, UTF-16/BOM redirection pitfalls, JSON depth truncation, dangerous aliases, empty-variable deletes, verify-after-write discipline.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- YehudaFrankel/clankbraintheir own version, first seen Apr 16, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- YehudaFrankel/clankbrain★ 16same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository110 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/project-bootstrap/templates/agents.mdAGENTS.md
- a11y-auditSkill
- agentic-ragSkill
- agent-reachSkill
- ai3d-genSkill
- ai-coding-dictionarySkill
- ai-toolsSkill
- animation-directionSkill
- api-specSkill
- architecture-diagramsSkill
- architectureSkill
- ascii-artSkill
- ask-bundleSkill
- binary-triageSkill
- bragSkill
- brag-slimSkill
- career-opsSkill
- code-reviewSkill
- computer-useSkill
- context7Skill
- context-hygieneSkill
- creative-engineeringSkill
- cu-realtimeSkill
- data-analystSkill
- databaseSkill
- dead-wireSkill
- debuggingSkill
- deploySkill
- devin-configSkill
- dispatching-parallel-agentsSkill
- dmaSkill
- dockerSkill
- drift-reportSkill
- e2e-testingSkill
- edge-casesSkill
- executionSkill
- fact-checkSkill
- finishing-a-development-branchSkill
- firmware-probeSkill
- frontend-designSkill
- gatesSkill
- ghidraSkill
- ghSkill
- github-actionsSkill
- git-workflowsSkill
- grillingSkill
- handoffSkill
- humanizerSkill
- hyperframesSkill
- i18nSkill
- image-forensicsSkill
- impeccableSkill
- implement-layaSkill
- intakeSkill
- jiraSkill
- knowledge-modelingSkill
- laya-orchestratorSkill
- learn-modeSkill
- mcp-governanceSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Use write/edit tools to create or edit real files.
- Very specific: line 53
Never pipe .exe output via >: re-encodes to UTF-16.
- Very specific: line 62
Before any write: if ([string]::IsNullOrEmpty($content)) { throw "empty content" }.
- Very specific: line 68
After writing JSON programmatically, validate: Get-Content $f -Raw | ConvertFrom-Json must parse.
- Very specific: line 78
Check path variables: if ([string]::IsNullOrWhiteSpace($p)) { throw }.
- Very specific: line 80
Use -LiteralPath (not -Path) when the path may contain [ ] * ?
- Distinctive: line 125
After writing, read back and confirmed?
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PowerShell Safe
PowerShell footguns silently blank files and corrupt encoding. Targets Windows PowerShell 5.1 (powershell.exe), the default on Windows machines without pwsh.
Rule zero: file content does not go through the shell
Use write/edit tools to create or edit real files. Never:
echo "..." > file.ps1for real files.Set-Content/Out-File/Add-Contentfor code or config.- Redirect (
>,>>) is only acceptable for disposable output (logs, temp dumps).
Redirect re-encodes, may emit BOM, does no surgical diff, and if the left side produces $null the existing file becomes blank.
The classic bug: read and write the same file in one pipeline
Get-Content $f | ForEach-Object { $_ -replace 'a','b' } | Set-Content $f
# RESULT: $f BLANKED. Set-Content opens for write before Get-Content finishes.Equally fatal variants: type $f | ... > $f, Import-Csv $f | ... | Export-Csv $f.
Correct patterns, in order:
# 1. Read fully into memory BEFORE writing
$c = [IO.File]::ReadAllText($f)
$c = $c -replace 'a','b'
[IO.File]::WriteAllText($f, $c) # UTF-8 no BOM
# 2. Temp + move (safer: original survives mid-failure)
$tmp = "$f.tmp"
# ...generate content into $tmp...
if ((Get-Item $tmp).Length -eq 0) { throw "tmp empty, aborting" }
Move-Item -Force $tmp $fEncoding: PS 5.1 silent corruption
>/>>areOut-File: in 5.1 they write UTF-16LE with BOM. Git sees binary, diff dies, parsers break.Out-File -Encoding utf8/Set-Content -Encoding utf8in 5.1 write UTF-8 with BOM. BOM breaks shebang, some JSON/YAML parsers, diff tools.- UTF-8 without BOM in 5.1:
[IO.File]::WriteAllText($path, $text). - Detect BOM:
Get-Content -Encoding Byte -TotalCount 3 $f->239 187 191= UTF-8 BOM;255 254= UTF-16LE. - PS7 (
pwsh) defaults to utf8NoBOM; check$PSVersionTable.PSVersionbefore relying on it. - Never pipe
.exeoutput via>: re-encodes to UTF-16. Capture in a variable +WriteAllText, orcmd /c "foo.exe > out.txt".
$null blanks files
$content = Get-Something # failed, returned $null
$content | Out-File $f # $f is now BLANKBefore any write: if ([string]::IsNullOrEmpty($content)) { throw "empty content" }.
JSON round-trip is destructive
ConvertTo-Jsondefaults-Depth 2: deeper objects become"System.Collections.Hashtable"strings. Always-Depth 32.ConvertFrom-Jsonin 5.1 loses comments and may reorder keys. For point edits, useedittool or surgical regex instead of deserialize->modify->serialize.- After writing JSON programmatically, validate:
Get-Content $f -Raw | ConvertFrom-Jsonmust parse. Test-Jsononly exists in PS7; in 5.1 the try/catch aroundConvertFrom-Jsonis the test.
Destructive ops: Remove-Item, empty variables, -LiteralPath
$p = Get-TargetDir # returned $null or ""
Remove-Item -Recurse -Force "$p\sub" # becomes "\sub" or cwd!- Check path variables:
if ([string]::IsNullOrWhiteSpace($p)) { throw }. Test-Path -LiteralPath $pbefore deleting; if absent, stop.- Use
-LiteralPath(not-Path) when the path may contain[ ] * ?(wildcards delete neighbors). -WhatIffirst on-Recursewhen the target isn't obviously disposable.
Quoting and escapes
- Single quotes = literal; double quotes interpolate
$varand`n(backtick is the PS escape, not\). &&does not exist in PS 5.1. Chain with;orcmd1; if ($LASTEXITCODE -eq 0) { cmd2 }.$?= last cmdlet bool;$LASTEXITCODE= last.exeexit code. Do not mix.- Inside the exec tool (Git Bash),
$is eaten by bash. For anything beyond one line, write a.ps1with thewritetool and runpowershell -NoProfile -ExecutionPolicy Bypass -File x.ps1.
Aliases that lie
| Alias | Actually is | Trap |
curl | Invoke-WebRequest | Not curl.exe: no -k, different output, slow .Content download |
wget | Invoke-WebRequest | same |
sc | Set-Content | sc file x BLANKS the file; sc.exe is services |
iex | Invoke-Expression | never with external input |
rm,ls,cat,cp,mv,echo | PS cmdlets | Unix flags missing or change meaning |
In scripts write full cmdlet names or explicit .exe (curl.exe, sc.exe).
Errors: try/catch catches almost nothing
- try/catch only catches terminating errors. Use
-ErrorAction Stopon critical cmdlets or$ErrorActionPreference = 'Stop'at the top. -NoProfilewhen invoking scripts: user profiles inject unpredictable behavior.
Post-write verification (mandatory)
Get-Item $f | Select-Object Length
Get-Content $f -TotalCount 5
# JSON: Get-Content $f -Raw | ConvertFrom-Json | Out-NullSize 0 or unexpected encoding = stop and investigate. "The command ran without error" is NOT verification.
Checklist before writing/deleting via PowerShell
- Target exists?
Test-Pathdone? - Backup if a real file?
Copy-Item $f "$f.bak". - Content validated (non-null, parses)?
- Explicit correct encoding? (UTF-8 no BOM =
WriteAllText) - Reading and writing the same file? (forbidden in one pipeline)
- Path variable checked non-empty?
-LiteralPath? - After writing, read back and confirmed?
Cascade
edge-cases: what if $var is empty / file missing / BOM present.shell-safe: sibling skill, same class of disaster in bash.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

