Safe rm

From aspiers/ai-config · View interactive version

Safe rm is an AI agent skill from the GitHub repository aspiers/ai-config. Deletes files and directories through a wrapper that avoids the usual per- command permission prompt. Use only when content must genuinely be deleted, such as clearing build artifacts or dropping obsolete files during a refactor. Moves, renames, and relocations that preserve content use mv instead.

How to use this skill

Skill file

Safe File Deletion

When to use this skill

Use this skill only when files or directories must genuinely be deleted. Do

not use it to move, rename, or relocate content that should remain; use mv

instead.

This skill is particularly useful when:

How it works

It runs the ai-safe-rm script which has an intelligent git-aware backup

strategy. Use -r flag for directories.

Behavior

For files:

  1. Tracked in git, unmodified: Files are deleted directly (can be

recovered from git)

  1. Tracked in git, modified: Files are moved to

.safe-rm/<path>/<filename>.<hash>.<ext> (e.g., README.b72ae922.md)

or .safe-rm/<path>/<filename>.<hash> (e.g., LICENSE.88fdc130) to

preserve the modified version

  1. Not tracked in git: Files are moved to

.safe-rm/<path>/<filename>.<hash>.<ext> or .safe-rm/<path>/<filename>.<hash>

for safety

For directories (requires -r flag):

  1. All files unmodified tracked: Directory is deleted directly with

rm -rf (can be recovered from git)

  1. Contains modified tracked or untracked files: The script recurses

through the directory, applying the file logic to each file

individually. Only modified/untracked files are backed up, while

unmodified tracked files are deleted. Empty directories are removed

after processing.

The <hash> is the first 8 characters of the MD5 sum of the file

content, ensuring unique backups of different versions.

Limitations

Only use this skill for files/directories within the current git repository.

For files outside the repository:

Pre-check before calling:

Before running ai-safe-rm, verify all paths are within the repo:

# Verify path is inside current repo
git rev-parse --is-inside-work-tree && realpath --relative-to="$(git rev-parse --show-toplevel)" /path/to/file | grep -q '^[^.]' && echo "Inside repo" || echo "Outside repo"

Usage

When you need to delete files or directories as part of a refactoring or

cleanup task:

  1. Identify the files/directories to delete
  1. Call ai-safe-rm [-r] <file1> <file2> ... to safely remove them
  1. The script will output what action was taken for each file/directory

Important Notes

Examples

All examples assume files are within the current git repository:

# Delete a single file
ai-safe-rm src/old-component.ts

# Delete multiple files
ai-safe-rm src/legacy/*.js

# Delete a directory
ai-safe-rm -r ./old-feature

# Delete multiple directories and files
ai-safe-rm -r ./tests/deprecated ./legacy src/unused.ts

For files outside the repository, use rm directly:

# Delete file outside repo
rm /home/user/.cache/temp-file.txt

# Delete directory outside repo
rm -rf /tmp/build-artifacts/
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.