Skip to content
Open Sourceen
shellmemory

A terminal command logger that records every command across your shell sessions directly into a SQLite database.

What is shellmemory?

shellmemory is a shell hook that silently records every command you run — across all your terminal sessions — into a local SQLite database. It's persistent, searchable shell history that lives beyond your shell's built-in HISTFILE.

Your commands are timestamped, tagged with the working directory, and queryable with SQL or a built-in search command. Nothing is sent anywhere. It's all local.

The Problem It Solves

Shell history is fragile. By default, most shells keep a flat text file with a limited line count. History gets truncated, overwritten when multiple sessions close in parallel, or simply lost when you switch machines.

shellmemory trades the text file for a proper database: every command, from every session, preserved indefinitely and queryable without learning new tools.

Core Features

Automatic capture

Install the hook once and every command is logged automatically. No manual invocation needed.

# Hook fires after every command
PROMPT_COMMAND="shellmemory log"  # bash
precmd() { shellmemory log }     # zsh

Per-entry metadata

Each recorded command includes:

FieldDescription
commandThe full command string
timestampISO 8601 datetime
exit_codeReturn code of the command
cwdWorking directory at time of execution
session_idUUID per terminal session
hostnameMachine hostname
shellmemory search "docker"          # full-text search
shellmemory search --dir ~/projects  # filter by directory
shellmemory search --failed          # only failed commands (exit_code != 0)
shellmemory search --since "7 days"  # time-bounded search

Export and statistics

shellmemory stats                    # summary: total commands, top commands
shellmemory export --format csv      # export to CSV
shellmemory export --format json     # export to JSON

Installation

# Clone and source the hook
git clone https://github.com/fernandobelotto/shellmemory ~/.shellmemory
echo 'source ~/.shellmemory/shellmemory.sh' >> ~/.bashrc  # or .zshrc

shellmemory requires sqlite3 to be available on your PATH.

Tech Stack

  • Shell (Bash/Zsh compatible) — the hook and CLI are pure shell scripts
  • SQLite — embedded database, zero dependencies beyond the sqlite3 binary
  • Schema migrations run automatically on first use

Design Philosophy

shellmemory is intentionally minimal. It doesn't try to be a full shell replacement or a cloud sync tool. It captures commands locally, stores them in a format you can query with any SQL tool, and gets out of the way. The database file is yours — back it up, query it with DBeaver, pipe it through jq, do whatever you want with it.