0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Codeのセッションをプロジェクト横断でみる

0
Posted at

ワンライナー

find ~/.claude/projects -name "*.jsonl" -printf "%T@ %p\n" | sort -rn | awk '{print $2}' | while read f; do
  title=$(jq -rRs '
    split("\n") | map(select(length>0) | try fromjson) |
    map(select(.type=="user")) | first |
    .message.content |
    if type=="string" then . elif type=="array" then (map(select(.type=="text")) | first | .text) else "" end |
    .[0:60] | gsub("\n";" ")
  ' "$f" 2>/dev/null)
  mtime=$(date -r "$f" "+%Y-%m-%d %H:%M")
  printf "%s  %s  %s\n" "$mtime" "${f#$HOME/.claude/projects/}" "${title:-[no message]}"
done | less -S

解説

  • テストした環境はUbunt24 on WSL
  • 最後のlessはやってもやらなくてもOK
  • less -S は右スクロールできるおまじない(lessで開いたあとも-Sで折り返しはトグルできる))
  • 実行結果も載せたかったけど、ほとんど隠さないと行けないので載せてない
  • このワンライナーもClaude Codeに書かせた
    • 最初はPythonで書いてきたけど、「それはワンライナーから逸脱するのでダメ」としてjqで無理やり書かせた
    • jqコマンドの引数はもはや人力ではかけない

作った背景

  • 生成AIのセッションって割と「資産」ではある
  • だから不要なものは整理して大事なものだけ残したい
  • Claude Code自体がディレクトリ単位でプロジェクトが切られるため、/resume では横断して履歴をたどりづらい
  • 何よりもClaude Code本体からセッションを削除する導線がないため、物理的なファイルのパスを取得してからでないと削除できない
  • あちこちのマシンにClaude Codeをインストールしてるから、コピペで動くワンライナーにしている
  • サーバーにログインしたらこのワンライナーをコピペする
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?