TL;DR: Tell Claude Code about your installed commands (rg, fd, jq, etc.) via a user rule file (~/.claude/rules/), and it’ll automatically prefer rg over grep, fd over find, and so on. One prompt does the whole inventory.
Background
Claude Code knows basic UNIX commands like grep, find, and cat, but it doesn’t know whether your machine has rg (ripgrep) or fd installed.
So even though you have faster tools available, Claude Code ends up using grep every time, or runs which rg to check before using it. A bit wasteful, right?
By putting a “here’s what’s installed on this machine” list in a rules file, Claude Code will pick the optimal command from the very start of each session.
One Prompt to Inventory Everything
Just give Claude Code this prompt, and it’ll handle everything from investigating commands to generating the rules file:
Survey UNIX commands on this machine that are particularly useful for agent operations (rg, jq, fd, yq, etc.).
1. For useful but not-yet-installed commands, classify by priority and use AskUserQuestion to ask the user whether to install them or just show the install commands
2. For commands that need installation, wait for the user to install them before continuing
3. Re-survey installed commands, then save the installed commands list and a preferred-alternatives mapping (grep→rg, etc.) to ~/.claude/rules/unix-commands.md in a concise format
Key points:
- Giving examples (
rg, jq, fd, yq) helps Claude Code understand what kind of tools you’re after - Separating steps prevents Claude Code from installing things on its own — you choose what to install
- Requesting a preferred-alternatives mapping ensures replacement rules like
grep→rgare auto-generated - Specifying
~/.claude/rules/ensures the list is automatically applied in all future sessions
For a more casual approach, this shorter version works just as well:
https://php-tips.com/en/2026/03/30/claude-code-unix-commands-rules/
Do a UNIX command inventory based on this article
Why User Rules (~/.claude/rules/)?
UNIX commands depend on your machine’s environment, not on individual projects. Placing the file in user rules (~/.claude/rules/) applies it across all projects, and it won’t affect the repository when team members have different setups.
Conversely, project-specific tools (like php artisan or cake commands) belong in project rules (.claude/rules/).
Example of the Generated Rules File
Here’s what the generated ~/.claude/rules/unix-commands.md looks like (excerpt):
# Unix Commands for Agent Operations
## Installed Commands
### Search & Explore
| Command | Path | Purpose |
|---------|-----------------------|----------------------------|
| `rg` | `/opt/homebrew/bin/rg` | Fast text search (ripgrep) |
| `fd` | `/opt/homebrew/bin/fd` | Fast file finder |
| `tree` | `/opt/homebrew/bin/tree` | Directory tree display |
### Data Processing
| Command | Path | Purpose |
|-----------|---------------------------|------------------------|
| `jq` | `/opt/homebrew/bin/jq` | JSON processor |
| `yq` | `/opt/homebrew/bin/yq` | YAML/XML processor |
| `gron` | `/opt/homebrew/bin/gron` | Make JSON greppable |
| `sqlite3` | `/usr/bin/sqlite3` | SQLite database operations |
The most impactful section is the “Recommended Alternatives”:
## Recommended Alternatives
| Standard | Preferred | Why |
|----------|-----------|--------------------------------------------------|
| `grep` | `rg` | Faster, recursive by default, respects .gitignore |
| `find` | `fd` | Intuitive syntax, faster, respects .gitignore |
| `sed` | `sd` | Literal regex, intuitive syntax |
| `cat` | `bat` | Syntax highlighting, line numbers |
| `curl` | `xh` | Concise syntax, colorized JSON output |
| `du` | `dust` | Visual disk usage display |
With the “Recommended Alternatives” section in place, Claude Code automatically favors modern commands. When it sees grep → rg spelled out explicitly, it won’t reach for grep anymore.
Another quietly significant benefit is that command lines become cleaner and less error-prone. For example, sed replacements require fiddly quoting and flags like sed -i '' 's/old/new/g' file, whereas sd is just sd 'old' 'new' file. The -name and -exec incantations of find also become intuitive syntax with fd. Fewer mistakes in the commands Claude Code generates means fewer do-overs.
The generated rules file was around 800 tokens. If you’re concerned about token consumption, you can use simplify to make it more compact.
/simplify ~/.claude/rules/unix-commands.md
In my case, it shrank to about 250 tokens.
Aside
When I ran the prompt myself, I discovered quite a few tools I’d never heard of.
ast-grep can parse and search/replace code based on its syntax tree, making refactoring safer than plain text search.
gron converts JSON into a grep-friendly flat format — a handy alternative approach to jq.
It’s nice to have Claude Code introduce you to tools you didn’t know existed.