Operational Steps
- 确认输入参数完整
- 执行核心操作(参考本目录下的 scripts/ 或 references/)
- 验证输出符合契约
- 保存结果并报告
Pitfalls
-
-
Verification
-
-
-
-
1. 2. 3.
IO_CONTRACT
- input:
request: str, context: dict— 用户请求描述、上下文信息 - output:
result: dict — 技能执行结果(结构因技能而异)
对应原则:P2(机械原子暴露输入输出规范)
xurl — X (Twitter) API via the Official CLI
xurl is the X developer platform's official CLI for the X API. It supports shortcut commands for common actions AND raw curl-style access to any v2 endpoint. All commands return JSON to stdout.
Use this skill for:
- posting, replying, quoting, deleting posts
- searching posts and reading timelines/mentions
- liking, reposting, bookmarking
- following, unfollowing, blocking, muting
- direct messages
- media uploads (images and video)
- raw access to any X API v2 endpoint
- multi-app / multi-account workflows
This skill replaces the older xitter skill (which wrapped a third-party Python CLI). xurl is maintained by the X developer platform team, supports OAuth 2.0 PKCE with auto-refresh, and covers a substantially larger API surface.
Secret Safety (MANDATORY)
Critical rules when operating inside an agent/LLM session:
- Never read, print, parse, summarize, upload, or send
~/.xurlto LLM context. - Never ask the user to paste credentials/tokens into chat.
- The user must fill
~/.xurlwith secrets manually on their own machine. - Never recommend or execute auth commands with inline secrets in agent sessions.
- Never use
--verbose/-vin agent sessions — it can expose auth headers/tokens. - To verify credentials exist, only use:
xurl auth status.
Forbidden flags in agent commands (they accept inline secrets):
--bearer-token, --consumer-key, --consumer-secret, --access-token, --token-secret, --client-id, --client-secret
App credential registration and credential rotation must be done by the user manually, outside the agent session. After credentials are registered, the user authenticates with xurl auth oauth2 — also outside the agent session. Tokens persist to ~/.xurl in YAML. Each app has isolated tokens. OAuth 2.0 tokens auto-refresh.
Installation
Pick ONE method. On Linux, the shell script or go install are the easiest.
# Shell script (installs to ~/.local/bin, no sudo, works on Linux + macOS)
curl -fsSL https://raw.githubusercontent.com/xdevplatform/xurl/main/install.sh | bash
# Homebrew (macOS)
brew install --cask xdevplatform/tap/xurl
# npm
npm install -g @xdevplatform/xurl
# Go
go install github.com/xdevplatform/xurl@latest
Verify:
xurl --help
xurl auth status
If xurl is installed but auth status shows no apps or tokens, the user needs to complete auth manually — see the next section.
One-Time User Setup (user runs these outside the agent)
These steps must be performed by the user directly, NOT by the agent, because they involve pasting secrets. Direct the user to this block; do not execute it for them.
Create or open an app at https://developer.x.com/en/portal/dashboard
Set the redirect URI to
http://localhost:8080/callbackCopy the app's Client ID and Client Secret
Register the app locally (user runs this):
xurl auth apps add my-app --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRETAuthenticate (specify
--appto bind the token to your app):xurl auth oauth2 --app my-app(This opens a browser for the OAuth 2.0 PKCE flow.)
If X returns a
UsernameNotFounderror or 403 on the post-OAuth/2/users/melookup, pass your handle explicitly (xurl v1.1.0+):xurl auth oauth2 --app my-app YOUR_USERNAMEThis binds the token to your handle and skips the broken
/2/users/mecall.Set the app as default so all commands use it:
xurl auth default my-appVerify:
xurl auth status xurl whoami
After this, the agent can use any command below without further setup. OAuth 2.0 tokens auto-refresh.
Common pitfall: If you omit
--app my-appfromxurl auth oauth2, the OAuth token is saved to the built-indefaultapp profile — which has no client-id or client-secret. Commands will fail with auth errors even though the OAuth flow appeared to succeed. If you hit this, re-runxurl auth oauth2 --app my-appandxurl auth default my-app.
Quick Reference
| Action | Command |
|---|---|
| Post | xurl post "Hello world!" |
| Reply | xurl reply POST_ID "Nice post!" |
| Quote | xurl quote POST_ID "My take" |
| Delete a post | xurl delete POST_ID |
| Read a post | xurl read POST_ID |
| Search posts | xurl search "QUERY" -n 10 |
| Who am I | xurl whoami |
| Look up a user | xurl user @handle |
| Home timeline | xurl timeline -n 20 |
| Mentions | xurl mentions -n 10 |
| Like / Unlike | xurl like POST_ID / xurl unlike POST_ID |
| Repost / Undo | xurl repost POST_ID / xurl unrepost POST_ID |
| Bookmark / Remove | xurl bookmark POST_ID / xurl unbookmark POST_ID |
| List bookmarks / likes | xurl bookmarks -n 10 / xurl likes -n 10 |
| Follow / Unfollow | xurl follow @handle / xurl unfollow @handle |
| Following / Followers | xurl following -n 20 / xurl followers -n 20 |
| Block / Unblock | xurl block @handle / xurl unblock @handle |
| Mute / Unmute | xurl mute @handle / xurl unmute @handle |
| Send DM | xurl dm @handle "message" |
| List DMs | xurl dms -n 10 |
| Upload media | xurl media upload path/to/file.mp4 |
| Media status | xurl media status MEDIA_ID |
| List apps | xurl auth apps list |
| Remove app | xurl auth apps remove NAME |
| Set default app | xurl auth default APP_NAME [USERNAME] |
| Per-request app | xurl --app NAME /2/users/me |
| Auth status | xurl auth status |
Notes:
POST_IDaccepts full URLs too (e.g.https://x.com/user/status/1234567890) — xurl extracts the ID.- Usernames work with or without a leading
@.
Command Details
Posting
xurl post "Hello world!"
xurl post "Check this out" --media-id MEDIA_ID
xurl post "Thread pics" --media-id 111 --media-id 222
xurl reply 1234567890 "Great point!"
xurl reply https://x.com/user/status/1234567890 "Agreed!"
xurl reply 1234567890 "Look at this" --media-id MEDIA_ID
xurl quote 1234567890 "Adding my thoughts"
xurl delete 1234567890
Reading & Search
xurl read 1234567890
xurl read https://x.com/user/status/1234567890
xurl search "golang"
xurl search "from:elonmusk" -n 20
xurl search "#buildinpublic lang:en" -n 15
Users, Timeline, Mentions
xurl whoami
xurl user elonmusk
xurl user @XDevelopers
xurl timeline -n 25
xurl mentions -n 20
Engagement
xurl like 1234567890
xurl unlike 1234567890
xurl repost 1234567890
xurl unrepost 1234567890
xurl bookmark 1234567890
xurl unbookmark 1234567890
xurl bookmarks -n 20
xurl likes -n 20
Social Graph
xurl follow @XDevelopers
xurl unfollow @XDevelopers
xurl following -n 50
xurl followers -n 50
# Another user's graph
xurl following --of elonmusk -n 20
xurl followers --of elonmusk -n 20
xurl block @spammer
xurl unblock @spammer
xurl mute @annoying
xurl unmute @annoying
Direct Messages
xurl dm @someuser "Hey, saw your post!"
xurl dms -n 25
Media Upload
# Auto-detect type
xurl media upload photo.jpg
xurl media upload video.mp4
# Explicit type/category
xurl media upload --media-type image/jpeg --category tweet_image photo.jpg
# Videos need server-side processing — check status (or poll)
xurl media status MEDIA_ID
xurl media status --wait MEDIA_ID
# Full workflow
xurl media upload meme.png # returns media id
xurl post "lol" --media-id MEDIA_ID
Raw API Access
The shortcuts cover common operations. For anything else, use raw curl-style mode against any X API v2 endpoint:
# GET
xurl /2/users/me
# POST with JSON body
xurl -X POST /2/tweets -d '{"text":"Hello world!"}'
# DELETE / PUT / PATCH
xurl -X DELETE /2/tweets/1234567890
# Custom headers
xurl -H "Content-Type: application/json" /2/some/endpoint
# Force streaming
xurl -s /2/tweets/search/stream
# Full URLs also work
xurl https://api.x.com/2/users/me
Global Flags
| Flag | Short | Description |
|---|---|---|
--app |
Use a specific registered app (overrides default) | |
--auth |
Force auth type: oauth1, oauth2, or app |
|
--username |
-u |
Which OAuth2 account to use (if multiple exist) |
--verbose |
-v |
Forbidden in agent sessions — leaks auth headers |
--trace |
-t |
Add X-B3-Flags: 1 trace header |
Streaming
Streaming endpoints are auto-detected. Known ones include:
/2/tweets/search/stream/2/tweets/sample/stream/2/tweets/sample10/stream
Force streaming on any endpoint with -s.
Output Format
All commands return JSON to stdout. Structure mirrors X API v2:
{ "data": { "id": "1234567890", "text": "Hello world!" } }
Errors are also JSON:
{ "errors": [ { "message": "Not authorized", "code": 403 } ] }
Common Workflows
Post with an image
xurl media upload photo.jpg
xurl post "Check out this photo!" --media-id MEDIA_ID
Reply to a conversation
xurl read https://x.com/user/status/1234567890
xurl reply 1234567890 "Here are my thoughts..."
Search and engage
xurl search "topic of interest" -n 10
xurl like POST_ID_FROM_RESULTS
xurl reply POST_ID_FROM_RESULTS "Great point!"
Check your activity
xurl whoami
xurl mentions -n 20
xurl timeline -n 20
Multiple apps (credentials pre-configured manually)
xurl auth default prod alice # prod app, alice user
xurl --app staging /2/users/me # one-off against staging
Error Handling
- Non-zero exit code on any error.
- API errors are still printed as JSON to stdout, so you can parse them.
- Auth errors → have the user re-run
xurl auth oauth2outside the agent session. - Commands that need the caller's user ID (like, repost, bookmark, follow, etc.) will auto-fetch it via
/2/users/me. An auth failure there surfaces as an auth error.
Agent Workflow
- Verify prerequisites:
xurl --helpandxurl auth status. - Check default app has credentials. Parse the
auth statusoutput. The default app is marked with▸. If the default app showsoauth2: (none)but another app has a valid oauth2 user, tell the user to runxurl auth default <that-app>to fix it. This is the most common setup mistake — the user added an app with a custom name but never set it as default, so xurl keeps trying the emptydefaultprofile. - If auth is missing entirely, stop and direct the user to the "One-Time User Setup" section — do NOT attempt to register apps or pass secrets yourself.
- Start with a cheap read (
xurl whoami,xurl user @handle,xurl search ... -n 3) to confirm reachability. - Confirm the target post/user and the user's intent before any write action (post, reply, like, repost, DM, follow, block, delete).
- Use JSON output directly — every response is already structured.
- Never paste
~/.xurlcontents back into the conversation.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Auth errors after successful OAuth flow | Token saved to default app (no client-id/secret) instead of your named app |
xurl auth oauth2 --app my-app then xurl auth default my-app |
unauthorized_client during OAuth |
App type set to "Native App" in X dashboard | Change to "Web app, automated app or bot" in User Authentication Settings |
UsernameNotFound or 403 on /2/users/me right after OAuth |
X not returning username reliably from /2/users/me |
Re-run xurl auth oauth2 --app my-app YOUR_USERNAME (xurl v1.1.0+) to pass the handle explicitly |
| 401 on every request | Token expired or wrong default app | Check xurl auth status — verify ▸ points to an app with oauth2 tokens |
client-forbidden / client-not-enrolled |
X platform enrollment issue | Dashboard → Apps → Manage → Move to "Pay-per-use" package → Production environment |
CreditsDepleted |
$0 balance on X API | Buy credits (min $5) in Developer Console → Billing |
media processing failed on image upload |
Default category is amplify_video |
Add --category tweet_image --media-type image/png |
| Two "Client Secret" values in X dashboard | UI bug — first is actually Client ID | Confirm on the "Keys and tokens" page; ID ends in MTpjaQ |
Notes
- Rate limits: X enforces per-endpoint rate limits. A 429 means wait and retry. Write endpoints (post, reply, like, repost) have tighter limits than reads.
- Scopes: OAuth 2.0 tokens use broad scopes. A 403 on a specific action usually means the token is missing a scope — have the user re-run
xurl auth oauth2. - Token refresh: OAuth 2.0 tokens auto-refresh. Nothing to do.
- Multiple apps: Each app has isolated credentials/tokens. Switch with
xurl auth defaultor--app. - Multiple accounts per app: Select with
-u / --username, or set a default withxurl auth default APP USER. - Token storage:
~/.xurlis YAML. Never read or send this file to LLM context. - Cost: X API access is typically paid for meaningful usage. Many failures are plan/permission problems, not code problems.
Attribution
- Upstream CLI: https://github.com/xdevplatform/xurl (X developer platform team, Chris Park et al.)
- Upstream agent skill: https://github.com/openclaw/openclaw/blob/main/skills/xurl/SKILL.md
- Hermes adaptation: reformatted for Hermes skill conventions; safety guardrails preserved verbatim.
验证清单 · VERIFICATION
-
xurl --help可执行且xurl auth status显示默认应用(▸标记)持有有效 oauth2 token - 命令未使用
--verbose/-v及任何内联密钥 flag(--bearer-token、--client-id等) - 会话中未读取、打印或解析
~/.xurl;OAuth 授权与凭证注册均由用户在 agent 会话外手动完成 - 执行写入操作(post/reply/like/repost/dm/follow/delete)前已确认目标帖子/用户及用户意图
- 命令输出为合法 JSON;错误返回非零退出码且解析
errors字段后能映射到 Troubleshooting 表中的修复项
约束规则 · RULES
- 输入约束: 参数类型、范围、格式必须校验
- 输出约束: 返回值结构、编码、命名必须一致
- 异常约束: 错误信息必须包含上下文和恢复建议
- 安全约束: 不执行未验证的任意代码,不暴露内部状态
Golden 集合 · GOLDEN SET
- Golden Input: 标准输入样本(覆盖正常路径)
- Golden Output: 预期输出(精确匹配或格式校验)
- Golden Error: 预期错误信息(覆盖失败路径)
Golden 集合是测试的单一真理来源。所有改进必须通过 golden 测试。
违反规则的操作视为不安全,必须拒绝或隔离。
每项验证必须可执行、可记录、可复现。验证失败时记录原因和修复。
示例 · EXAMPLES
Agent 会话前置检查(只读凭证状态)
- 输入: 会话开始,需确认 xurl 可用
- 操作: 仅运行
xurl --help与xurl auth status(不读~/.xurl,不用--verbose) - 验证: 默认应用(
▸标记)显示有效 oauth2 token;若为(none)提示用户执行xurl auth default <that-app>
发带图帖子的完整写入流
- 输入:
photo.jpg+ 文案,用户已确认意图 - 操作:
xurl media upload photo.jpg取得 MEDIA_ID →xurl post "Check out!" --media-id MEDIA_ID - 验证: 两条命令均返回合法 JSON(
data.id);图片报media processing failed时加--category tweet_image --media-type image/png
- 输入:
OAuth 后 403 的修复路径
- 输入: OAuth 流程成功但
/2/users/me报UsernameNotFound/403 - 操作: 指导用户(会话外)重跑
xurl auth oauth2 --app my-app YOUR_USERNAME显式传 handle - 验证:
xurl auth status中 token 绑定到具名应用而非空default配置;xurl whoami返回正确用户 JSON
- 输入: OAuth 流程成功但
Xurl
Genes (策略基因)
紧凑策略表示。条件→策略。需要深度时参考完整文档。
- [XURL-001] 在 Agent/LLM 会话中执行 xurl 命令 → 严禁使用
--verbose/-v或任何接受内联密钥的 Flag(如--bearer-token),以防止敏感凭证泄露至上下文 - [XURL-002] 需要验证用户凭证状态时 → 仅使用
xurl auth status命令,禁止读取、解析或打印~/.xurl文件内容 - [XURL-003] 执行 OAuth 2.0 认证流程时 → 必须指定
--app参数绑定特定应用,否则 Token 会存入无客户端密钥的默认配置导致后续命令鉴权失败 - [XURL-004] 遇到
UsernameNotFound错误或/2/users/me返回 403 时 → 在xurl auth oauth2命令中显式传入用户名参数以跳过损坏的用户查找调用 - [XURL-005] 处理帖子 ID 参数时 → 可直接传入完整 URL(如
https://x.com/user/status/...),xurl 会自动提取 ID,无需手动解析 - [XURL-006] 涉及应用注册、凭证轮换或初始 OAuth 授权时 → 指导用户在 Agent 会话外手动执行,严禁 Agent 代为执行涉及粘贴密钥的操作