DEV Community

Yunus Emre Ak
Yunus Emre Ak

Posted on • Originally published at yedhrab.com

TIL: AI keeps using rm -rf on important files. Changed rm to trash

r/ClaudeAIr/ClaudeCode

Was pair programming with AI. It deleted my configs twice.

First thought: Add confirmation prompts
Reality: I kept hitting yes without reading

Second thought: Restrict permissions
Reality: Too annoying for daily work

Final decision: alias rm='trash'

Now AI can rm -rf all day. Files go to trash, not void.

Command for macOS:

alias rm='trash'
Enter fullscreen mode Exit fullscreen mode

Add to ~/.zshrc to make permanent.


edit: Here is an another alternative

rm() {
    echo "WARNING: rm → trash (safer alternative)" >&2
    trash "$@"
}
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
aaron_1 profile image
Aaron

I created a more complicated version of this. It only intercepts rm from AI tools, so if you run rm yourself it still deletes normally by default (it's a setting). github.com/forethought-studio/ai-t...