Skip to content

Instantly share code, notes, and snippets.

@miratcan
Created March 4, 2026 08:10
Show Gist options
  • Select an option

  • Save miratcan/f69b9a064bd930b17af9c74d4eb363cc to your computer and use it in GitHub Desktop.

Select an option

Save miratcan/f69b9a064bd930b17af9c74d4eb363cc to your computer and use it in GitHub Desktop.
Claude Code skill: auto-fetch Reddit posts as markdown (no API key needed)
name description
reddit-to-markdown
Fetch a Reddit post and its comments as structured markdown. Auto-triggers when the user's message contains a reddit.com URL pointing to a submission (e.g. /r/sub/comments/id/...). Example triggers: any message containing "reddit.com/r/*/comments/*".

Reddit to Markdown

When the user's message contains a Reddit submission URL, fetch it and render as markdown so the content is available in the conversation.

How it works

Reddit serves JSON for any page when you append .json to the URL. No API key, no auth, no browser needed.

Steps

  1. Extract the Reddit submission URL from the user's message.
  2. Normalize the URL: strip query params and trailing slashes, ensure it ends with .json.
  3. Fetch with curl:
    curl -s -H "User-Agent: reddit2md/1.0" "<url>.json"
    
  4. Parse the JSON and render markdown using this Python snippet (pipe curl output into it):
import json, sys

data = json.load(sys.stdin)

post = data[0]['data']['children'][0]['data']
lines = []
lines.append(f"# {post['title']}")
meta = f"**{post['subreddit_name_prefixed']}** | u/{post['author']} | {post['score']} pts ({int(post.get('upvote_ratio',0)*100)}% upvoted) | {post.get('num_comments',0)} comments"
lines.append(meta)
flair = post.get('link_flair_text', '')
if flair:
    lines.append(f"Flair: {flair}")
lines.append('')
if post.get('selftext'):
    lines.append(post['selftext'])
    lines.append('')
if post.get('url') and not post.get('is_self'):
    lines.append(f"Link: {post['url']}")
    lines.append('')

MAX_DEPTH = 5

def render_comments(children):
    result = []
    for child in children:
        if child['kind'] != 't1':
            continue
        d = child['data']
        depth = d.get('depth', 0)
        if depth > MAX_DEPTH:
            continue
        result.append(f"[depth:{depth}] **u/{d.get('author','[deleted]')}** ({d.get('score',0)} pts)")
        result.append(d.get('body', ''))
        result.append('')
        replies = d.get('replies', '')
        if isinstance(replies, dict):
            result.extend(render_comments(replies['data']['children']))
    return result

lines.append('---')
lines.append('## Comments')
lines.append('')
lines.extend(render_comments(data[1]['data']['children']))
print('\n'.join(lines))
  1. Present the markdown output to the user in the conversation.

Rate limiting

Reddit may rate-limit requests. If you get a 429 or empty response, wait a few seconds and retry once.

Performance tip

For faster repeated use, save the Python snippet above to a file:

# One-time setup
cat << 'EOF' > ~/.local/bin/reddit2md
#!/usr/bin/env python3
import json, sys

data = json.load(sys.stdin)
post = data[0]['data']['children'][0]['data']
lines = []
lines.append(f"# {post['title']}")
meta = f"**{post['subreddit_name_prefixed']}** | u/{post['author']} | {post['score']} pts ({int(post.get('upvote_ratio',0)*100)}% upvoted) | {post.get('num_comments',0)} comments"
lines.append(meta)
flair = post.get('link_flair_text', '')
if flair:
    lines.append(f"Flair: {flair}")
lines.append('')
if post.get('selftext'):
    lines.append(post['selftext'])
    lines.append('')
if post.get('url') and not post.get('is_self'):
    lines.append(f"Link: {post['url']}")
    lines.append('')

MAX_DEPTH = 5

def render_comments(children):
    result = []
    for child in children:
        if child['kind'] != 't1':
            continue
        d = child['data']
        depth = d.get('depth', 0)
        if depth > MAX_DEPTH:
            continue
        result.append(f"[depth:{depth}] **u/{d.get('author','[deleted]')}** ({d.get('score',0)} pts)")
        result.append(d.get('body', ''))
        result.append('')
        replies = d.get('replies', '')
        if isinstance(replies, dict):
            result.extend(render_comments(replies['data']['children']))
    return result

lines.append('---')
lines.append('## Comments')
lines.append('')
lines.extend(render_comments(data[1]['data']['children']))
print('\n'.join(lines))
EOF
chmod +x ~/.local/bin/reddit2md

Then use: curl -s -H "User-Agent: reddit2md/1.0" "<url>.json" | reddit2md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment