Hermes session maintenance

From AtlasOmnia/hermes-custom-pack · View interactive version

Hermes session maintenance is an AI agent skill from the GitHub repository AtlasOmnia/hermes-custom-pack. hermes-session-maintenance — Maintain Hermes Agent session history: inspect size, export backups, prune old ended sessions, and configure safe auto-prune retention.

How to use this skill

Skill file

Hermes Session Maintenance

Use this skill when the user asks about pruning Hermes sessions, session retention, session DB size, hermes sessions prune, sessions.auto_prune, sessions.retention_days, session export/backup, or whether old conversations should be capped.

Operating principles

Standard workflow

  1. Inspect current volume:

```bash

hermes sessions stats

```

Use total sessions, messages, per-source counts, and DB size to shape the recommendation.

  1. Inspect prune command behavior when needed:

```bash

hermes sessions prune --help

```

  1. Check current config values:

```bash

hermes config show

```

If the summary output does not include the session settings, inspect the config file's sessions: block directly. Do not use hermes config get; this CLI supports show, edit, set, path, env-path, check, and migrate, not get.

  1. Recommend retention based on actual size and user needs.
  1. Before first major prune, export a backup:

```bash

hermes sessions export ~/hermes-sessions-backup-$(date +%Y%m%d).jsonl

```

  1. Enable auto-prune if approved:

```bash

hermes config set sessions.auto_prune true

hermes config set sessions.retention_days 30

```

  1. Reclaim space immediately with a manual prune:

```bash

hermes sessions prune --older-than 30

```

Add --yes only if the user has authorized non-interactive deletion.

  1. Verify after pruning:

```bash

hermes sessions stats

```

Source-specific cleanup

When one channel is the bloat source, prune only that source:

hermes sessions prune --older-than 30 --source cli
hermes sessions prune --older-than 90 --source telegram

Use this when the user wants to preserve messaging history longer than CLI scratch sessions.

For ongoing split retention, do not rely on global sessions.auto_prune because it has one retention window and can prematurely prune the longer-lived source. Use a quiet script under ~/.hermes/scripts/ and a local no-agent cron job instead:

hermes config set sessions.auto_prune false
hermes config set sessions.retention_days 45 # documentation/default only when auto_prune is off
# ~/.hermes/scripts/prune-sessions-by-source.sh:
# hermes sessions prune --older-than 15 --source cli --yes
# hermes sessions prune --older-than 45 --source telegram --yes

Schedule it daily with deliver='local' and no_agent=true so it does not message the user unless it fails. Cron script paths must be relative to ~/.hermes/scripts/, not absolute.

For the detailed split-retention pattern and one-time CLI purge procedure, see references/source-specific-retention-and-cli-clear.md.

One-time CLI clears

When the user explicitly asks to clear all CLI sessions, first try the CLI pruner:

hermes sessions prune --older-than 0 --source cli --yes

Then verify. If many CLI sessions remain, check whether they are unended/active (ended_at IS NULL). The built-in pruner only removes prune candidates, so historical CLI sessions that were never marked ended may remain.

For an explicit destructive CLI-only clear, keep the newest/current CLI session, delete messages and sessions rows for other source='cli' sessions directly in ~/.hermes/state.db, then checkpoint/VACUUM after stopping processes that hold the DB. Preserve Telegram/Discord/cron/subagent sessions unless separately requested. See the reference file above for the SQL and verification queries.

Pitfalls

Session forensics: token burn, suspected loops, and runaway turns

Use this skill not only for pruning/retention, but also when the user says a session "looped," burned too many tokens, felt unusually slow, or may have resent content repeatedly.

Fast diagnostic workflow

  1. Read the session from the DB and identify whether the waste came from:
  1. Check session totals in state.db:

```bash

sqlite3 ~/.hermes/state.db <<'SQL'

.headers on

.mode column

SELECT id, source, title, model, input_tokens, output_tokens,

cache_read_tokens, reasoning_tokens, api_call_count, message_count,

datetime(started_at,'unixepoch','localtime') AS started,

datetime(ended_at,'unixepoch','localtime') AS ended

FROM sessions

WHERE id='SESSION_ID';

SQL

```

  1. Inspect per-message shape to see the turn pattern and tool payload sizes:

```bash

sqlite3 ~/.hermes/state.db <<'SQL'

.headers on

.mode column

SELECT id, role, tool_name, tool_call_id, length(COALESCE(content,'')) AS content_len,

datetime(timestamp,'unixepoch','localtime') AS ts

FROM messages

WHERE session_id='SESSION_ID'

ORDER BY id;

SQL

```

  1. Check gateway timing/delivery behavior:

That pattern usually means streaming already delivered the final answer once, so the problem was not duplicate send.

  1. Attribute blame precisely:

What to conclude

Pitfalls

Cheap-first guidance to recommend after diagnosis

For lightweight link-analysis or one-question sessions:

See also: references/session-forensics-token-burn.md.

References

Public support files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.