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.
Core Principle
Ask via the page, not from Node: 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. No Reddit API key,
no OAuth app, no scraping selectors, the response is reddit's canonical listing JSON.
When to Use / NOT
- Use when: the user asks to search Reddit, find discussions or posts, or gauge
community sentiment on a topic, any query, with optional subreddit restriction and
sort/time filters. Works logged-out; a logged-in reddit session is used automatically
if present.
- NOT when: the task is anything other than searching (posting, commenting, etc.),
or no Chromium-based browser with remote debugging is running, the in-page fetch
needs a committed
reddit.com origin.
Workflow
- Ensure prerequisites:
browser-harness-js on PATH and a running Chromium-based
browser with remote debugging (chrome://inspect or --remote-debugging-port); run
bash <skill-dir>/scripts/setup if not set up.
- Run
rsearch "<query>" [count] with flags before the query: --json,
--subreddit NAME, --sort S, --time T.
- Read the structured results (title, subreddit, author, score, comments, permalink
URL, selftext, media URLs); link posts carry the external target in
url_overridden_by_dest.
- On persistent failure after the built-in retries, wait a bit or check the login
state, it means real rate-limiting.
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. A persistent failure then 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.
Red Flags
- Server-side
fetch/curl of reddit.com/search.json instead of the in-page fetch,
bot-walled or cookie-less default results.
waitFor('networkIdle') on reddit, the SPA polls continuously, so the quiet window
may never open.
- An unbounded page-side fetch, CDP calls have no built-in timeout; the eval must be
raced against the 20 s node-side timeout.
- Treating an empty result as success when the response was non-JSON or non-200, those
surface as errors, not empty results.
- Expecting exactly
count results, reddit caps limit at 100 and often returns
fewer, especially inside small subreddits.
- Flags after the query, flags go before the query.
Verification
- The command exits 0 and prints results (pretty text, or a raw JSON array with
--json).
- Each result carries the expected fields: title, subreddit, author, score, comments,
permalink URL, selftext, media URLs.
- A persistent error after the built-in retries means real rate-limiting, wait a bit or
check the login state before retrying.
References
N/A, no reference files; usage, result shape, and traps are fully covered in this file.
1---2name: rsearch3description: Use when the user asks to search Reddit, find discussions or posts, or gauge community sentiment on a topic. Searches Reddit through the browser via CDP and returns title, subreddit, author, score, comments, permalink, and selftext, with optional subreddit and sort filters. No API key; a logged-in 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## Core Principle1112Ask via the page, not from Node: a background tab opens `www.reddit.com`, then a13**same-origin** `fetch('/search.json?…', { credentials: 'include' })` hits reddit's own14JSON listing endpoint with the browser's cookies, UA, and referer. No Reddit API key,15no OAuth app, no scraping selectors, the response is reddit's canonical listing JSON.1617## When to Use / NOT1819- **Use when:** the user asks to search Reddit, find discussions or posts, or gauge20 community sentiment on a topic, any query, with optional subreddit restriction and21 sort/time filters. Works logged-out; a logged-in reddit session is used automatically22 if present.23- **NOT when:** the task is anything other than searching (posting, commenting, etc.),24 or no Chromium-based browser with remote debugging is running, the in-page fetch25 needs a committed `reddit.com` origin.2627## Workflow28291. Ensure prerequisites: `browser-harness-js` on PATH and a running Chromium-based30 browser with remote debugging (`chrome://inspect` or `--remote-debugging-port`); run31 `bash <skill-dir>/scripts/setup` if not set up.322. Run `rsearch "<query>" [count]` with flags before the query: `--json`,33 `--subreddit NAME`, `--sort S`, `--time T`.343. Read the structured results (title, subreddit, author, score, comments, permalink35 URL, selftext, media URLs); link posts carry the external target in36 `url_overridden_by_dest`.374. On persistent failure after the built-in retries, wait a bit or check the login38 state, it means real rate-limiting.3940## Usage4142```bash43rsearch "claude code" # up to 15 results, pretty44rsearch "local llm" 5 # 5 results45rsearch --json "stable diffusion" 10 # raw JSON array46rsearch --subreddit programming "git tips" # within one subreddit (r/ prefix optional)47rsearch --sort top --time week "browser automation" # sort + time filter4849rsearch "rust async" 3 & # parallel-safe50rsearch "go channels" 3 &51wait52```5354| Flag | Values | Default |55|------|--------|---------|56| `--json` |, | pretty text |57| `--subreddit NAME` | bare name, `r/name`, or `/r/name` | all of reddit |58| `--sort S` | `relevance` `hot` `top` `new` `comments` | `relevance` |59| `--time T` | `all` `hour` `day` `week` `month` `year` | `all` |60| positional 2 | count, 1–100 | 15 |6162## Result shape6364`--json` returns an array of posts, adapted 1:1 from opencli's column set:6566```json67[68 {69 "id": "1abc2de",70 "title": "Show r/programming: …",71 "subreddit": "r/programming",72 "author": "someuser",73 "score": 1234,74 "comments": 210,75 "url": "https://www.reddit.com/r/programming/comments/1abc2de/…",76 "created_utc": 1735689600,77 "selftext": "…",78 "post_hint": "link",79 "url_overridden_by_dest": "https://example.com/article",80 "preview_image_url": "https://preview.redd.it/…",81 "gallery_urls": []82 }83]84```8586Link 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`.8788## Traps8990- **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.91- **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.92- **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.93- **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. A persistent failure then means real rate limiting; wait a bit or check the login state.94- **Result count can be below `count`.** Reddit caps `limit` at 100 (the CLI clamps too) and often returns fewer, especially inside small subreddits.95- **Multi-flag ordering:** flags go before the query (`rsearch --sort top --time week "query"`), matching `gmaps`.9697## Red Flags9899- Server-side `fetch`/`curl` of `reddit.com/search.json` instead of the in-page fetch,100 bot-walled or cookie-less default results.101- `waitFor('networkIdle')` on reddit, the SPA polls continuously, so the quiet window102 may never open.103- An unbounded page-side fetch, CDP calls have no built-in timeout; the eval must be104 raced against the 20 s node-side timeout.105- Treating an empty result as success when the response was non-JSON or non-200, those106 surface as errors, not empty results.107- Expecting exactly `count` results, reddit caps `limit` at 100 and often returns108 fewer, especially inside small subreddits.109- Flags after the query, flags go before the query.110111## Verification112113- The command exits 0 and prints results (pretty text, or a raw JSON array with114 `--json`).115- Each result carries the expected fields: title, subreddit, author, score, comments,116 permalink URL, selftext, media URLs.117- A persistent error after the built-in retries means real rate-limiting, wait a bit or118 check the login state before retrying.119120121## References122123N/A, no reference files; usage, result shape, and traps are fully covered in this file.