Home / All Skills / Content & Media Creation / baoyu-post-to-x
Content & Media Creation · JimLiu/baoyu-skills

baoyu-post-to-x

Posts content and articles to X (Twitter). Supports regular posts with images/videos and X Articles (long-form Markdown). In Codex, honor explicit requests for the Codex Chrome plugin/@chrome by using the Chrome Extension workflow; otherwise use Chrome Computer Use when available and fall back to real Chrome CDP scripts only when allowed. Use when user asks to "post to X", "tweet", "publish to Twitter", or "share on X".

L5 Restricted · Isolated sandbox & strict auditV2 Human-AuditedReverse APITerms / ComplianceCredential / SessionExecute CommandNetwork AccessWrite FileDual-pass Audit
Author JimLiuGitHub JimLiu/baoyu-skills ↗Stars 25926License MIT(仓库根 LICENSE:Copyright (c) 2026 Jim Liu;根 package.json 同声明 "license": "MIT")Commit 1567581c26
Control levels describe skill capabilities and suggested control measures; they do not represent quality or safety certifications, nor do they dictate usability. Usage decisions rest entirely with users and administrators. Different agent hosts apply varying constraints; do not assume hosts provide automatic protection. Third-party skill copyrights belong to their original authors. Use at your own risk.

1How It Works & Mechanism

Instead of using Playwright/Puppeteer, it drives a real Chrome instance (via CDP connection) so that X perceives a standard browser session; scripts populate content into the real UI, leaving the publish action to the user or an explicit --submit flag.

README.md
Uses real Chrome with CDP to bypass anti-automation.
What is happening here: The README explicitly states this approach is designed to bypass the platform's anti-automation detection; the implementation relies on chrome-launcher + shared profile + CDP session (connecting to the browser's debugging port).

The primary method for attaching images is not CDP synthetic events, but genuine system-level Cmd+V keystrokes: images are first written to the system clipboard, and osascript/xdotool/ydotool sends paste keystrokes to the Chrome window, with CDP synthetic events serving only as a fallback.

skills/baoyu-post-to-x/references/regular-posts.md
Sends real Cmd+V keystroke to Chrome, bypassing CDP's synthetic events that X can detect
The motivation is explicitly stated in the documentation: 'This approach bypasses X's anti-automation detection that blocks Playwright/Puppeteer.'; the top comment in paste-from-clipboard.ts repeats the same rationale.

Regular posts, video posts, quotes, and long-form articles share the same underlying Chrome layer: resolving or reusing the debugging port, sharing profiles, injecting text via execCommand('insertText') or Input.insertText, and uploading files by directly passing paths via DOM.setFileInputFiles.

skills/baoyu-post-to-x/scripts/x-browser.ts
const X_COMPOSE_URL = 'https://x.com/compose/post';
The long-form article path also converts Markdown to HTML, replaces embedded images with XIMGPH_n placeholders, and locates each placeholder to insert images sequentially (as the X Articles editor does not accept clipboard image pastes).

Publishing is non-automated by default: scripts stop after populating content and prompt for manual review and submission; clicking tweetButton / publishButton occurs only when --submit is explicitly provided.

skills/baoyu-post-to-x/scripts/x-browser.ts
Post composed. Please review and click the publish button in the browser.
SKILL.md enforces a strict policy: under no circumstances should Publish/Post be clicked without explicit user confirmation during the current turn.

The credential surface relies on X session cookies: cookies for x.com/twitter.com are read via CDP Network.getCookies, asserting only that auth_token and ct0 exist (values are neither printed nor persisted), with the credential store being the shared Chrome profile.

skills/baoyu-post-to-x/scripts/x-utils.ts
const REQUIRED_X_SESSION_COOKIES = ['auth_token', 'ct0'] as const;
Both the profile and debugging port can be overridden via environment variables (BAOYU_CHROME_PROFILE_DIR / X_BROWSER_PROFILE_DIR / X_BROWSER_DEBUG_PORT), and the Chrome executable path can be configured with X_BROWSER_CHROME_PATH.

Reusing an existing running Chrome instance is supported by design: it scans ps aux for processes sharing the same profile and --remote-debugging-port; if found, it connects directly without launching a new browser.

packages/baoyu-chrome-cdp/src/index.ts
line.includes(options.profileDir) && line.includes("--remote-debugging-port=")
The benefit is reusing already logged-in sessions for stability; the trade-off is taking over a debugging session that may actively be in use by the user (closing only the tabs opened by the script upon exit).

Cross-platform clipboard and keystroke adaptations are built-in: macOS uses inline Swift/AppKit for clipboard writing + osascript for keystrokes; Linux uses wl-copy/xclip + xdotool/ydotool; Windows uses PowerShell STA and SendKeys.

