Ollama Chat History Cleaner

Ollama chat history cleaner

I made these scripts to clean only the chat history and the logs from Ollama GUI and server. It does not remove models, users, or app settings.

Motivation: Not only me — see issues in ollama#13926 and ollama#15099

Scripts are available for macOS, Linux, and Windows.

On macOS and Windows it checks common Ollama database paths automatically. It also checks if sqlite3 is installed and if the needed tables exist.

When you run it, it asks if you want a backup. Default answer is No.

Before and after

Before running the script:

Before

After running the script:

After

macOS and Linux

Install sqlite3

macOS:

brew install sqlite

Debian / Ubuntu:

sudo apt update && sudo apt install -y sqlite3

Fedora:

sudo dnf install -y sqlite

Arch:

sudo pacman -S sqlite

How to run

chmod +x ./ollama_chat_deleter.sh
./ollama_chat_deleter.sh

If your DB is in another place, pass it like this:

OLLAMA_DB="/full/path/to/db.sqlite" ./ollama_chat_deleter.sh

If you do not want the backup question, you can force it:

OLLAMA_BACKUP=no ./ollama_chat_deleter.sh

or:

OLLAMA_BACKUP=yes ./ollama_chat_deleter.sh

Delete Ollama logs

chmod +x ./ollama_logs_deleter.sh
./ollama_logs_deleter.sh

By default it uses:

$HOME/.ollama/logs

Before deleting, it prints all files/directories that will be removed and asks:

Delete all items above? [y/N]:

Only y or yes will continue. Any other answer cancels the delete.

If your logs path is different, use:

OLLAMA_LOG_DIR="/full/path/to/logs" ./ollama_logs_deleter.sh

Windows

Install sqlite3

Option 1 — winget (recommended):

Open PowerShell and run:

winget install SQLite.SQLite

Tip: If winget fails with a certificate error (0x8A15005E), run these two commands first:

winget settings --enable BypassCertificatePinningForMicrosoftStore
winget upgrade Microsoft.AppInstaller --accept-source-agreements --accept-package-agreements

Then retry winget install SQLite.SQLite.

winget install SQLite

After install, winget places sqlite3.exe inside %LOCALAPPDATA%\Microsoft\WinGet\Packages\ but does not add it to your PATH automatically. Fix it:

  1. Find the exact path:
Get-ChildItem "$env:LOCALAPPDATA\Microsoft\WinGet\Packages" -Recurse -Filter "sqlite3.exe" | Select-Object FullName
  1. Add the folder to your user PATH (replace the path with what the command above returned):
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\<YOU>\AppData\Local\Microsoft\WinGet\Packages\SQLite.SQLite_Microsoft.Winget.Source_8wekyb3d8bbwe", [EnvironmentVariableTarget]::User)
  1. Close and reopen PowerShell, then verify:
sqlite3 --version

Option 2 — manual:

  1. Go to https://sqlite.org/download.html
  2. Under Precompiled Binaries for Windows, download sqlite-tools-win-x64-*.zip
  3. Extract sqlite3.exe to a folder like C:\tools\sqlite3\
  4. Add that folder to your PATH:
    • Open Start → search Environment Variables
    • Edit Path under User variables
    • Add the folder path and click OK
  5. Reopen PowerShell and verify: sqlite3 --version

Allow PowerShell scripts to run

Windows blocks unsigned scripts by default. Run this once to allow local scripts:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Or, to bypass for a single run without changing policy:

powershell -ExecutionPolicy Bypass -File .\ollama_chat_deleter.ps1

How to run

.\ollama_chat_deleter.ps1

Running the script on Windows

Note: The script stops Ollama before wiping the database and waits for all Ollama processes (including the tray app) to exit before proceeding. If the -wal or -shm sidecar files cannot be removed because another process still holds them, a warning is printed but the chat deletion has already succeeded — SQLite cleans those files automatically on the next open.

The script looks for the database in these locations and uses the first one it finds:

  • %APPDATA%\Ollama\db.sqlite
  • %LOCALAPPDATA%\Ollama\db.sqlite

If your DB is somewhere else:

$env:OLLAMA_DB = "C:\full\path\to\db.sqlite"
.\ollama_chat_deleter.ps1

To skip the backup prompt:

$env:OLLAMA_BACKUP = "no"
.\ollama_chat_deleter.ps1

or:

$env:OLLAMA_BACKUP = "yes"
.\ollama_chat_deleter.ps1

Before and after (Windows)

Before:

Before (Windows)

After:

After (Windows)

Delete Ollama logs (Windows)

.\ollama_logs_deleter.ps1

By default it uses:

%USERPROFILE%\.ollama\logs

If your logs path is different:

$env:OLLAMA_LOG_DIR = "C:\custom\log\path"
.\ollama_logs_deleter.ps1

Note: Right now these are more involved than I would like, but I don’t have the knowledge to make this into a multiplatform app.


Enjoy!