| name | session-history |
| description | Use when user asks about past sessions, worklog, accumulated hours, "quanto trabalhei hoje", "worklog do dia", "histórico de sessões", "horas trabalhadas", "session history", or wants to review time spent on projects across sessions. |
Session History
Reports aggregated Claude Code session history via the session-query CLI, which reads the SQLite store written by the SessionEnd hook (with a JSON-lines fallback when sqlite3 is unavailable).
Mechanism
Each time a session ends, the SessionEnd hook upserts one row into the SQLite database at $HOME/.claude/session-env/history.db — one row per session_id in the sessions table (joined to projects for the canonical, worktree-grouped project), plus that session's heartbeats in events. Because the write is an upsert keyed on session_id, a session that ends repeatedly (e.g. across resume) stays a single row — totals are not double-counted. When sqlite3 is absent the hook falls back to appending one JSON line to $HOME/.claude/session-env/history.jsonl, which the next session imports.
Each session row carries active_seconds (working time — what the table and totals report), duration_seconds (wall-clock, available on request), branch, and issue_key.
The current (still running) session is NOT in the store — only completed sessions are. If the user also wants the live elapsed time, combine with session-tracker:session-status.
Usage
Call session-query, then render its JSON. The CLI owns the SQLite-vs-JSONL guard and the SQL/jq queries — no inline SQL needed here.
Table + total