skills/baoyu-post-to-x/scripts/copy-to-clipboard.ts
await runCommand('swift', [swiftPath, 'image', imagePath]);
On macOS, inline Swift source code is written to a temporary directory and compiled on the fly to support writing rich text and images to the system clipboard.

Includes an active pre-check script: verifies Chrome availability, profile isolation, bun, accessibility permissions, clipboard round-trip, paste keystroke capability, and running Chrome process conflicts, exiting with code 1 on failure.

skills/baoyu-post-to-x/SKILL.md
Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, Chrome conflicts.
The profile isolation check is deliberate: it confirms the skill does not target the user's primary Chrome directory ('const isIsolated = !profileDir.startsWith(userChromeDir);') to prevent accidental modifications to the main profile.

2Core Capabilities

01Publish standard posts (text + up to 4 images)
02Publish video posts (MP4/MOV/WebM)
03Quote posts with custom comments
04Publish X Articles (Markdown → HTML conversion, with cover and inline image placeholder workflow)
05Native keystroke pasting (bypassing synthetic events) and clipboard writes (images / rich HTML)
06Reuse active logged-in Chrome sessions (scanning ps aux for ports / attaching to existing debug sessions)
07Human-in-the-loop verification before publishing (no auto-publishing by default; requires explicit --submit)
08Environment pre-flight checks (Chrome/permissions/clipboard/keystrokes/conflicts) and cross-platform support (macOS/Linux/WSL/Windows)

3External Dependencies

KindDependency / Endpoint
clinpx -y bun(跑同目录兄弟脚本与自身)
cliosascript(macOS:激活 Chrome、发送 Cmd+V)
cliswift(macOS:编译内联 AppKit 剪贴板源码)
clixdotool / ydotool(Linux X11/Wayland 粘贴键)
clipowershell.exe / cmd.exe / wslpath(Windows 与 WSL 路径与键击)
clips aux / pgrep / which / where(进程与工具探测)
cli真实 Chrome/Chromium/Edge 二进制(以 CDP 参数启动)
networkX 发帖页与长文编辑器
network本地 Chrome DevTools 端点(HTTP 探测 + WebSocket CDP)
networkmarkdown 里引用的任意 http(s) 图片会被下载到本地临时目录(经 baoyu-md)
packagebaoyu-chrome-cdp / baoyu-md / front-matter / highlight.js / marked / remark-* / unified(scripts/package.json 声明)

4Recommended Governance & Evidence

Suggested Controls for Safe Operation
For Agent Runtime
Isolated environment, per-use explicit authorization
For Administrators
Strict authorization, full audit, compliance signoff
Evidence & Triggers (File Paths & Excerpts)
  • SKILL.md / 脚本: Invocation of undocumented or reverse-engineered private APIs / client fingerprint spoofing
  • SKILL.md / 脚本参数: Techniques to bypass anti-automation detection, disable host sandboxes, or ignore SSL certificate verification
  • SKILL.md / 会话存储: Reading or reusing browser user authentication states and session cookies
  • 本地凭据 / 浏览器配置: Reading user login cookies/sessions/keyrings: CDP Network.getCookies reads session cookies for x.com / twitter.com and asserts auth_token and ct0
  • scripts/: Executing local scripts or commands: ${BUN_X} {baseDir}/scripts/x-browser.ts|x-video.ts|x-quote.ts|x-article.ts
  • 网络端点: Declared external network access: https://x.com/compose/post and https://x.com/compose/articles (real browser navigation)
  • 本地工作目录: File I/O and artifact output: $TMPDIR/x-article-content.html (long-form article HTML) and $TMPDIR/x-article-images (temporary directory for article images)
Audit Notes: (Classified as a capability/policy-level assessment rather than malicious injection: no obfuscation, no hardcoded secrets, no exfiltration to unexpected destinations, no TLS/sandbox downgrades, and no unescaped interpolations). Three primary rationales: ① [Technical evasion of anti-automation detection] The README explicitly states its design purpose: 'Uses real Chrome with CDP to bypass anti-automation.' Implementation-wise, it prioritizes physical OS keystrokes over CDP synthetic events: 'Sends real Cmd+V keystroke to Chrome, bypassing CDP\'s synthetic events that X can detect'. Comments atop paste-from-clipboard.ts reiterate: 'This bypasses CDP\'s synthetic events which websites can detect and ignore.', reflected in pasteFromClipboard('Google Chrome', 5, 500) with CDP event fallbacks. ② [Credential footprint] Accesses auth_token and ct0 (REQUIRED_X_SESSION_COOKIES) for x.com/twitter.com via CDP Network.getCookies within a shared Chrome profile (overridable by environment variables), and scans ps aux for --remote-debugging-port to commandeer existing browser debugging sessions. ③ [External side-effects and process manipulation] When --submit is flagged, it automatically clicks tweetButton/publishButton to publish irreversible public posts under the user's account; SKILL.md additionally instructs executing pkill on Chrome debug processes when port conflicts arise. Unlike auto-commenter (which merely evades AI content detection), this tool directly circumvents platform-level bot detection, triggering the red-tier criteria for 'Anti-anti-scraping / Evasion'—in the same category as patchright in notebooklm-skill or client impersonation in baoyu-youtube-transcript.

