ScriptsApr 15, 2026·2 min read

McFly — Fly Through Your Shell History with Context-Aware Search

McFly replaces the default Ctrl-R reverse search in bash/zsh/fish with a neural-ranked, context-aware history finder that considers directory, exit status, and recency.

TL;DR
McFly ranks shell history results by directory, exit status, and recency for smarter Ctrl-R search.
§01

What it is

McFly replaces the default Ctrl-R reverse history search in bash, zsh, and fish with a context-aware, neural-ranked search. Instead of simple substring matching, McFly considers your current working directory, the exit status of previous commands, the time of day, and how recently you used each command to rank results.

McFly is for developers and sysadmins who run many commands across multiple projects and want their shell history to surface the right command in the right context.

The project is actively maintained with regular releases and a growing user community. Documentation covers common use cases, and the open-source nature means you can inspect the source code, contribute fixes, and adapt the tool to your specific requirements.

§02

How it saves time or tokens

Default shell history search shows the most recent match regardless of context. If you run git push in 20 different repositories, Ctrl-R always shows the last one. McFly ranks the git push from your current directory higher because it understands context. This eliminates scrolling through irrelevant matches and reduces typo-driven re-runs.

§03

How to use

  1. Install McFly via brew, cargo, or your package manager.
  2. Add the shell integration to your profile (bash, zsh, or fish).
  3. Press Ctrl-R to search with McFly instead of the default history search.
§04

Example

# Install McFly
brew install mcfly

# Add to .zshrc
eval "$(mcfly init zsh)"

# Add to .bashrc
eval "$(mcfly init bash)"

# Add to fish config
mcfly init fish | source

# Usage: press Ctrl-R and start typing
# McFly ranks results by:
# - Current directory context
# - Command exit status (successful commands rank higher)
# - Recency and frequency
# - Time of day patterns
§05

Related on TokRepo

§06

Common pitfalls

  • McFly stores its database in ~/.mcfly/. If you use multiple machines, history is not shared automatically. Each machine maintains its own context database.
  • The initial history import from .bash_history or .zsh_history lacks context metadata (directory, exit status). Context-aware ranking improves over time as McFly records new commands.
  • McFly intercepts Ctrl-R. If you prefer the default behavior in some sessions, set MCFLY_DISABLE=1 before sourcing the init script.

Before adopting this tool, evaluate whether it fits your team's existing workflow. Read the official documentation thoroughly, and start with a small proof-of-concept rather than a full migration. Community forums, GitHub issues, and Stack Overflow are valuable resources when you encounter edge cases not covered in the documentation.

Frequently Asked Questions

How does McFly rank search results?+

McFly uses a small neural network trained on your shell usage patterns. It considers the current working directory, command exit status (preferring successful commands), recency, frequency, and time-of-day patterns to rank results.

Which shells does McFly support?+

McFly supports bash, zsh, and fish. Each shell has a dedicated init command that sets up the Ctrl-R keybinding and command tracking.

Does McFly replace my shell history file?+

No. McFly maintains its own SQLite database alongside your regular shell history. Your .bash_history or .zsh_history file is not modified. McFly imports existing history on first run.

Can I delete sensitive commands from McFly?+

Yes. Use mcfly search to find commands and delete them from the McFly database. You can also set MCFLY_HISTORY_LIMIT to cap the number of stored commands.

Is McFly written in Rust?+

Yes. McFly is written in Rust, which gives it fast startup time and low memory usage. The neural ranking model is lightweight and runs in milliseconds.

Citations (3)
  • McFly GitHub— McFly is a context-aware shell history search tool
  • McFly README— Neural-ranked results considering directory, exit status, and recency
  • Rust Language— Rust-based CLI tool design

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets