Reddit Search
Search Reddit posts through the browser: a background tab opens www.reddit.com, then a same-origin fetch('/search.json?…', { credentials: 'include' }) hits reddit's own JSON listing endpoint with the browser's cookies, UA, and referer. Adapted from opencli's clis/reddit/search.js. No Reddit API key, no OAuth app, no scraping selectors — the response is reddit's canonical listing JSON. Each call opens its own tab and WebSocket session — safe for parallel use.
Usage
rsearch "claude code" # up to 15 results, pretty
rsearch "local llm" 5 # 5 results
rsearch --json "stable diffusion" 10 # raw JSON array
rsearch --subreddit programming "git tips" # within one subreddit (r/ prefix optional)
rsearch --sort top --time week "browser automation" # sort + time filter
rsearch "rust async" 3 & # parallel-safe
rsearch "go channels" 3 &
wait
| Flag |
Values |
Default |
--json |
— |
pretty text |
--subreddit NAME |
bare name, r/name, or /r/name |
all of reddit |
--sort S |
relevance hot top new comments |
relevance |
--time T |
all hour day week month year |
all |
| positional 2 |
count, 1–100 |
15 |
Result shape
--json returns an array of posts, adapted 1:1 from opencli's column set:
[
{
"id": "1abc2de",
"title": "Show r/programming: …",
"subreddit": "r/programming",
"author": "someuser",
"score": 1234,
"comments": 210,
"url": "https://www.reddit.com/r/programming/comments/1abc2de/…",
"created_utc": 1735689600,
"selftext": "…",
"post_hint": "link",
"url_overridden_by_dest": "https://example.com/article",
"preview_image_url": "https://preview.redd.it/…",
"gallery_urls": []
}
]
Link posts carry the external target in url_overridden_by_dest (pretty output prints it after ->); galleries list direct i.redd.it images in gallery_urls.
Traps
- Ask via the page, not from Node. Server-side
fetch/curl of reddit.com/search.json gets bot-walled or cookie-less default results. The in-page fetch runs with the browser's reddit cookies and real UA on a committed reddit.com origin — that's the whole trick. A logged-in session is used automatically; logged-out searches silently filter NSFW results.
- Don't
waitFor('networkIdle') on reddit. The SPA polls continuously, so the 500 ms quiet window may never open. The script waits for the Page.frameNavigated commit (which fires regardless) plus a short document.readyState poll — the fetch only needs the committed origin, not a fully-built page.
- Bound the page-side fetch. CDP calls have no built-in timeout; the eval is raced against a 20 s node-side timeout so a hung reddit request fails instead of leaking the tab.
- Non-JSON or non-200 responses surface as errors, not empty results — e.g.
HTTP 403: Blocked or a "non-JSON response … block or login wall" message. This fires only after the CLI has already retried twice with backoff: a fresh cookie jar's first /search.json hit gets a 403 interstitial whose response sets the cookies that make the retry pass, so a persistent failure means real rate-limiting — wait a bit or check the login state.
- Result count can be below
count. Reddit caps limit at 100 (the CLI clamps too) and often returns fewer, especially inside small subreddits.
- Multi-flag ordering: flags go before the query (
rsearch --sort top --time week "query"), matching gmaps.
1---2name: rsearch3description: Search Reddit posts through the browser via CDP. Returns structured results (title, subreddit, author, score, comments, permalink URL, selftext, media URLs) for any query, with optional subreddit restriction and sort/time filters. Use when the user asks to search Reddit, find discussions or posts, or gauge community sentiment on a topic. Requires browser-harness-js on PATH and a Chromium-based browser with remote debugging; no Reddit API key — works logged-out, and a logged-in reddit session is used automatically if present.4---56# Reddit Search78Search Reddit posts through the browser: a background tab opens `www.reddit.com`, then a **same-origin** `fetch('/search.json?…', { credentials: 'include' })` hits reddit's own JSON listing endpoint with the browser's cookies, UA, and referer. Adapted from [opencli](https://github.com/jackwener/opencli)'s `clis/reddit/search.js`. No Reddit API key, no OAuth app, no scraping selectors — the response is reddit's canonical listing JSON. Each call opens its own tab and WebSocket session — safe for parallel use.910## Usage1112```bash13rsearch "claude code" # up to 15 results, pretty14rsearch "local llm" 5 # 5 results15rsearch --json "stable diffusion" 10 # raw JSON array16rsearch --subreddit programming "git tips" # within one subreddit (r/ prefix optional)17rsearch --sort top --time week "browser automation" # sort + time filter1819rsearch "rust async" 3 & # parallel-safe20rsearch "go channels" 3 &21wait22```2324| Flag | Values | Default |25|------|--------|---------|26| `--json` | — | pretty text |27| `--subreddit NAME` | bare name, `r/name`, or `/r/name` | all of reddit |28| `--sort S` | `relevance` `hot` `top` `new` `comments` | `relevance` |29| `--time T` | `all` `hour` `day` `week` `month` `year` | `all` |30| positional 2 | count, 1–100 | 15 |3132## Result shape3334`--json` returns an array of posts, adapted 1:1 from opencli's column set:3536```json37[38 {39 "id": "1abc2de",40 "title": "Show r/programming: …",41 "subreddit": "r/programming",42 "author": "someuser",43 "score": 1234,44 "comments": 210,45 "url": "https://www.reddit.com/r/programming/comments/1abc2de/…",46 "created_utc": 1735689600,47 "selftext": "…",48 "post_hint": "link",49 "url_overridden_by_dest": "https://example.com/article",50 "preview_image_url": "https://preview.redd.it/…",51 "gallery_urls": []52 }53]54```5556Link posts carry the external target in `url_overridden_by_dest` (pretty output prints it after `->`); galleries list direct `i.redd.it` images in `gallery_urls`.5758## Traps5960- **Ask via the page, not from Node.** Server-side `fetch`/`curl` of `reddit.com/search.json` gets bot-walled or cookie-less default results. The in-page fetch runs with the browser's reddit cookies and real UA on a committed `reddit.com` origin — that's the whole trick. A logged-in session is used automatically; logged-out searches silently filter NSFW results.61- **Don't `waitFor('networkIdle')` on reddit.** The SPA polls continuously, so the 500 ms quiet window may never open. The script waits for the `Page.frameNavigated` **commit** (which fires regardless) plus a short `document.readyState` poll — the fetch only needs the committed origin, not a fully-built page.62- **Bound the page-side fetch.** CDP calls have no built-in timeout; the eval is raced against a 20 s node-side timeout so a hung reddit request fails instead of leaking the tab.63- **Non-JSON or non-200 responses surface as errors**, not empty results — e.g. `HTTP 403: Blocked` or a "non-JSON response … block or login wall" message. This fires only after the CLI has already retried twice with backoff: a fresh cookie jar's first `/search.json` hit gets a 403 interstitial whose response sets the cookies that make the retry pass, so a persistent failure means real rate-limiting — wait a bit or check the login state.64- **Result count can be below `count`.** Reddit caps `limit` at 100 (the CLI clamps too) and often returns fewer, especially inside small subreddits.65- **Multi-flag ordering:** flags go before the query (`rsearch --sort top --time week "query"`), matching `gmaps`.