5Second-Pass Verification

  • [ok] 反自动化侦测的绕过(判红主因) — README 'bypass anti-automation' + regular-posts.md 的 Cmd+V/合成事件两段 + paste-from-clipboard.ts 顶部注释互相印证;x-browser.ts 里 pasteFromClipboard('Google Chrome', 5, 500) 为首选,CDP 键事件为 fallback。
  • [ok] cookie 面边界:只经 CDP 读、不落盘 — x-utils.ts 经 Network.getCookies 取 x.com/twitter.com cookie 并在内存构建 map,仅断言 auth_token/ct0 存在;全目录 grep 未发现写入 cookie 文件或读取 Cookies SQLite('Cookies' 只出现在单测字面量里)。
  • [ok] 接管已运行调试会话 — packages/baoyu-chrome-cdp 通过 ps aux 匹配 profileDir + --remote-debugging-port 找端口并连接;x-utils.ts 也自行 spawnSync('ps', ['aux']) 做占用判定。
  • [ok] 发布动作默认关闭 — tweetButton/publishButton 的 click 都包在 --submit 分支内;未提交时脚本打印提示让用户自己在浏览器点发布;SKILL.md 另有『必须当轮明确确认』的硬规则。
  • [ok] 进程级动作(pkill) — SKILL.md 第 321 行给出 pkill -f "Chrome.*remote-debugging-port" …; sleep 2 的清理配方;该命令不在任何 TS 脚本内,需由 agent 执行——已写入 security.scripts_executed 与 risks。
  • [discrepancy] 文档与实现不一致(--disable-blink-features) — references/regular-posts.md 宣称 CDP 路线会用 --disable-blink-features=AutomationControlled 启动 Chrome,但 x-utils.ts 只传 extraArgs: ['--start-maximized'];该参数仅出现在 packages/baoyu-chrome-cdp/src/mermaid.ts 的无头渲染启动里。故『绕过』的实际手段是真实键击 + 真实浏览器,而非该启动参数。
  • [ok] 单测是否触碰网络/浏览器 — x-utils.test.ts 与 md-to-html.test.ts 均为纯函数/临时目录测试(锁文件判定、启动重试判定、cookie map、markdown 解析),无网络、无 Chrome 启动。
  • [ok] 档位复核(批4 终裁) — 按 Main 终裁与范式红档『反反爬/绕过』字面命中判 red(撤回先前的 orange);同时保留可减轻情节的说明:无 TLS/沙箱降级、无未转义插值、cookie 不落盘、发布默认关闭。

6Verdict & Scenarios

  • Strict gating on irreversible actions: populates content by default and waits for manual submission, only publishing automatically when --submit is set.
  • Comprehensive cross-platform desktop automation: tailored clipboard and keystroke implementations with retry mechanisms for macOS, Linux, WSL, and Windows.
  • Pre-flight diagnostics addressing real failure points: checks Chrome, profile isolation, accessibility permissions, clipboard round-trip, keystroke delivery, and process conflicts.
  • Meticulous long-form article handling: uses XIMGPH_n placeholders, toolbar Insert → Media uploads, and verifies placeholder clearance for each image.
  • Disciplined execution modes: strictly forbids silent fallbacks between the Chrome extension, Computer Use, and CDP workflows.
  • Best for: Ideal for personal use workflows with concrete content ready to publish, where users prefer manual review before submission: one-click drafting of long-form or media posts into the X editor, or explicit automated publishing via --submit; also well-suited for individuals seeking to reuse an authenticated Chrome instance while avoiding Playwright-style automation footprints.
    Not for: Not suitable for enterprise environments with strict compliance constraints or sensitivity to platform Terms of Service (due to technical evasion of anti-automation detection); not intended for unattended or fully autonomous workflows triggered by queries (due to risks of irreversible public actions); not supported in environments lacking desktop automation privileges (requires accessibility permissions, Swift compilation, or keystroke tools); not suitable for delegating third-party accounts or sessions to agent execution.
    Install Agent-Ready
    ① Verified Mirror 2026-09-15
    Option A · Direct DownloadDownload baoyu-post-to-x.tar.gz
    sha256: 83fb7a73416e3fe3…
    Option B · Copy Guide for Agent
    install.json
    Agents automatically download and verify mirrors from this JSON guide.
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit 1567581c26.