Have you ever suffered from the reckless decisions of AI coding assistants? They always tend to swing between two extremes.
User: "Help me design feature XX."
AI: "Sure, I'll do that right away." (makes edits)
User: "Great, now add feature YY."
AI: "No problem!" (edits again, messing up previous logic)
User: "Actually, this is worse than before."
AI:
git checkout .(wipes out all uncommitted changes, including your own precious manual modifications)User: "WHAT?!"
Taking Git version management as an example, dealing with AI assistants can be a painful dilemma:
- Either they never use Git to back up versions, letting important local changes disappear silently during massive AI rewrites;
- Or they abuse tools, executing commands like
git checkout .orgit restoreas if they were toys, with zero regard for safety.
Sometimes, this leads to catastrophic consequences!
If we grant AI agents full terminal access, we live in constant fear of their recklessness, bearing the risk of data loss. If we deny them terminal access entirely, our development and collaboration productivity drops significantly.
It feels like always increasing the system variance while dragging down the expected return. Since these risks are caused by a few high-risk instructions, let's lock those risk-prone commands!
BlockCommand is a lightweight PowerShell Command Interceptor designed for Windows.
By injecting a secure wrapper function into your PowerShell $PROFILE, it proxies and monitors specific commands and subcommands.
By default, when an AI agent runs a risky command (e.g., git checkout or git restore), the wrapper intercepts the process and denies execution immediately unless the authentication parameter is provided:
- User: "Discard my local modifications."
- AI:
git checkout . - PowerShell Interceptor:
need Agree(by UserAgree=[YOUR_PASSWORD])(aborted) - AI: "This command requires authorization. Could you please provide the permission password?"
- User: "The password is XXX."
- AI:
git checkout . UserAgree=XXX - PowerShell Interceptor: (Validates, strips the token, runs original
git checkout .) -> Success!
For detailed information on configuring authentication modes (Interactive vs Parameterized) or custom parameter names, and providing instructions for AI agents, please refer to: 👉 Advanced Configuration & AI Guidelines
Download setup.ps1 from this repository.
Double-click setup.ps1 or run it in your PowerShell terminal:
./setup.ps1- Enter your desired validation password when prompted during setup.
- By default, it intercepts
git checkoutandgit restore. - You can configure additional rules (such as
git reset --hardorrm) by editing the configuration hash table at the top of the script:
$INTERCEPT_RULES = @{
"git" = @{
"subs" = @("checkout", "restore");
"warn" = "need user agree"
}
}To completely remove the interception policy, simply run the script again and type uninstall.
Share this with friends who are also co-piloting with AI! If this tool saves your code from AI accidents, please give us a Star 🌟!
I am more than happy to design customized blocking scripts and rules based on your scenarios and feedback.