Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BlockCommand - Terminal Shield Guarding Against Risky AI Commands

Have you ever suffered from the reckless decisions of AI coding assistants? They always tend to swing between two extremes.

🎭 A Familiar Drama

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 . or git restore as 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!


🚀 How It Works

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:

🎭 AI & User Collaboration Flow

  1. User: "Discard my local modifications."
  2. AI: git checkout .
  3. PowerShell Interceptor: need Agree(by UserAgree=[YOUR_PASSWORD]) (aborted)
  4. AI: "This command requires authorization. Could you please provide the permission password?"
  5. User: "The password is XXX."
  6. AI: git checkout . UserAgree=XXX
  7. PowerShell Interceptor: (Validates, strips the token, runs original git checkout .) -> Success!

🛠️ Advanced Settings & AI Guidelines

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


📦 Getting Started

1. Download the Script

Download setup.ps1 from this repository.

2. Run the Installer

Double-click setup.ps1 or run it in your PowerShell terminal:

./setup.ps1

3. Setup Your Password & Rules

  • Enter your desired validation password when prompted during setup.
  • By default, it intercepts git checkout and git restore.
  • You can configure additional rules (such as git reset --hard or rm) by editing the configuration hash table at the top of the script:
$INTERCEPT_RULES = @{
    "git" = @{
        "subs" = @("checkout", "restore");
        "warn" = "need user agree"
    }
}

4. Uninstall

To completely remove the interception policy, simply run the script again and type uninstall.


⭐ Support & Star

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.

About

🛡️Stop 🤖AI from ⚠️abusing ⚡risky 💻commands like 'git checkout'! A 🪶lightweight 🐚PowerShell 🛡️shield guarding against 💥catastrophic 🤖AI ⚙️actions with 💎clean, 🔑parameterized 📝authorization.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages