Skip to content

feat: backup-sessions command to prevent tool auto-deletion of sessions#18

Open
xliry wants to merge 1 commit intopeteromallet:mainfrom
xliry:fix/issue-16-prevent-session-deletion
Open

feat: backup-sessions command to prevent tool auto-deletion of sessions#18
xliry wants to merge 1 commit intopeteromallet:mainfrom
xliry:fix/issue-16-prevent-session-deletion

Conversation

@xliry
Copy link

@xliry xliry commented Mar 1, 2026

Fixes #16

Problem

Claude Code and Gemini CLI automatically delete sessions older than 30 days. This causes data loss for dataclaw users who haven't exported their data yet.

Solution

1. dataclaw backup-sessions command (new)

Copies all session files from ~/.claude/projects/ and ~/.gemini/tmp/ to ~/.dataclaw/session_backup/ — a location that coding tools don't clean up.

# Manual run
dataclaw backup-sessions

# Automate with cron (hourly)
0 * * * * dataclaw backup-sessions

Output:

{
  "backed_up": 42,
  "already_current": 100,
  "backup_dir": "~/.dataclaw/session_backup",
  "next_steps": ["...cron instructions..."]
}

2. Parser reads from backup as fallback

_discover_claude_projects(), _discover_gemini_projects(), and parse_project_sessions() now merge results from both the original source directory and ~/.dataclaw/session_backup/. Sessions deleted by tool cleanup are still included in exports.

3. README documentation

Added a "Preventing session deletion" section with:

  • backup-sessions command and cron setup
  • How to configure Claude Code (cleanupPeriodDays: 0 in settings.json) and Gemini CLI to retain sessions longer

Testing

All existing 290 tests pass. Test helpers updated to monkeypatch the new backup dir constants so they don't leak into isolation tests.

…romallet#16)

Prevent data loss from automatic session cleanup by Claude Code and Gemini CLI:

- Add `dataclaw backup-sessions` CLI command that copies session files from
  ~/.claude/projects/ and ~/.gemini/tmp/ to ~/.dataclaw/session_backup/
- Parser now reads from backup location as fallback, so sessions deleted by
  tool cleanup are still included in exports
- Document cron setup and tool configuration options in README

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent automatic deletion of old sessions

1 participant