Claude session log to kb
Skill bokuwalily/claude-code-skills/skills/claude-session-log-to-kb
Stop hook 経由で Claude Code セッションの会話ログを Markdown 化してナレッジベースに追記するパターン。新規プロジェクトでセッション長期記憶を設けたいとき、または extract_conversations.py 相当の仕組みを構築・デバッグするときに使う。From its SKILL.md
npx -y skills add bokuwalily/claude-code-skills --skill claude-session-log-to-kbAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.2 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it
Procedure
1. ディレクトリ構成
~/.claude/projects/<project-slug>/ ← Claude Code が自動生成する JSONL セッションログ
~/Documents/my-knowledge-base/
├── extract_conversations.py ← JSONL → Markdown 変換スクリプト
├── raw/conversations/ ← 出力先(<label>_<session-id[:8]>.md)
│ └── INDEX.md ← 自動生成インデックス
└── logs/ ← hook 実行ログ
2. Stop hook の接続(settings.json)
~/.claude/settings.json の Stop フックで stop_hooks_combined.sh を呼び出す。
このスクリプトから obsidian_stop_sync.sh が起動し、5分デバウンス後に抽出を実行する。
"Stop": [{"hooks": [{"type": "command", "command": "/path/to/stop_hooks_combined.sh"}]}]
3. obsidian_stop_sync.sh の多重起動防止パターン
DEBOUNCE_SEC=300
LOCK="/tmp/obsidian_stop_sync.lock"
STAMP="/tmp/obsidian_stop_sync.last"
# デバウンス: 前回完了から DEBOUNCE_SEC 未満なら skip
if [ -f "$STAMP" ]; then
last=$(stat -f %m "$STAMP" 2>/dev/null || echo 0)
now=$(date +%s)
[ $((now - last)) -lt "$DEBOUNCE_SEC" ] && exit 0
fi
# mkdir ロック(stale は 30 分で自動回収)
if [ -d "$LOCK" ]; then
lock_age=$(( $(date +%s) - $(stat -f %m "$LOCK" 2>/dev/null || echo 0) ))
[ "$lock_age" -gt 1800 ] && rmdir "$LOCK" 2>/dev/null
fi
mkdir "$LOCK" 2>/dev/null || exit 0
trap 'rmdir "$LOCK" 2>/dev/null' EXIT
printf '{"decision":"approve"}\n' を 本体実行前に 返すことで Claude Code をブロックしない。
4. extract_conversations.py のコア処理
PROJECTS_DIR = Path.home() / ".claude" / "projects"
RAW_DIR = Path.home() / "Documents" / "my-knowledge-base" / "raw"
# ~/.claude/projects/<slug>/*.jsonl を走査
for project_dir in sorted(PROJECTS_DIR.iterdir()):
label = normalize_label(project_dir.name) # human-readable ラベルに変換
conv_dir = RAW_DIR / "conversations"
for jsonl_path in sorted(project_dir.glob("*.jsonl")):
messages = parse_session(jsonl_path) # type+message フィールドを抽出
md = format_session_md(messages, session_id, label)
out_path = conv_dir / f"{label}_{session_id[:8]}.md"
out_path.write_text(md)
parse_session のポイント
obj["type"]が"user"または"assistant"の行のみ採用- content が
listの場合はtype=="text"ブロックのみ連結(tool_resultはスキップ)
正規化ルール
PROJECT_LABELSハードコード辞書で優先マッチ- フォールバック:
-Users-you-プレフィックスを剥がして残りをラベルに /private/var/folders/・/tmp/由来はEXCLUDE_PREFIXESで除外
5. 出力ファイルの形式
# <label> - <session_id[:8]>
**日時**: YYYY-MM-DD HH:MM
---
**user**: <テキスト>
**assistant**: <テキスト>
---
サイズ降順の INDEX.md が generate_index() により同フォルダに自動更新される。
6. 新プロジェクトへの追加手順
PROJECT_LABELSに{"-Users-you-...-<project>": "<label>"}を追記stop_hooks_combined.shに Codex 版スクリプト (extract_codex_conversations.py) も必要なら同様に追加~/.claude/settings.jsonの Stop hook がリポジトリ側.claude/settings.jsonに上書きされていないか確認
Pitfalls
- フル再スキャン: スクリプトは毎回全 JSONL を走査して上書き出力する。セッション数 800+・corpus 940MB を超えると実行時間が長くなる →
DEBOUNCE_SEC=300が実質的なスロットル - バックグラウンド実行:
obsidian_stop_sync.shは& exit 0パターンでバックグラウンド化しているが、サブシェルログは~/Documents/my-knowledge-base/logs/obsidian-hooks.logで確認できる - TMPDIR 壊れ:
mktempが失敗するとPAYLOADが空になりすべての後続フックが no-op になる。stop_hooks_combined.shでは fallback パスを用意している - LOCK stale: プロセス異常終了時に
LOCKディレクトリが残る。30分で自動回収されるが、急いで手動クリアするならrmdir /tmp/obsidian_stop_sync.lock stat -f %m: macOS 固有。Linux ではstat -c %Yに替える
Verification
# 最新セッションが変換されているか確認
ls -lt ~/Documents/my-knowledge-base/raw/conversations/ | head -5
# hook 実行ログ(エラー有無)
tail -20 ~/Documents/my-knowledge-base/logs/obsidian-hooks.log
# 手動トリガー(デバウンス解除は STAMP 削除)
rm -f /tmp/obsidian_stop_sync.last
bash ~/.local/bin/obsidian_stop_sync.sh
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most context ai engineering skills give in ~1.6k tokens
Counted across 1,193 of the 1,976 authors here whose files we hold, read 2026-08-07
- Dispatch a fresh implementer subagent per taskin 48 of 1193, across 19 files
- Dispatch a final code reviewer after all tasksin 33 of 1193, across 8 files
- Provide full task text to the subagentin 30 of 1193, across 9 files
- Review spec compliance before code qualityin 27 of 1193, across 10 files
- Make the hook script executablein 26 of 1193, across 8 files
- Re-snapshot after navigation or DOM changesin 25 of 1193, across 19 files
- Read files before editing themin 22 of 1193, across 11 files
- Answer subagent questions before proceedingin 22 of 1193, across 7 files
- Mark task complete in TodoWrite after approvalin 22 of 1193, across 6 files
- Merge hook into existing settingsin 21 of 1193, across 3 files
- Ask if installation is global or projectin 20 of 1193, across 2 files
- Copy the hook script to target locationin 20 of 1193, across 2 files
Said here and by no other author read
- call sync script from stop hook
- debounce script execution by five minutes
- prevent multiple script instances using lock directory
- return approval json before main execution
- skip tool_result blocks during parsing
- skip user and assistant rows only
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.