reddit-cli
A command-line interface for browsing and posting to Reddit, built in Rust. Provides commands for browsing subreddits, searching posts, reading post details with comment trees, viewing user profiles, fetching comments, and submitting text posts.
Prerequisites
- Rust (1.80+ for
LazyLocksupport) - A Reddit account
- Reddit API credentials (OAuth2 "script" app)
Setup
1. Create a Reddit App
- Go to Reddit App Preferences.
- Click "create another app..." at the bottom.
- Fill in:
- name:
reddit-cli(or any name) - type: select script
- redirect uri:
http://localhost:8080
- name:
- Click "create app".
- Note the client ID (string under the app name) and the client secret.
Note: Password-based OAuth does not work with accounts that have two-factor authentication (2FA) enabled. Use an account without 2FA or disable it temporarily.
2. Configure Credentials
Edit .env with your credentials:
REDDIT_CLIENT_ID=your_client_id
REDDIT_CLIENT_SECRET=your_client_secret
REDDIT_USERNAME=your_reddit_username
REDDIT_PASSWORD=your_reddit_password
3. Build
The binary will be at target/release/reddit-cli.
Usage
Browse a Subreddit
Fetch posts from a subreddit with a given sort order.
| Option | Short | Default | Description |
|---|---|---|---|
--sort |
-s |
hot |
Sort order: hot, new, top, rising, controversial |
--limit |
-l |
25 |
Number of posts to fetch (1-100) |
--time |
-t |
day |
Time filter for top/controversial: hour, day, week, month, year, all |
Examples:
# Hot posts from r/rust
# Top posts from r/programming this week
# New posts from r/linux
Search Reddit
Search across all of Reddit or within a specific subreddit.
| Option | Short | Default | Description |
|---|---|---|---|
--subreddit |
-r |
Restrict search to a subreddit | |
--sort |
-s |
relevance |
Sort order: relevance, hot, top, new, comments |
--limit |
-l |
25 |
Number of results (1-100) |
--time |
-t |
all |
Time filter: hour, day, week, month, year, all |
Examples:
# Search all of Reddit
# Search within a subreddit
# Recent results only
View a Post
Get a post's full details including its comment tree.
The post_id argument accepts:
- A bare post ID (e.g.,
abc123) - A full Reddit URL (e.g.,
https://www.reddit.com/r/rust/comments/abc123/...) - A short URL (e.g.,
https://redd.it/abc123)
| Option | Short | Default | Description |
|---|---|---|---|
--depth |
-d |
3 |
Maximum depth of nested comment replies (0-10) |
--limit |
-l |
50 |
Maximum number of top-level comments (1-200) |
Examples:
# View a post by ID
# View with deeper comment nesting
# View from a full URL
View a User Profile
Get a user's profile information with optional recent posts and comments.
| Option | Short | Default | Description |
|---|---|---|---|
--posts |
-p |
false |
Include the user's recent posts |
--comments |
-c |
false |
Include the user's recent comments |
Examples:
# Basic profile info
# Profile with recent posts and comments
# Just recent comments
View Comments
Fetch comments from a post with a specific sort order. Similar to post but focuses only on the comment tree.
| Option | Short | Default | Description |
|---|---|---|---|
--sort |
-s |
best |
Sort order: best, top, new, controversial, old, qa |
--limit |
-l |
50 |
Maximum number of comments (1-200) |
Examples:
# Best comments
# Top comments, limited to 10
# Newest comments from a URL
Submit a Post
Submit a text post to a subreddit.
| Option | Short | Default | Description |
|---|---|---|---|
--title |
-t |
Post title (required, max 300 characters) | |
--body |
-b |
"" |
Post body text |
Examples:
# Submit a text post
# Submit a title-only post
Output Format
Posts are displayed as a numbered list with metadata:
[1] Title of the post
r/subreddit | u/author | 1,234 pts (95%) | 56 comments | 2h ago
https://reddit.com/r/subreddit/comments/abc123
Comments are displayed as an indented tree:
u/author | 42 pts | 3h ago
Comment body text...
u/reply_author | 10 pts | 2h ago
Reply body text...
User profiles show account stats:
u/username
Account age: 5y | Link karma: 12,345 | Comment karma: 67,890
Project Structure
src/
main.rs -- CLI definition with clap, subcommand dispatch
client.rs -- Reddit OAuth client with token caching
models.rs -- Serde types for Reddit API responses
validation.rs -- Input validation with compiled regexes
format.rs -- Colored terminal output formatting
commands/
browse.rs -- Browse subreddit posts
search.rs -- Search Reddit
post.rs -- View post with comments
user.rs -- View user profile and activity
comments.rs -- View comments from a post
submit.rs -- Submit a text post
License
MIT