Patrick Decatandtaylor.fish fd95859eb5 perf(daemon): update the search index in place on delete (atuinsh/atuin#4743)
Supersedes atuinsh/atuin#4407, which I closed. It's the same fix, rebuilt on top of the search index rework from atuinsh/atuin#4586 and atuinsh/atuin#4730.

Since atuinsh/atuin#4045, deleting an entry from the inspector or with `atuin search --delete` waits for the daemon to rebuild its whole search index before it replies. On my history, about 370k rows and 150k unique commands, that still takes 1.8 to 2.1s per delete with a release build of current main.

This updates the index in place instead. Before deleting the rows, the daemon reads which commands the deleted ids belong to. Afterwards it streams the runs that those commands have left with the new `Sqlite::history_of_command`. Then `SearchIndex::sync_commands` rebuilds just those commands and removes the ones with no runs left. `CommandData` only keeps aggregates, so a command is rebuilt from its remaining runs rather than having one run subtracted.

The update holds a new `SyncPermit` from `SharedSearchIndex::begin_sync`. The permit takes the add lock for writing, so no run can be added between the reads and the update. It is refused while a rebuild is pending or the startup fill is running, because their loads may already hold the deleted runs. It is also refused when the rebuild would change the settings. Those deletes still do the full rebuild, and so do bulk deletes over 10k ids or 100 commands and read errors. A sync also drops the cached session preload. `num_total` became `changes`, so a session-preload search that began before a sync doesn't cache a stale result.

Deleting a test entry with `atuin search --delete` on a copy of that history, release builds:

- current main: 1.8 to 2.1s
- this branch: about 180ms

New tests compare `sync_commands` with a fresh load of the remaining rows. Others cover when `begin_sync` refuses, syncs and adds taking turns, the session preload across a sync, and both delete paths end to end. `cargo test -p atuin-daemon -p atuin-client` and clippy pass on 1.98.

## Checks
- [x] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle
- [x] I have checked that there are no existing pull requests for the same thing

<!-- atuin-pr-template-necessary-for-ci: v2 -->

Co-authored-by: taylor.fish <contact@taylor.fish>
2026-11-17 01:40:09 +00:00
2021-04-14 17:40:50 +00:00
2021-05-14 08:31:15 +01:00
2022-03-17 21:43:54 +00:00
2026-07-23 23:41:06 +00:00
2021-05-10 21:28:07 +01:00

Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'

making your terminal magical


Atuin gives you, and your agents, a history of everything that happened in your terminal.

Shell history Atuin replaces your shell history with a SQLite database that records exit codes, working directories, hosts and durations. Hit Ctrlr and find any command you've ever run, on any machine.

Agent Threads Atuin captures your Claude Code, Codex, OpenCode and other agent sessions. Start a thread on your laptop, then atuin resume it on a different machine, in a different harness.

Your agents can, optionally, search everything that's ever happened through the built-in MCP server.

Atuin can also sync both history and threads across all of your machines, end-to-end encrypted. Or it can work totally offline!

Quick Start

curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh

Then, restart your shell.

History

Atuin captures everything you do in the terminal, storing it into a SQLite database. Hitting CTRLr opens a pretty pane with all your bash history. Atuin logs your exit codes, working directories, hostnames, command duration and much much more. You can hit Return to execute a command, Tab to edit any highlighted command.

Searching shell history with ctrl-r, then picking a match

Agents can search your history too:

Claude Code finding a command from your shell history through Atuin's MCP server

As well as the search UI, atuin has a CLI interface for searching commands:

# search for all successful `make` commands, recorded after 3pm yesterday
atuin search --exit 0 --after "yesterday 3pm" make

Threads

Atuin captures what your agents do. Automatically move your context and thread history from one machine to another, or from one harness to another.

With Atuin Threads, your agent has access to your full history, and the built-in Atuin MCP gives your agent context on everything you've ever done.

Claude Code recalling a decision from last week's Codex thread through Atuin's MCP server

You can take a session you started on your personal computer in Claude Code, and $ atuin resume it in a remote machine inside Codex.

A Claude Code thread on a laptop, resumed in Codex over ssh on another machine

Similarly to the history index, you can search through your threads:

atuin threads search 'c++'

Sync

Atuin syncs all your AI threads, your shell sessions across all your computers (even ephemeral VMs!). You can either use the official Atuin Service or you can self-host the sync server. Everything it syncs is end-to-end encrypted.

Atuin supports zsh, bash, fish, nushell, xonsh and PowerShell as well as Claude Code, Codex, Opencode, Copilot, Grok, Hermes, and many more.

Atuin does so much more and we have extensive documentation! If you ever need help, reach out to us through our communities.

Please open a PR for any others!

Community

Contributors

We are very grateful to all our contributors!

Made with contrib.rocks.

Languages
Rust 97.6%
Shell 1.2%
Fluent 0.4%
Nix 0.2%
TypeScript 0.2%
Other 0.2%