feat: add /sessions command for session history management (#142)

Add a new /sessions command to manage Claude Code session history with
alias support for quick access to previous sessions.

Features:
- List sessions with pagination and filtering (by date, ID)
- Load and view session content and metadata
- Create memorable aliases for sessions
- Remove aliases
- Display session statistics (lines, items, size)
- List all aliases

New libraries:
- scripts/lib/session-manager.js - Core session CRUD operations
- scripts/lib/session-aliases.js - Alias management with atomic saves

New command:
- commands/sessions.md - Complete command with embedded scripts

Modified:
- scripts/lib/utils.js - Add getAliasesPath() export
- scripts/hooks/session-start.js - Show available aliases on session start

Session format support:
- Old: YYYY-MM-DD-session.tmp
- New: YYYY-MM-DD-<short-id>-session.tmp

Aliases are stored in ~/.claude/session-aliases.json with Windows-
compatible atomic writes and backup support.

Co-authored-by: 王志坚 <wangzhijian10@bgyfw.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
xcfdszzr
2026-02-03 08:51:37 +08:00
committed by GitHub
parent e7cb442843
commit d85b1ae52e
5 changed files with 1152 additions and 0 deletions

View File

@@ -34,6 +34,13 @@ function getSessionsDir() {
return path.join(getClaudeDir(), 'sessions');
}
/**
* Get the session aliases file path
*/
function getAliasesPath() {
return path.join(getClaudeDir(), 'session-aliases.json');
}
/**
* Get the learned skills directory
*/
@@ -382,6 +389,7 @@ module.exports = {
getHomeDir,
getClaudeDir,
getSessionsDir,
getAliasesPath,
getLearnedSkillsDir,
getTempDir,
ensureDir,