x-hacker-news
Fetch and analyze Hacker News content - the premier tech community for developers, AI researchers, and software engineers
IMPORTANT: Before using any x hn command, you MUST load x-cmd first: . ~/.x-cmd.root/X
Cost
[OK] Free - No API key required
Loading x-cmd
Not installed? -> Search and use the x-cmd skill to install x-cmd first
Installed? -> Load x-cmd:
CODEBLOCK0
Non-Interactive Usage
Use x hn for direct non-interactive calls:
CODEBLOCK1
Note: x hn is non-interactive, suitable for scripts and automation. For interactive browsing, use x hn after loading . ~/.x-cmd.root/X.
AI and Machine Learning Discussions
Filter top stories for AI/ML topics using x jq:
CODEBLOCK2
Programming and Development
Filter top stories for programming topics:
CODEBLOCK3
Software Engineering News
Get software engineering and tech industry discussions:
CODEBLOCK4
Story Lists
Get various story lists:
CODEBLOCK5
JSON Fields:
CODEBLOCK6
x jq Processing Examples:
CODEBLOCK7
Post Details
Get specific post details and comments:
CODEBLOCK8
Examples:
CODEBLOCK9
Note: Posts with many comments have large data size, consider limiting output or batch processing.
User Info
Get user information:
CODEBLOCK10
Examples:
CODEBLOCK11
Note: Active users have large data including all submission records, which may cause timeouts. Use x jq to limit output fields.
User hn-index
Calculate user influence metric:
CODEBLOCK12
Output Example:
CODEBLOCK13
Note: This command fetches all user submissions and may take time for active users.
Caching
x hn module has built-in caching:
CODEBLOCK14
Command Reference
| Command | Description | Output |
|---|
| INLINECODE7 | Top stories | JSON array |
| INLINECODE8 |
New stories | JSON array |
|
x hn best --json N,M | Best stories | JSON array |
|
x hn ask --json N,M | Ask HN posts | JSON array |
|
x hn show --json N,M | Show HN posts | JSON array |
|
x hn job --json N,M | Job postings | JSON array |
|
x hn item --json <id> | Post details | JSON object |
|
x hn user --json <name> | User info | JSON object |
|
x hn hidx <name> | hn-index | Plain text |
Dependencies
- - x-cmd (required): provides hn module
- x jq (optional): JSON processing via x-cmd
More: https://x-cmd.com/llms.txt
Entrance for AI agents.
x-hacker-news
获取并分析 Hacker News 内容——面向开发者、AI 研究人员和软件工程师的首选技术社区
重要提示:在使用任何 x hn 命令之前,必须先加载 x-cmd:. ~/.x-cmd.root/X
费用
[是] 免费 - 无需 API 密钥
加载 x-cmd
未安装? -> 搜索并使用 x-cmd 技能先安装 x-cmd
已安装? -> 加载 x-cmd:
bash
. ~/.x-cmd.root/X
非交互式使用
使用 x hn 进行直接的非交互式调用:
bash
获取热门故事的 JSON 数据
x hn top --json 1,10
获取特定帖子的详细信息
x hn item --json 43701153
注意: x hn 是非交互式的,适用于脚本和自动化。如需交互式浏览,请在加载 . ~/.x-cmd.root/X 后使用 x hn。
AI 与机器学习讨论
使用 x jq 过滤热门故事中的 AI/ML 主题:
bash
过滤热门故事中与 AI 相关的标题
x hn top --json 1,100 | x jq [.[] | select(.title | test(AI|artificial intelligence|machine learning|LLM|ChatGPT; i))]
过滤 LLM 和模型讨论
x hn top --json 1,100 | x jq [.[] | select(.title | test(GPT|Claude|Llama|neural|model; i))]
过滤 AI 安全与对齐讨论
x hn top --json 1,100 | x jq [.[] | select(.title | test(AI safety|alignment|AGI; i))]
编程与开发
过滤热门故事中的编程主题:
bash
过滤编程语言讨论
x hn top --json 1,100 | x jq [.[] | select(.title | test(Rust|Go|Python|TypeScript|JavaScript; i))]
过滤 Web 开发
x hn top --json 1,100 | x jq [.[] | select(.title | test(React|Vue|frontend|backend|web; i))]
过滤 DevOps 与基础设施
x hn top --json 1,100 | x jq [.[] | select(.title | test(Kubernetes|Docker|DevOps|cloud; i))]
过滤软件工程主题
x hn top --json 1,100 | x jq [.[] | select(.title | test(programming|coding|developer|software|GitHub|open source; i))]
软件工程新闻
获取软件工程与科技行业讨论:
bash
过滤创业与商业讨论
x hn top --json 1,100 | x jq [.[] | select(.title | test(startup|Y Combinator|funding|business; i))]
过滤职业与招聘主题
x hn top --json 1,100 | x jq [.[] | select(.title | test(hiring|interview|career|salary|remote; i))]
显示 Ask HN 帖子(通常涉及职业/商业讨论)
x hn ask --json 1,20
显示 Show HN 帖子(新项目/工具)
x hn show --json 1,20
故事列表
获取各种故事列表:
bash
获取热门故事(第 1-10 条)
x hn top --json 1,10
获取第 11-20 条
x hn top --json 11,20
其他类型
x hn new --json 1,10
x hn best --json 1,10
x hn ask --json 1,10
x hn show --json 1,10
x hn job --json 1,10
JSON 字段:
json
{
by: username, // 作者
descendants: 161, // 评论数
id: 47392084, // 帖子 ID
kids: [47393177, ...], // 评论 ID 列表
score: 582, // 分数/点赞数
time: 1773609736, // Unix 时间戳(秒)
title: Post Title, // 标题
type: story, // 类型(story/job 等)
url: https://... // URL
}
x jq 处理示例:
bash
提取标题和 URL
x hn top --json 1,10 | x jq -r .[] | \(.title)\t\(.url)
计算平均分数
x hn top --json 1,30 | x jq [.[].score] | add / length
按分数排序
x hn top --json 1,50 | x jq -r .[] | \(.score)\t\(.title) | sort -rn | head -10
热门域名统计
x hn top --json 1,100 | x jq -r .[].url // empty | \
sed -E s|https?://||; s|/.*|| | sort | uniq -c | sort -rn | head -10
格式化简报输出
x hn top --json 1,5 | x jq -r .[] | \n[\(.score) points] \(.title)\nAuthor: @\(.by) | Comments: \(.descendants)\n\(.url)\n
仅过滤 AI 相关故事
x hn top --json 1,100 | x jq [.[] | select(.title | test(AI|artificial intelligence|machine learning|LLM|ChatGPT; i))]
过滤编程故事
x hn top --json 1,100 | x jq [.[] | select(.title | test(programming|coding|developer|software|GitHub; i))]
帖子详情
获取特定帖子的详细信息和评论:
bash
x hn item --json
示例:
bash
获取帖子详情
x hn item --json 47392084 | x jq .[0] | {id, title, by, score, descendants, url}
获取评论 ID 列表(前 20 条)
COMMENT_IDS=$(x hn item --json 47392084 | x jq .[0].kids[:20] | .[])
获取每条评论内容(注意:每次请求需要时间)
for cid in $COMMENT_IDS; do
x hn item --json $cid | x jq -r [.by, .text[0:100]] | @tsv
done
注意: 评论多的帖子数据量较大,建议限制输出或分批处理。
用户信息
获取用户信息:
bash
x hn user --json
示例:
bash
获取关键用户字段(限制活跃用户的输出)
x hn user --json dang | x jq {id, created, karma, submitted: (.submitted | length)}
提取用户资料
x hn user --json dang | x jq {
username: .id,
created: .created,
karma: .karma,
about: (.about[0:200] // )
}
注意: 活跃用户的数据量较大,包含所有提交记录,可能导致超时。请使用 x jq 限制输出字段。
用户 hn-index
计算用户影响力指标:
bash
x hn hidx
输出示例:
hn-index: 42
注意: 该命令会获取用户的所有提交,对于活跃用户可能需要较长时间。
缓存
x hn 模块内置缓存功能:
bash
查看缓存配置
x hn cfg cat
默认缓存时间
- 故事数据:60 分钟
- 索引数据:30 分钟
- 缓存目录:~/.x-cmd.root/local/cache/hn/
命令参考
| 命令 | 描述 | 输出 |
|---|
| x hn top --json N,M | 热门故事 | JSON 数组 |
| x hn new --json N,M |
最新故事 | JSON 数组 |
| x hn best --json N,M | 最佳故事 | JSON 数组 |
| x hn ask --json N,M | Ask HN 帖子 | JSON 数组 |
| x hn show --json N,M | Show HN 帖子 | JSON 数组 |
| x hn job --json