Search sessions

From richardgill/nix · View interactive version

Search sessions is an AI agent skill from the GitHub repository richardgill/nix. Search saved pi chats, pi conversations, pi sessions, Claude Code chats, Claude Code conversations, and Claude Code sessions. Triggers: "search pi chats", "search pi conversations", "search pi sessions", "find in pi chats", "search Claude Code sessions", "search Claude Code conversations", "search C

How to use this skill

Skill file

Search Sessions

Use this skill when asked to search previous agent chats, conversations, session history, or saved JSONL transcripts for pi or Claude Code.

Scope

Pi current-folder search command

Replace SEARCH TERMS with the user's query.

q='SEARCH TERMS'
session_key=$(printf '%s' "$PWD" | sed 's#^/##; s#/#-#g')
rg -0 -l --no-messages --glob '*.jsonl' -i -F "$q" "$HOME/.pi/agent/sessions/--$session_key--" \
  | xargs -0 -r jq -r --arg q "$q" '
    def text:
      if type == "string" then .
      elif type == "array" then map(if type == "string" then . elif .type == "text" then .text else empty end) | join("\n")
      else empty end;
    . as $e
    | ($e.message? // $e) as $m
    | ($m.role? // empty) as $role
    | select($role == "user" or $role == "assistant")
    | (($m.content? // "") | text) as $text
    | select($text | ascii_downcase | contains($q | ascii_downcase))
    | "--- " + input_filename + " " + ($e.timestamp // "") + " " + $role + "\n" + $text + "\n"
  '

Claude Code current-folder search command

Replace SEARCH TERMS with the user's query.

q='SEARCH TERMS'
session_key=$(printf '%s' "$PWD" | sed 's#^/##; s#/#-#g')
rg -0 -l --no-messages --glob '*.jsonl' -i -F "$q" "$HOME/.claude/projects/-$session_key" \
  | xargs -0 -r jq -r --arg q "$q" '
    def text:
      if type == "string" then .
      elif type == "array" then map(if type == "string" then . elif .type == "text" then .text else empty end) | join("\n")
      else empty end;
    . as $e
    | ($e.message? // $e) as $m
    | ($m.role? // empty) as $role
    | select($role == "user" or $role == "assistant")
    | (($m.content? // "") | text) as $text
    | select($text | ascii_downcase | contains($q | ascii_downcase))
    | "--- " + input_filename + " " + ($e.timestamp // "") + " " + $role + "\n" + $text + "\n"
  '

Pi all-sessions search command

Replace SEARCH TERMS with the user's query.

q='SEARCH TERMS'
rg -0 -l --no-messages --glob '*.jsonl' -i -F "$q" "$HOME/.pi/agent/sessions" \
  | xargs -0 -r jq -r --arg q "$q" '
    def text:
      if type == "string" then .
      elif type == "array" then map(if type == "string" then . elif .type == "text" then .text else empty end) | join("\n")
      else empty end;
    . as $e
    | ($e.message? // $e) as $m
    | ($m.role? // empty) as $role
    | select($role == "user" or $role == "assistant")
    | (($m.content? // "") | text) as $text
    | select($text | ascii_downcase | contains($q | ascii_downcase))
    | "--- " + input_filename + " " + ($e.timestamp // "") + " " + $role + "\n" + $text + "\n"
  '

Claude Code all-sessions search command

Replace SEARCH TERMS with the user's query.

q='SEARCH TERMS'
rg -0 -l --no-messages --glob '*.jsonl' -i -F "$q" "$HOME/.claude/projects" \
  | xargs -0 -r jq -r --arg q "$q" '
    def text:
      if type == "string" then .
      elif type == "array" then map(if type == "string" then . elif .type == "text" then .text else empty end) | join("\n")
      else empty end;
    . as $e
    | ($e.message? // $e) as $m
    | ($m.role? // empty) as $role
    | select($role == "user" or $role == "assistant")
    | (($m.content? // "") | text) as $text
    | select($text | ascii_downcase | contains($q | ascii_downcase))
    | "--- " + input_filename + " " + ($e.timestamp // "") + " " + $role + "\n" + $text + "\n"
  '

Output

$ARGUMENTS

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.