3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

きっかけ

ClaudeCode(略:CC)が最近流行っていますね。
ClaudeCodeに限らずですがAIと会話しながら作業を進めていると、最初のころに話してた内容(特にプロンプト)を人間側が忘れてしまうことよくあります。
そこで、AIとの会話ログから最初のころのAIとの対話内容を思い出そうと思ったのがきっかけ。
それ以外にも、CCを使って行った結果を見た他の人間から「これどうやったの?」という問いかけに対して、ログを見せて説明出来たらラクチンだな~と思ったのもきっかけ。

利用環境

  • Windows11
  • WSL AlmaLinux-9
  • Cursor 1.1.3
  • ClaudeCode 1.0.31

ClaudeCode(略:CC)のログのありか

以下にあるファイルを開けば会話ログを見ることができます。

  • WSLで見る場合のCCの会話ログありか
    • /home/{User Name}/.claude/projects/{CodeBasePath(kebab-case)} の中
  • Windowsで見る場合のCCの会話ログありか
    • \\wsl$\{DistributionName}\home\{UserName}\.claude\projects\{CodeBasePath(kebab-case)} の中

    • 例:

      • Windowsのユーザ名(正確にはWSL内のユーザ名):Shohei_Otani
      • コードベースパス:C:\Users\Shohei_Otani\Documents\dekopin\
      • WSLで見る場合のCCの会話ログありか
        • /home/Shohei_Otani/.claude/projects/-mnt-c-Users-Shohei-Otani-Documents-dekopin
      • Windowsで見る場合のCCの会話ログありか
        • \\wsl$\AlmaLinuxOS-9\home\Shohei_Otani\.claude\projects\-mnt-c-Users-Shohei-Otani-Documents-dekopin

ログファイルの中身

(ClaudeCode本人に直接答えてもらいました)

ログファイルの構造

  • 最初の行にセッション情報(JSON形式)
  • 各行が1つのJSONログエントリ
  • ファイル名はconversations_{timestamp}.jsonl形式

ClaudeCodeログの主要キー

  • 基本情報

    • uuid: 各メッセージの一意識別子
    • parentUuid: 親メッセージのUUID(返信の場合)
    • timestamp: ISO 8601形式のタイムスタンプ
    • sessionId: セッション識別子
    • version: ClaudeCodeのバージョン
  • メッセージ構造

    • type: メッセージタイプ(user/assistant/system)
    • message.role: メッセージの役割
    • message.content: メッセージ内容(文字列または配列)
  • コンテンツブロック(配列の場合)

    • type: text/tool_use/tool_result
    • text: テキスト内容
    • name: ツール名
    • input: ツール入力パラメータ
  • メタデータ

    • cwd: 実行時の作業ディレクトリ
    • userType: ユーザータイプ(external/internal等)
    • isSidechain: サイドチェーンメッセージかどうか
    • isMeta: メタメッセージかどうか
  • ツール関連の詳細(content配列内)

    • tool_useブロック: name(ツール名)とinput(パラメータ)
    • tool_resultブロック: ツールの実行結果

ClaudeCodeメッセージタイプ別サンプルログ

ClaudeCodeの主要なメッセージタイプのサンプルです。実際のログは1行1JSONのJSONL形式で保存されます。

ユーザーメッセージ(テキスト)
  {
    "parentUuid": null,
    "isSidechain": false,
    "userType": "external",
    "cwd": "/home/user/project",
    "sessionId": "01234567-89ab-cdef-0123-456789abcdef",
    "version": "0.9.0",
    "type": "user",
    "message": {
      "role": "user",
      "content": "ファイルの内容を読んでください"
    },
    "isMeta": false,
    "uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "timestamp": "2024-01-15T10:30:00.123Z"
  }
ユーザーメッセージ(コマンド実行)
  {
    "parentUuid": null,
    "isSidechain": false,
    "userType": "external",
    "cwd": "/mnt/c/Users/user/Documents/project",
    "sessionId": "01234567-89ab-cdef-0123-456789abcdef",
    "version": "0.9.0",
    "type": "user",
    "message": {
      "role": "user",
      "content": "<command-name>npm test</command-name>\n<command-message>run
  tests</command-message>\n<command-args></command-args><local-command-stdout>Test
  results: 10 passed, 0
  failed</local-command-stdout>このテストエラーを修正してください"
    },
    "isMeta": false,
    "uuid": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "timestamp": "2024-01-15T10:31:00.456Z"
  }
アシスタントメッセージ(ツール使用)
  {
    "parentUuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "isSidechain": false,
    "userType": "external",
    "cwd": "/home/user/project",
    "sessionId": "01234567-89ab-cdef-0123-456789abcdef",
    "version": "0.9.0",
    "type": "assistant",
    "message": {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "ファイルの内容を確認します。"
        },
        {
          "type": "tool_use",
          "name": "Read",
          "input": {
            "file_path": "/home/user/project/src/index.ts"
          }
        },
        {
          "type": "text",
          "text": "ファイルには以下の内容が含まれています:\n-
  Expressサーバーの初期化\n- ルーティング設定\n- ミドルウェアの設定"
        }
      ]
    },
    "isMeta": false,
    "uuid": "c3d4e5f6-a7b8-9012-cdef-123456789012",
    "timestamp": "2024-01-15T10:30:15.789Z"
  }
