tmux tip: Add file paths to context with fzf in Claude Code
One of the killer features in tmux is the floating popup window. This enables
all kinds of interesting workflows, because with a mapping of your choice, you
can spawn any process in a floating window on top of your panes. This process
will inherit the current pane's working directory, has all the tmux APIs etc. at
its disposal, so all kinds of cool things are possible.
Over a year ago, when I was still using Aider and suffering from its
clunky file path autocomplete, I
got the idea
of combining tmux popups with fzf. The basic idea is that you launch
fzf in a popup that filters through files in your current working directory.
You can select one or more files, and the selected files are inserted into the
pane that invoked the tool, each prefixed with the @ symbol as is customary in
AI terminal UI apps.
I've since packaged this and a few other file/directory picking related
workflows under a single command-line tool called
tmux-file-picker.
You can find the installation instructions in the README. For now, I'll cover some of my favorite workflows and the related configuration.
#Workflows
#Just pick some files in the current directory
bind C-f display-popup -E "tmux-file-picker"
This is the most basic workflow covered above and shown in the demo. The bind
makes it so that pressing prefix (Ctrl-b by default) +
Ctrl-f launches tmux-file-picker in a tmux popup.
#Pick directories in the current directory
bind C-r display-popup -E "tmux-file-picker -d"
With -d, it opens a fzf that filters directories in the current repository.
This is sometimes useful when you want to point the agent to some directory but
not a specific file.
#Pick recently accessed directories or files
bind C-z display-popup -E "tmux-file-picker --zoxide"
bind C-d display-popup -E "tmux-file-picker --zoxide --dir-only"
A recent addition is that the tool integrates with
zoxide, which allows filtering
through recently accessed directories. With --zoxide, you are presented with a
two-step flow, where the tool first prompts to filter through directories, and
upon selection, a second fuzzy-finder is invoked where files in that directory
are shown. I've come to really like this one, because I very often tell agents
to refer to some configuration etc. in other projects.
Hope any tmux users out there find this useful. To me, this nicely illustrates the power of terminal composability. A popup, a fuzzy finder, and a few lines of config solve a problem that might otherwise require a complex plugin ecosystem in a GUI app.
For another although still work in progress tool that also uses tmux popups, check out: tmux-snaglord