charmbracelet/crush · warning

no data available: no sessions found in database

Error message

no data available: no sessions found in database

What it means

runStats returns this hard-coded error when project databases were found and merged, but mergedStats.Total.TotalSessions == 0 — i.e. the database(s) exist yet contain no sessions. It distinguishes an empty-but-valid database from the no-projects case.

Source

Thrown at internal/cmd/stats.go:194

		defer conn.Close()

		stats, err := gatherStats(ctx, conn)
		if err != nil {
			return fmt.Errorf("failed to gather stats: %w", err)
		}

		projectStats = []ProjectStats{{ProjectPath: "", Stats: stats}}
	}

	if len(projectStats) == 0 {
		return fmt.Errorf("no data available: no projects found")
	}

	// Merge stats from all projects.
	mergedStats := mergeStats(projectStats)

	if mergedStats.Total.TotalSessions == 0 {
		return fmt.Errorf("no data available: no sessions found in database")
	}

	currentUser, err := user.Current()
	if err != nil {
		return fmt.Errorf("failed to get current user: %w", err)
	}
	username := currentUser.Username

	var projName string
	switch {
	case crawlDir != "":
		projName = crawlDir
	case useAll:
		projName = "all projects"
	default:
		project, err := os.Getwd()
		if err != nil {
			return fmt.Errorf("failed to get current directory: %w", err)

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Use crush to start a session (chat once) so data is recorded, then rerun stats.
  2. Check the sessions table directly: sqlite3 <dataDir>/crush.db 'SELECT COUNT(*) FROM sessions;' to confirm it is empty.
  3. If you expect data, verify you are pointing at the correct data dir (HOME/XDG_DATA_HOME overrides) and correct --crawl-dir/--all targets.
  4. If sessions were deleted intentionally, accept the message or remove the empty db so fresh history accumulates.

Example fix

// before
XDG_DATA_HOME=/tmp crush stats   # looks at an empty data dir
// after
crush stats                       # uses the real data dir with recorded sessions
Defensive patterns

Strategy: validation

Validate before calling

n, err := queryCount(conn, "SELECT COUNT(*) FROM sessions")
if err != nil {
	return err
}
if n == 0 {
	return fmt.Errorf("skipping stats: database has no sessions yet")
}

Prevention

When it happens

Trigger: Running `crush stats` (or --all/--crawl-dir) against data dirs where crush.db exists but the sessions table is empty — fresh installs, databases wiped/reset, crawl dirs containing only initialized crush projects with no conversations; also after manually deleting session rows or restoring an empty db.

Common situations: New machine or new project where crush was opened but never used; user cleared ~/.local/share/crush/crush.db to fix a problem and then ran stats; crawl-dir matching dotfile/build dirs containing stray empty crush.db files.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/0ccd6a55b8fa3619. Report an issue: GitHub.