アシスタントメッセージ(複数ツール使用)
  {
    "parentUuid": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "isSidechain": false,
    "userType": "external",
    "cwd": "/mnt/c/Users/user/Documents/project",
    "sessionId": "01234567-89ab-cdef-0123-456789abcdef",
    "version": "0.9.0",
    "type": "assistant",
    "message": {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "プロジェクトの構造を確認してから、必要なファイルを修正します。"
        },
        {
          "type": "tool_use",
          "name": "LS",
          "input": {
            "path": "/mnt/c/Users/user/Documents/project/src"
          }
        },
        {
          "type": "tool_use",
          "name": "Read",
          "input": {
            "file_path": "/mnt/c/Users/user/Documents/project/package.json"
          }
        },
        {
          "type": "tool_use",
          "name": "Edit",
          "input": {
            "file_path": "/mnt/c/Users/user/Documents/project/src/test.js",
            "old_string": "expect(result).toBe(5)",
            "new_string": "expect(result).toBe(10)"
          }
        }
      ]
    },
    "isMeta": false,
    "uuid": "d4e5f6a7-b8c9-0123-defa-234567890123",
    "timestamp": "2024-01-15T10:32:00.012Z"
  }
システムメッセージ(メタ情報)
  {
    "parentUuid": null,
    "isSidechain": false,
    "userType": "internal",
    "cwd": "/home/user/project",
    "sessionId": "01234567-89ab-cdef-0123-456789abcdef",
    "version": "0.9.0",
    "type": "system",
    "message": {
      "role": "system",
      "content": "Session initialized with working directory: /home/user/project"
    },
    "isMeta": true,
    "uuid": "e5f6a7b8-c9d0-1234-efab-345678901234",
    "timestamp": "2024-01-15T10:29:00.000Z"
  }
サイドチェーンメッセージ
  {
    "parentUuid": "c3d4e5f6-a7b8-9012-cdef-123456789012",
    "isSidechain": true,
    "userType": "internal",
    "cwd": "/home/user/project",
    "sessionId": "01234567-89ab-cdef-0123-456789abcdef",
    "version": "0.9.0",
    "type": "assistant",
    "message": {
      "role": "assistant",
      "content": "Analyzing code structure for optimization opportunities..."
    },
    "isMeta": false,
    "uuid": "f6a7b8c9-d0e1-2345-fabc-456789012345",
    "timestamp": "2024-01-15T10:30:20.123Z"
  }

サイドチェーンメッセージとは…

サイドチェーンメッセージは、メインの会話フローとは別に、バックグラウンドで実行される補助的な処理や分析のメッセージです。
サイドチェーンメッセージは、Claudeが内部的に考えたり分析したりする過程を記録したもので、ユーザーには通常表示されませんが、ログには記録されます。これにより、Claudeの思考プロセスや分析過程を後から確認できます。

サイドチェーンメッセージの特徴
  • 主な用途:

    • コードの構造分析
    • 最適化の機会の検討
    • バックグラウンドでの情報収集
    • 内部的な推論プロセス
  • 特徴:

    • isSidechain: true が設定される
    • userType: "internal" であることが多い
    • メインの会話には直接表示されない
    • 親メッセージ(parentUuid)を持つことが多い

ログファイルを見やすくする

以下のリポジトリで公開されている、CCの会話ログを読みやすいHTML形式に変換するPython CLIツールを使うと便利。(Daniel Demmelさんありがとうございます!!)

導入

# Python 3.12の要件に対応するためにPythonバージョンアップ
pyenv install 3.12.10

# Python 3.12.10をグローバルに設定
pyenv global 3.12.10

# 新しいPythonバージョンを確認
python3 --version

# パスを更新して永続化
echo 'export PATH="$HOME/.pyenv/versions/3.12.10/bin:$PATH"' >> ~/.bashrc

# claude-code-logをシステムにインストール
uv pip install --system claude-code-log

# インストール確認
claude-code-log --help

使い方(すべてのプロジェクトを処理してブラウザで開く)

  1. claude-code-log --open-browser を実行する
  2. CC会話ログのありか に、htmlができあがる
  3. ブラウザで該当htmlを開いてログを見る
    • \\wsl$\{DistributionName}\home\{UserName}\.claude\projects\にあるindex.htmlをブラウザで開く

その他の使い方

# ヘルプ表示
claude-code-log --help

# すべてのプロジェクトを処理してブラウザで開く
claude-code-log --open-browser

# 特定の日付範囲でフィルタ
claude-code-log --from-date "yesterday" --to-date "today" --open-browser

# 特定のプロジェクトのみ処理
claude-code-log /path/to/specific/project --open-browser

ログの保存期間を長く設定する

  • CCの設定ファイルで cleanupPeriodDays の値を設定することでログの保持期間(デフォルトは30日)を調整できます(Anthropic公式 より)

CCの設定ファイルのありか

  • こちら のAnthropic公式案内に記載あり。以下は同じ内容の要約です

    • ユーザ設定
      • ~/.claude/settings.json (WSLの場合も同じ)
    • プロジェクト設定
      • チームと共有される設定用(ソース管理にチェックインされる)
        • {ProjectRoot}/.claude/settings.json
      • チームと共有しない個人用(ソース管理にチェックインされない。CCが作成時に.gitignoreに設定するらしい)
        • {ProjectRoot}/.claude/settings.local.json

設定ファイルの優先順位

  • こちら のAnthropic公式案内に記載あり
  • 優先順位(高い方から低い方へ)
    1. エンタープライズポリシー
    2. コマンドライン引数
    3. ローカルプロジェクト設定
    4. 共有プロジェクト設定
    5. ユーザー設定
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?