Filters and Context
Outcome: you can ask the database
questions with edges — in this folder,
this session only, the ones that
failed, before Tuesday — and get
exactly the rows that fit. Check: every
command below is in transcript
t04-search.txt, run against the lab's
database of 22 imported and 13 live
commands.
A search query matches the text of commands. Filters match the facts recorded alongside the text (chapter 4): directory, session, host, exit code, date. The two compose: query and filters together.
Scope: the filter modes
Atuin names six scopes, and they work
identically in the interactive window
(chapter 6, where Ctrl-R cycles them)
and on the command line, as
--filter-mode:
- global — everything in the database. The default.
- host — commands run on this machine. On a synced multi-machine database (chapter 11) this stops being everything; in the lab it changed nothing, which is itself a fact about a one-machine life.
- session — commands from the current shell session only.
- directory — commands run in the current working directory.
- workspace — commands run anywhere
inside the current Git repository's
tree; the directory scope with a
wider, project-shaped net. The lab
proved this one against a two-folder
repository: from
lists/, workspace returned the commands run innotes/too, where directory returned only its own folder's (transcriptt12-workspace.txt). - session-preload — a variant of
session used by the up-arrow binding;
named here so the word never surprises
you in a
--helplisting.
The lab asked for its live session's commands and got the chapter-4 session back, deduplicated, newest first:
$ atuin search --filter-mode session --cmd-only
mkdir -p ~/projects/garden-notes
cd ~/projects/garden-notes
echo "water the tomatoes on Friday" > todo.txt
cat todo.txt
sleep 2
grep -rin tomato .
ls /no/such/place
false
python3 --version
cd ~
tar czf garden-notes-backup.tgz projects/garden-notes
atuin history list --format "{time} | exit {exit} | {duration} | {directory} | {command}" | tail -13
And from inside the garden-notes folder, the directory scope:
$ cd …/projects/garden-notes && atuin search --filter-mode directory --cmd-only
echo "water the tomatoes on Friday" > todo.txt
cat todo.txt
sleep 2
grep -rin tomato .
ls /no/such/place
false
python3 --version
cd ~
Note the last line: cd ~ belongs to
the folder — it was run from there, on
its way out. Filters judge a command by
where it started, which is the only
sensible rule.
Directory by hand
--cwd <dir> asks for any folder
without travelling to it, and
--exclude-cwd <dir> removes one:
$ atuin search --cwd /home/…/projects/garden-notes --cmd-only
printed the same eight commands as the directory scope above. In your own history these two are how you ask what do I usually do in the deploy folder? without going there.
Exit codes: asking for failures
--exit N keeps only commands that
ended with code N, and it repeats —
--exit 1 --exit 2 keeps either:
$ atuin search --exit 2 --format "{time} | exit {exit} | {directory} | {command}"
2026-10-28 11:37:08 | exit 2 | …/projects/garden-notes | ls /no/such/place
$ atuin search --exit 1 --exit 2 --cmd-only
ls /no/such/place
false
--exclude-exit 0 is the blunter
instrument — everything that was not a
clean success. Use it knowing chapter
4's caveat: imported rows carry exit
−1, unknown, so an exclude-the-zeros
search over a freshly imported history
returns the whole imported past wearing
a guilty look it has not earned.
Filter imported and live facts with
that in mind, or bound the search by
date at the same time.
Dates
--before and --after take dates and
phrases (2026-10-10, yesterday 3pm)
and compose with everything above:
$ atuin search --before 2026-10-10 --cmd-only | wc -l
12
Twelve of the lab's rows predate
10 October — all of them imports, since
the lab's live session happened on the
28th. On a real machine this pair is
how you rebuild what did I do last
Tuesday, in this folder, that worked:
date, directory, --exclude-exit
pointed the other way — a question
plain ~/.bash_history cannot even be
asked.