dev.to7 de junio de 2026 AFECTA AL EXAMEN
ModeloAPI

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...

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.

python
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"]

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:

python
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)

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):

python
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})

**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 minu

Leer artículo completo en dev.to