Created
July 20, 2026 17:41
-
-
Save ekinertac/31c6d3e0d7c55dfa44a01c46a5c168e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # pr-session — Find Claude Code session by GitHub PR number | |
| # | |
| # Searches ~/.claude session logs for a given PR number and outputs the | |
| # session ID, path, and title. Useful for quickly jumping back to the | |
| # work context that created or touched a PR. | |
| # | |
| # Usage: pr-session <pr_number> | |
| # | |
| # Output: | |
| # Session ID: <session-uuid> | |
| # Session Path: <working-directory> | |
| # Session Title: <session-title> | |
| # | |
| # Example: | |
| # $ pr-session 22366 | |
| # Session ID: 855406b4-be8c-4fa6-a996-75e12338638e | |
| # Session Path: /Users/ekinertac/Code/humbl.ai | |
| # Session Title: Find agent chat model used in repo | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: pr-session <pr_number>" | |
| exit 1 | |
| fi | |
| PR_NUMBER="$1" | |
| SESSION_FILE="" | |
| # Search for PR in session logs | |
| SESSION_FILE=$(/usr/bin/grep -l "prNumber.*$PR_NUMBER" ~/.claude/projects/*/*.jsonl 2>/dev/null | head -1) | |
| if [[ -z "$SESSION_FILE" ]]; then | |
| echo "No session found for PR #$PR_NUMBER" >&2 | |
| exit 1 | |
| fi | |
| # Extract session details from the first PR entry and the session file | |
| SESSION_ID=$(/usr/bin/grep "prNumber.*$PR_NUMBER" "$SESSION_FILE" 2>/dev/null | head -1 | jq -r '.sessionId // empty') | |
| if [[ -z "$SESSION_ID" ]]; then | |
| echo "Could not extract session ID" >&2 | |
| exit 1 | |
| fi | |
| # Get session title (customTitle field) and path (cwd field) from the session file | |
| SESSION_TITLE=$(jq -r '.customTitle // empty' "$SESSION_FILE" 2>/dev/null | head -1) | |
| SESSION_PATH=$(jq -r '.cwd // empty' "$SESSION_FILE" 2>/dev/null | grep -v '^$' | head -1) | |
| if [[ -z "$SESSION_TITLE" ]]; then | |
| SESSION_TITLE="untitled" | |
| fi | |
| if [[ -z "$SESSION_PATH" ]]; then | |
| SESSION_PATH="unknown" | |
| fi | |
| echo "Session ID: $SESSION_ID" | |
| echo "Session Path: $SESSION_PATH" | |
| echo "Session Title: $SESSION_TITLE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment