Building a Continuous AI Workflow with PostHog and GitHub
This guide shows you how to build an automated system that continuously monitors PostHog session recordings, analyzes user experience issues using AI, and automatically creates GitHub issues for your development team to address.
What You'll Build
A fully automated workflow that fetches PostHog session data, uses Continue
CLI to identify UX problems, and creates GitHub issues with specific technical
recommendations
Create an intelligent analysis script that fetches and analyzes session recordings:
Copy
Ask AI
#!/bin/bash# analyze-sessions.shset -esource .envecho "🎬 Fetching session recordings from PostHog..."# Fetch recent session recordings with potential issuescurl -s -H "Authorization: Bearer $POSTHOG_API_KEY" \ "$POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/session_recordings/?limit=20" \ | jq '.results[] | { id: .id, duration: .recording_duration, start_url: .start_url, click_count: .click_count, console_error_count: .console_error_count, person_distinct_id: .person.distinct_ids[0], start_time: .start_time }' > sessions.jsonecho "📊 Found $(cat sessions.json | jq -s length) sessions"# Filter for problematic sessions (errors or long durations)cat sessions.json | jq -s 'map(select(.console_error_count > 0 or .recording_duration > 300))' > problem-sessions.jsonecho "🚨 Found $(cat problem-sessions.json | jq length) problematic sessions"# Analyze with Continue CLIcat problem-sessions.json | cn -p "Analyze these PostHog session recordings to identify user experience issues.Each session contains:- duration: how long the session lasted (in seconds)- start_url: the page where the user started- click_count: total number of clicks- console_error_count: JavaScript errors encounteredLook for patterns that suggest code issues:1. **High Error Sessions**: Sessions with console_error_count > 0 - What pages/URLs are generating errors? - Are users abandoning after errors occur?2. **Long Duration Sessions**: Sessions over 300 seconds (5+ minutes) - Are users struggling to complete tasks? - Low click count + high duration = user confusion3. **Abandonment Patterns**: - Users starting on key pages but not progressing - Short sessions on important conversion pagesFor each issue pattern you identify:- Describe the user behavior problem- Suggest likely technical causes (JS errors, slow loading, UI confusion)- Recommend specific code areas to investigate- Provide example fixes or improvements- Priority: High (blocks user goals), Medium (hurts UX), Low (minor issue)Focus on actionable technical improvements that will measurably improve user experience."echo "✅ Analysis complete! Check the output above for optimization opportunities."
What This Script Does:
Fetches recent session recordings from
PostHog API
Filters for problematic sessions (errors or long durations)
Analyzes with Continue CLI to identify specific UX issues
Create a smart script that parses the AI analysis and automatically creates GitHub issues:
Intelligent Issue Creation
This script automatically extracts issues from Continue CLI analysis,
determines priority levels, assigns appropriate labels, and creates
well-formatted GitHub issues
Copy
Ask AI
#!/bin/bash# create-github-issues.sh - Creates GitHub issues from Continue CLI analysis outputset -esource .env# Input file containing Continue CLI analysis outputANALYSIS_FILE="analysis-results.txt"# File to track created issues to prevent duplicatesISSUE_TRACKING_FILE=".created_issues.json"# Check if analysis file existsif [ ! -f "$ANALYSIS_FILE" ]; then echo "❌ Analysis file not found: $ANALYSIS_FILE" exit 1fi# Check if GitHub CLI is installedif ! command -v gh &> /dev/null; then echo "❌ GitHub CLI (gh) not found. Please install it first:" echo " https://cli.github.com/manual/installation" exit 1fi# Make sure gh is authenticatedif ! gh auth status &> /dev/null; then echo "❌ GitHub CLI not authenticated. Please run 'gh auth login' first." exit 1fi# Create issue tracking file if it doesn't existif [ ! -f "$ISSUE_TRACKING_FILE" ]; then echo "[]" > "$ISSUE_TRACKING_FILE"fi# Function to check if an issue with this title already existsissue_exists() { local title="$1" local issue_hash=$(echo "$title" | md5sum | cut -d' ' -f1) # Check in our tracking file if grep -q "\"$issue_hash\"" "$ISSUE_TRACKING_FILE"; then return 0 # Issue exists fi # Also check actual GitHub issues to be doubly sure if gh issue list --repo "$GITHUB_OWNER/$GITHUB_REPO" --search "$title in:title" --json title | grep -q "$title"; then # Add to tracking file if found on GitHub but not in our tracking local tracking_data=$(cat "$ISSUE_TRACKING_FILE") echo "$tracking_data" | jq --arg hash "$issue_hash" '. += [$hash]' > "$ISSUE_TRACKING_FILE" return 0 # Issue exists fi return 1 # Issue doesn't exist}# Function to record that we created an issuerecord_issue() { local title="$1" local issue_hash=$(echo "$title" | md5sum | cut -d' ' -f1) local tracking_data=$(cat "$ISSUE_TRACKING_FILE") echo "$tracking_data" | jq --arg hash "$issue_hash" '. += [$hash]' > "$ISSUE_TRACKING_FILE"}# Function to create a GitHub issue using GitHub CLIcreate_github_issue() { local title="$1" local body="$2" local labels="$3" # Check if this issue already exists if issue_exists "$title"; then echo "ℹ️ Issue already exists: $title" return 0 fi echo "Creating issue: $title" # Convert labels from JSON array format to comma-separated list # Remove brackets, quotes, and add commas labels_list=$(echo $labels | sed 's/\[//g' | sed 's/\]//g' | sed 's/"//g' | sed 's/,/,/g') # Create issue using GitHub CLI issue_url=$(gh issue create \ --repo "$GITHUB_OWNER/$GITHUB_REPO" \ --title "$title" \ --body "$body" \ --label "$labels_list" \ --web) if [ $? -eq 0 ]; then echo "✅ Created issue: $issue_url" # Record that we created this issue record_issue "$title" else echo "❌ Failed to create issue" fi}# Extract and parse issues from analysis outputecho "🔍 Parsing analysis results for issues..."# Count the issues in the file by looking for ## Issue patternissue_count=$(grep -c "^## Issue" "$ANALYSIS_FILE" || echo 0)if [ "$issue_count" -eq 0 ]; then echo "ℹ️ No issues found in analysis output." exit 0fiecho "📊 Found $issue_count potential issues to process"# Process each issue sectionwhile IFS= read -r line || [[ -n "$line" ]]; do if [[ $line =~ ^## ]]; then # If we have a previous issue, create it if [ -n "${issue_title:-}" ] && [ -n "${issue_body:-}" ]; then # Determine appropriate labels based on priority in the issue body if [[ "$issue_body" =~ "High Priority" ]]; then labels="[\"bug\", \"high-priority\", \"user-experience\"]" elif [[ "$issue_body" =~ "Medium Priority" ]]; then labels="[\"enhancement\", \"medium-priority\", \"user-experience\"]" else labels="[\"low-priority\", \"user-experience\"]" fi # Create the issue create_github_issue "$issue_title" "$issue_body" "$labels" fi # Start a new issue issue_title="UX Issue: ${line#\#\# Issue }" issue_body="" elif [ -n "${issue_title:-}" ]; then # Add line to current issue body if [ -n "$issue_body" ]; then issue_body="$issue_body\n$line" else issue_body="$line" fi fidone < <(sed -n '/^## Issue/,/^## Issue\|^$/p' "$ANALYSIS_FILE")# Create the last issue if there is oneif [ -n "${issue_title:-}" ] && [ -n "${issue_body:-}" ]; then # Determine appropriate labels based on priority in the issue body if [[ "$issue_body" =~ "High Priority" ]]; then labels="[\"bug\", \"high-priority\", \"user-experience\"]" elif [[ "$issue_body" =~ "Medium Priority" ]]; then labels="[\"enhancement\", \"medium-priority\", \"user-experience\"]" else labels="[\"low-priority\", \"user-experience\"]" fi # Create the issue create_github_issue "$issue_title" "$issue_body" "$labels"fiecho "✅ GitHub issues creation process completed!"
Make it executable:
Copy
Ask AI
chmod +x create-github-issues.sh
Smart Label Assignment: The script automatically assigns labels based on
issue priority:
High Priority → bug, high-priority,
user-experience
Medium Priority → enhancement, medium-priority,
user-experience
Low Priority → low-priority, user-experience
Be sure to customize the label logic in the script to match your
repository’s labeling conventions!
\"$POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/session_recordings/?limit=1"# Test GitHub API curl -H "Authorization: token$GITHUB_PERSONAL_ACCESS_TOKEN" \"https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO"
2
Run Session Analysis
bash ./analyze-sessions.sh Expected: JSON files with session data and
AI analysis output
3
Test Issue Creation
bash ./create-github-issues.sh Expected: New issues created in your
GitHub repository
4
Full Workflow Test
bash ./daily-analysis.sh Expected: Complete end-to-end execution with
GitHub issues created
Success Indicators:
PostHog API returns session data (not empty)
Continue CLI generates analysis with identified issues
GitHub issues are created with proper labels and formatting
After completing this guide, you have a complete Continuous AI system that:✅ Monitors user experience - Automatically fetches and analyzes PostHog session data
✅ Identifies problems intelligently - Uses AI to spot patterns and technical issues
✅ Creates actionable tasks - Generates GitHub issues with specific recommendations
✅ Runs autonomously - Operates daily without manual intervention
✅ Scales with your team - Handles growing amounts of session data automatically
Continuous AI
Your system now operates at Level 2 Continuous AI - AI handles routine
analysis tasks with human oversight through GitHub issue review and
prioritization.