ai-session-archiver
v1.3.0
Published
Archive Codex, OpenCode, and Claude Code sessions to Obsidian vault
Downloads
81
Maintainers
Readme
AI Session Archiver
Archive AI coding assistant sessions to your Obsidian vault
AI Session Archiver is a CLI tool that reads local session logs from AI coding assistants (Codex, OpenCode, Claude Code) and converts them into structured Obsidian notes — automatically extracting goals, learnings, troubleshooting, and key concepts.
How It Works
A local post-processor that runs after a session ends:
AI coding session ends
↓
ai-session-archiver reads local log files (JSONL / SQLite)
↓
LLM analysis (Claude Haiku) ← ANTHROPIC_API_KEY set
or heuristic fallback ← no API key / --offline
↓
Markdown note saved to Obsidian vaultLLM mode (default when ANTHROPIC_API_KEY is set): Claude Haiku analyzes the session transcript and extracts goals, learnings, troubleshooting items, and tags — accurately, in any language.
Offline mode (no API key or --offline flag): fully local heuristic analysis, no external calls.
The most convenient setup is to hook it into Claude Code's Stop event, so archiving happens automatically after every turn.
Quick Start
# Install globally
npm install -g ai-session-archiver
# One-time setup: registers Stop hook + installs /archive command for Claude Code
ai-session-archiver install --vault ~/Obsidian
# Optional: set your Anthropic API key for LLM-powered analysis
export ANTHROPIC_API_KEY=sk-ant-...That's it. From now on:
- Auto: Every Claude Code turn archives the session automatically (Stop hook)
- On demand: Type
/archivein any Claude Code session to archive interactively
Supported Providers
| Provider | Data Location | Status |
|----------|--------------|--------|
| Claude Code | ~/.claude/projects/**/*.jsonl | Fully supported |
| Codex | ~/.codex/sessions/**/*.jsonl | Fully supported |
| OpenCode | ~/.local/share/opencode/opencode.db | Fully supported |
Claude Code Integration (Recommended)
Run one command to get both auto-archiving and the /archive slash command:
ai-session-archiver install --vault ~/ObsidianThis does two things at once:
1. Registers a Stop hook — archives every Claude Code session automatically
Adds to ~/.claude/settings.json:
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "ai-session-archiver hook --vault ~/Obsidian --output \"10-Sessions\""
}
]
}
]
}
}2. Installs /archive command — interactive archiving inside Claude Code
Adds ~/.claude/commands/archive.md so Claude knows how to use the archiver. Now you can say:
/archive → archives the most recent Claude Code session
/archive opencode → archives the most recent OpenCode session
/archive codex <session-id> → archives a specific Codex session
/archive --dry-run → preview without saving
/archive all recent → archives 5 most recent sessions across all providersClaude picks the right session and runs the command for you — no need to remember IDs or flags.
Skip individual steps
ai-session-archiver install --vault ~/Obsidian --skip-hook # command only
ai-session-archiver install --vault ~/Obsidian --skip-command # hook only
ai-session-archiver setup-hook --vault ~/Obsidian # hook only (legacy)Manual hook invocation
echo '{"session_id":"<id>","stop_hook_active":false}' | ai-session-archiver hook --vault ~/ObsidianTo remove everything: delete the Stop hook entry from ~/.claude/settings.json and remove ~/.claude/commands/archive.md.
All Commands
providers — Check availability
ai-session-archiver providersInstalled Providers:
====================
Claude Code (claude-code)
Status: ✓ Available
OpenCode (opencode)
Status: ✓ Available
Codex (codex)
Status: ✓ Availablesessions — List sessions
# All providers
ai-session-archiver sessions
# Filter by provider
ai-session-archiver sessions --provider claude-code
# Limit results
ai-session-archiver sessions --limit 20Provider | Session ID | Msgs | Last Updated
-------------|--------------------------------------|------|-------------
claude-code | 66bc677a-3624-495f-8e3b-effead6db2f0 | 20 | 2026. 5. 10.
codex | 019dd95f-1bc1-7460-a7d4-657769bb4e23 | 110 | 2026. 4. 29.
opencode | ses_23ae81207ffeYyyce881Gsr3BE | 187 | 2026. 4. 26.archive — Archive a specific session
ai-session-archiver archive <session-id> --provider <provider>
# Options
-v, --vault <path> Obsidian vault path (default: ~/Obsidian)
-o, --output <folder> Output folder inside vault (default: 10-Sessions)
-t, --template <path> Custom template file
--dry-run Preview output without saving
--offline Skip LLM analysis, use heuristic only# Preview first
ai-session-archiver archive ses_23ae81207ffeYyyce881Gsr3BE \
--provider opencode \
--vault ~/Obsidian \
--dry-run
# Save to vault
ai-session-archiver archive ses_23ae81207ffeYyyce881Gsr3BE \
--provider opencode \
--vault ~/Obsidian \
--output "10-Sessions"recent — Archive recent sessions in bulk
# Archive the 5 most recent sessions from all providers
ai-session-archiver recent --limit 5 --vault ~/Obsidian
# Only from a specific provider
ai-session-archiver recent --provider codex --limit 3 --vault ~/Obsidianhook — Run from Claude Code Stop hook
# Reads session_id from stdin (called automatically by Claude Code)
ai-session-archiver hook --vault ~/Obsidian --output "10-Sessions"setup-hook — Register Claude Code Stop hook
ai-session-archiver setup-hook --vault ~/Obsidian --output "10-Sessions"Output Format
Each archived session becomes a markdown file in your vault:
Filename: 2026-05-10-typescript-66bc677a-3624.md
---
date: 2026-05-10
session_id: 66bc677a-3624-495f-8e3b-effead6db2f0
tags: [typescript, obsidian, codex, troubleshooting]
concepts:
- [[TypeScript]]
- [[Obsidian]]
- [[Codex]]
---
## Context
Archive AI coding assistant sessions to Obsidian vault
## What I Did
OpenCodeProvider 재구현 / Stop hook 등록 명령어 추가 / vault-writer overwrite 지원
## Key Learnings
- OpenCode는 ~/.local/share/opencode/opencode.db에 SQLite로 저장
- Claude Code Stop hook으로 세션 종료 시 자동 아카이브 가능
## Issues & Solutions
| 문제 | 원인 | 해결 |
|-----|------|------|
| OpenCodeProvider 미동작 | globalThis.session_list 사용 | SQLite 직독으로 재구현 |
## Related
- [[TypeScript]]
- [[Obsidian]]Template Customization
Available variables
| Variable | Description |
|----------|-------------|
| {{it.date}} | Session date (YYYY-MM-DD) |
| {{it.sessionId}} | Full session ID |
| {{it.goal}} | First user message / session context |
| {{it.summary}} | Key actions taken |
| {{it.learningPoints}} | Bullet list of extracted learnings |
| {{it.troubleshooting}} | Table of problems, causes, and solutions |
| {{it.concepts}} | Tech concepts as [[wikilinks]] |
| {{it.tags}} | Comma-separated tags |
Custom template
---
date: {{it.date}}
id: {{it.sessionId}}
type: dev-session
---
# {{it.goal}}
## Summary
{{it.summary}}
## Learnings
{{it.learningPoints}}
## References
{{it.concepts}}ai-session-archiver archive <id> --provider claude-code --template ./my-template.mdInstallation
npm install -g ai-session-archiverRequirements: Node.js 18+, sqlite3 CLI (pre-installed on macOS)
Optional: ANTHROPIC_API_KEY — enables LLM-powered analysis (Claude Haiku). Without it, the tool falls back to offline heuristic analysis.
Development
git clone <repo-url>
cd ai-session-archiver
npm install
npm run build
npm run test
npm run test:coverageProject Structure
src/
├── providers/ Provider adapters (claude-code, codex, opencode)
├── analyzers/ Heuristic session analysis
├── renderers/ Markdown template rendering
├── commands/ CLI command handlers
└── utils/ slugify, vault-writer
templates/ Default and example templatesRoadmap
- [ ] GitHub Copilot / Cursor / Aider support
- [x] LLM-powered analysis mode (Claude Haiku, default)
- [ ] Web UI for browsing archived sessions
License
MIT © Yeji
See PROVIDERS.md for provider-specific setup and troubleshooting.
