DEV Community

Henry Knight
Henry Knight

Posted on

How I Built a Reddit Karma Bot with Claude API and CDP Browser Automation

Reddit is one of the hardest platforms to automate. Shadowbans, karma gates, rate limits, fingerprint checks. I spent two weeks building a Reddit automation system using Chrome DevTools Protocol (CDP) and the Claude API, and here are the exact patterns that worked.

Why CDP Instead of Playwright or Selenium

Most tutorials reach for Playwright. It works great for testing, but it announces itself. Reddit detects navigator.webdriver, checks timing patterns, and analyzes mouse movement entropy.

CDP gives lower-level control. Connecting directly to a running Chrome instance (not spawned by automation) gives you a real browser profile with real history, cookies, and hardware fingerprints.

import subprocess, requests

# Launch Chrome with remote debugging - NOT via Playwright
chrome_proc = subprocess.Popen([
    "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
    "--remote-debugging-port=9222",
    "--user-data-dir=/tmp/reddit-session",
])

# Connect directly
targets = requests.get("http://localhost:9222/json").json()
ws_url = targets[0]["webSocketDebuggerUrl"]
Enter fullscreen mode Exit fullscreen mode

Reddit sees a real Chrome install, not a puppeteer-spawned chromium binary.

Claude API as a Decision Layer

The hard problem is not navigation - it is knowing what to do. Karma grows through genuinely useful comments. Posting platitudes gets you shadowbanned in hours.

I wired Claude as a reasoning layer. For each post, the bot sends title, top comments, and subreddit context:

from anthropic import Anthropic
import json

client = Anthropic()

def should_comment(post_title, top_comments, subreddit):
    prompt = (
        f"Subreddit: r/{subreddit}\n"
        f"Post: {post_title}\n"
        f"Top comments: {top_comments}\n\n"
        "Should I comment? Only if I add genuine value. "
        "Return JSON: should_comment (bool), comment (str or null), reasoning (str)."
    )
    resp = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=512,
        messages=[{"role": "user", "content": prompt}]
    )
    return json.loads(resp.content[0].text)
Enter fullscreen mode Exit fullscreen mode

This single call separates a bot banned in 24 hours from one that survives weeks. Claude catches bot-sounding patterns that rule-based filters miss.

Detection Evasion: What Actually Works

1. Timing entropy. Bots type at consistent speeds. Humans do not. I added Gaussian-distributed delays between keystrokes (mean 80ms, sigma 30ms):

import random, time

def human_type(ws, text):
    for char in text:
        send_cdp(ws, "Input.dispatchKeyEvent", {"type": "keyDown", "text": char})
        time.sleep(abs(random.gauss(0.08, 0.03)))
        send_cdp(ws, "Input.dispatchKeyEvent", {"type": "keyUp", "text": char})
Enter fullscreen mode Exit fullscreen mode

2. Scroll behavior. Reddit JS watches scroll patterns. I implemented smooth scrolling with pause durations proportional to estimated reading time.

3. Session aging. New accounts are suspect. I built a warmup phase: browse r/all for 20 minutes, upvote some posts, read threads before ever posting. Claude selects which posts to touch so the pattern looks organic.

4. Network fingerprinting. Reddit checks TLS fingerprints. A raw Python requests call looks nothing like Chrome. Routing API calls through the browser via CDP Network interception matches the fingerprint exactly.

Architecture

Task Queue      <- target subreddits and goals
     |
CDP Controller  <- real Chrome, human-like inputs
     |
Claude API      <- decides what is worth saying
     |
Action Logger   <- SQLite, records outcomes, feeds back
Enter fullscreen mode Exit fullscreen mode

The logger matters long-term. Every comment, upvote received, shadowban - all in SQLite. The system learns which subreddits respond well and which comment styles land. What starts as a bot becomes a feedback loop.

What I Learned

The hardest part was not the code. It was understanding why each detection layer exists and addressing the underlying signal. Reddit does not ban you for using CDP - it bans you for behaving like a bot. The fix is behavioral, not technical.

Claude as a reasoning layer turned scripted automation into something closer to a judgment system. It reads context, decides whether a comment is worth making, and generates text that does not sound machine-generated - because it is not.


Get the full toolkit at https://payhip.com/b/GuYx8

Top comments (0)