Use Reddit directly over HTTP via reddit.com/*.json through the bundled cross-platform Python CLI.
Entry point
Cross-platform:
uv run --script <skill-dir>/scripts/cli.py ...
Set <skill-dir> to this skill directory. Do not rely on shell sourcing, executable bits, or shebang dispatch.
Environment check policy: run the documented CLI entrypoint first; it auto-loads a skill-local .env using the lookup order below. Missing REDDIT_USER_AGENT is not a hard blocker because this skill has a built-in default.
Quick start
uv run --script <skill-dir>/scripts/cli.py browse all hot limit=10
uv run --script <skill-dir>/scripts/cli.py browse technology top time=week limit=10
uv run --script <skill-dir>/scripts/cli.py search "h1b" subreddits='["cscareerquestions","immigration"]' sort=new time=month limit=10
uv run --script <skill-dir>/scripts/cli.py post programming 1abcde comment_limit=20 comment_sort=top
uv run --script <skill-dir>/scripts/cli.py post-url "https://reddit.com/r/programming/comments/1abcde/example/" comment_limit=20
uv run --script <skill-dir>/scripts/cli.py user-analysis spez posts_limit=5 comments_limit=5 time_range=month
uv run --script <skill-dir>/scripts/cli.py explain "cake day"
uv run --script <skill-dir>/scripts/cli.py browse all hot limit=25 raw=1
Output shape
By default HTTP commands return a compact agent-shaped JSON envelope. The shape varies per command:
browse/search/user-posts/user-comments:{"type": ..., "<subreddit|user|query>": ..., "sort": ..., "time": ..., "count": N, "results": [...]}. Each result keeps:id,title,subreddit,author,score,num_comments,url,permalink,created_utc,flair(when set),selftext_preview(when set, collapsed and capped),over_18,is_self.post/post-url:{"type": "post", "post": {...compact listing fields...}, "comments": [{"id", "author", "score", "body", "created_utc", "permalink", "depth"}, ...]}.moreplaceholder comments are dropped. Comment bodies are collapsed to single-spaced text.user:{"type": "user", "user": "...", "profile": {"name", "created_utc", "link_karma", "comment_karma", "total_karma", "verified", "is_gold", "is_mod"}}.user-analysis: structured summary, seereference.md.explain:{"term": "<normalized>", "definition": "..."}.
Pass raw=1 to receive the full upstream JSON unchanged. raw=1 works with browse, search, post, post-url, user, user-posts, user-comments. explain and user-analysis are always structured.
Errors
HTTP failures emit one-line compact JSON to stderr:
{"error":{"provider":"reddit","status":403,"message":"Reddit returned HTTP 403","body_bytes":1234,"body_preview":"...","body_truncated":true,"kind":"network_security_block"}}
Fields:
error.provider—"reddit"error.status— HTTP status from Reddit (ornullfor network errors)error.message— short human-readable causeerror.body_bytes— upstream response sizeerror.body_preview— first 500 chars of the upstream body, decoded UTF-8error.body_truncated—trueif the body was longer than the preview caperror.kind—"network_security_block"when the body text containsblocked by network security;"network_error"forURLError;"invalid_json"for unparseable responses; omitted otherwise
HTTP errors return exit code 22. Network errors return 1. Validation errors return 2 with a concise stderr line, no traceback.
Environment
- Keep
.envbeside this skill if you want a stable local User-Agent. - CLI lookup order:
REDDIT_ENV_FILE- skill
.env $SKILLS_DIR/reddit/.env- nearest ancestor
skills/reddit/.env
- Tracked template:
.env.example - Common vars:
REDDIT_USER_AGENTREDDIT_BASE_URL
Failure handling
- Do not treat the parent shell as the source of truth for
REDDIT_USER_AGENT; always run the CLI so it can load its own.env. - If env loading still fails, set
REDDIT_ENV_FILEdynamically from the skill path rather than hard-coding a machine-specific directory. - Missing
REDDIT_USER_AGENTafter CLI lookup is not a hard blocker because the CLI has a built-in default. - Distinguish env lookup behavior from HTTP failures or Reddit-side blocking; report the actual request failure instead of claiming the skill lacks credentials.
- A
network_security_blockerror means Reddit (or an upstream proxy) refused the request, not a local config issue. SwitchREDDIT_USER_AGENTor change egress before retrying.
Aliases
searchaccepts:subreddits='["a","b"]'(must be a JSON list of non-empty strings; malformed values return rc=2)author=<username>flair=<text>time=is an alias fort=
post/post-urlaccept:comment_limit=→limit=comment_sort=→sort=comment_depth=→depth=
Validation rules
browserequires a subreddit; sort must behot|new|top|rising|controversialand appear before anykey=valuearg. A stray positional token afterkey=valueis rc=2.post-urlrequires anhttp://orhttps://URL. Anything else is rc=2.user-analysisnumeric args must be non-negative integers;time_rangemust beday|week|month|year|all. Invalid values return rc=2 (no silent "all" fallback).explainlower-cases and trims whitespace; hyphens are treated as spaces for glossary lookup. Empty / whitespace-only input is rc=2.
Required follow-up reads
| Need | Read | When |
| --- | --- | --- |
| Pick the right command and args for a Reddit query | reference.md (Endpoints) | Before invoking a new command |
| Reuse a known query shape | assets/query-templates.json | When the request matches a known template |
| Understand the compact JSON envelope or error shape | reference.md (Output shape / Errors) | When consuming structured output or stderr |
| Diagnose a network_security_block | SKILL.md (Failure handling) | When error.kind is network_security_block |
| Override User-Agent / base URL | .env.example | When changing HTTP identity or hitting a mirror |
| Future refactor concerns, expectations, and regression traps | references/future-refactor.md | You are planning a larger refactor or changing output/error contracts |
Notes
- Public JSON endpoints work anonymously for basic read-only use.
- Set a custom
REDDIT_USER_AGENTfor better hygiene and fewer blocks. - Reddit also has OAuth-backed APIs, but this skill intentionally stays on public JSON endpoints for low-friction read-only access.
- If you need authenticated/private/high-throughput access later, treat that as a separate OAuth feature instead of overloading this helper.
Query templates
See assets/query-templates.json.
Validation
uv run --script <skill-dir>/scripts/cli.py --help
Reference
See reference.md.
微信扫一扫