Home / All Skills / Content & Media Creation / canghe-danger-x-to-markdown
Content & Media Creation · freestylefly/canghe-skills

canghe-danger-x-to-markdown

Converts X (Twitter) tweets and articles to markdown with YAML front matter. Uses reverse-engineered API requiring user consent. Use when user mentions "X to markdown", "tweet to markdown", "save tweet", or provides x.com/twitter.com URLs for conversion.

L5 Restricted · Isolated sandbox & strict auditV2 Human-AuditedReverse APITerms / ComplianceCredential / SessionExecute CommandNetwork AccessWrite FileDual-pass Audit
Author freestyleflyGitHub freestylefly/canghe-skills ↗License MIT(仓库根 LICENSE)Commit dd0bf35595
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

Core mechanism relies on a reverse-engineered X API: SKILL.md states it uses a reverse-engineered X API to extract tweets, threads, and Articles into markdown.

skills/canghe-danger-x-to-markdown/SKILL.md
This tool uses a reverse-engineered X API, NOT official.
What it is doing: Instead of requesting official APIs, it scrapes directly using web client capabilities; the script entry point is scripts/main.ts, containing modules like graphql, cookies, media-localizer, etc.

Distinct extraction paths for three content types: Regular tweets and threads are converted into markdown with YAML front matter, while X Articles undergo full-text entity extraction.

skills/canghe-danger-x-to-markdown/SKILL.md
- Tweets/threads → Markdown with YAML front matter
What it is doing: The front matter includes url, author, tweetCount, and coverImage; Articles are parsed by resolveArticleEntityFromTweet in tweet-article.ts.

Implementation of Article full-text extraction: It first attempts to use the embedded article entity in the tweet; if unavailable, it parses the article id from the URL and fetches it independently via fetchXArticle.

skills/canghe-danger-x-to-markdown/scripts/tweet-article.ts
const fetched = await fetchXArticle(articleId, cookieMap, false);
What it is doing: extractArticleIdFromTweet extracts the ID from note_tweet/legacy URLs using the regex /\/(?:i\/)?article\/(\d+)/, then pulls the full text by ID.

Authentication relies on user account cookies: It prioritizes environment variables X_AUTH_TOKEN / X_CT0, falling back to Chrome login and local cookie caching.

skills/canghe-danger-x-to-markdown/SKILL.md
1. **Environment variables** (preferred): `X_AUTH_TOKEN`, `X_CT0`
What it is doing: cookies.ts handles loading from three sources and validating required items, spawning local Chrome (via child_process in the script) when necessary.

Retrieved cookies are persisted to cookies.json: cookie-file.ts writes JSON in the structure version/updatedAt/cookieMap, with paths resolved cross-platform by paths.ts.

skills/canghe-danger-x-to-markdown/scripts/cookie-file.ts
await writeFile(p, JSON.stringify(payload, null, 2), "utf8");
What it is doing: It defaults to the user data directory canghe-skills/x-to-markdown/cookies.json, which can be overridden via X_COOKIE_PATH.

Media localization is optional: Enabling --download-media downloads images/videos to imgs/ and videos/ alongside the markdown, rewriting links to relative paths.

skills/canghe-danger-x-to-markdown/SKILL.md
| `--download-media` | Download image/video assets to local `imgs/` and `videos/`, and rewrite markdown links to local relative paths |
What it is doing: Download logic resides in media-localizer.ts; remote URLs are preserved when this flag is not set.

Media processing defaults to "generate markdown first, ask later": It first runs without download parameters, asks only if remote media URLs remain in the output, and reruns to overwrite links upon confirmation.

skills/canghe-danger-x-to-markdown/SKILL.md
5. If user confirms → run script **again** with `--download-media` (overwrites markdown with localized links)
What it is doing: The three download_media states (ask/1/0) are specified by SKILL.md, while the script side only accepts the --download-media boolean flag.

EXTEND.md first-time setup is implemented as a blocking operation: When missing, it must interactively prompt for preferences (media policy, output directory, save location); silent defaults are prohibited.

skills/canghe-danger-x-to-markdown/SKILL.md
**CRITICAL**: When EXTEND.md is not found, you **MUST use `AskUserQuestion`** to ask the user for their preferences before creating EXTEND.md.
What it is doing: The detailed questionnaire and EXTEND.md template are stored separately in references/config/first-time-setup.md.

Reverse-engineering usage requires a consent gate: If the consent file is missing or versions mismatch, a disclaimer is displayed; if the user rejects it, an exit message is printed and execution stops.

skills/canghe-danger-x-to-markdown/SKILL.md
**Step 5**: On decline → output "User declined. Exiting." and stop.
What it is doing: The consent file contains accepted, acceptedAt, and disclaimerVersion, located at ~/.local/share/canghe-skills/x-to-markdown/consent.json.

Data directory is resolved per platform: paths.ts uses XDG_DATA_HOME (or ~/.local/share) on Linux, Application Support on macOS, and APPDATA on Windows.

skills/canghe-danger-x-to-markdown/scripts/paths.ts
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
What it is doing: Paths for cookies, consent, and chrome-profile are derived from the same data directory, each having an environment variable override key.

2Core Capabilities

01Single tweet/long thread → markdown
02X Article full-text extraction (embedded entity → fallback fetch by id)
03YAML front matter output (url/author/tweetCount/coverImage)
04Media localization (imgs/ and videos/ + link rewriting)
05Three-way cookie acquisition (env → local file → Chrome login) and --login refresh
06Consent gate and mandatory interactive first-time setup (consent.json + EXTEND.md questionnaire)
07--json structured output and -o custom output path
08Deterministic archive directory structure

3External Dependencies

KindDependency / Endpoint
networkx.com(登录流程与逆向 API 请求)
networkpbs.twimg.com(推文图片资源,出现在输出样例 coverImage)
clibun / npx(以 npx -y bun 运行脚本)
cli本机 Chrome/Chromium(回落到浏览器登录时 spawn 以取 cookie)

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 / 脚本: Calls undisclosed or reverse-engineered private APIs / spoofs client identifiers
  • SKILL.md / 脚本参数: Contains logic to bypass automation detection, disable host sandboxes, or skip SSL certificate validation
  • SKILL.md / 会话存储: Reads or reuses browser user session cookies and login states
  • 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: Account cookies: X_AUTH_TOKEN / X_CT0 (env prioritized), local cookies.json next, and finally via Chrome login retrieval (sk
  • scripts/: Executes local scripts or commands: scripts/main.ts (run via npx -y bun; spawns Chrome to read cookies during browser login fallback)
  • 网络端点: Declares external network access: https://x.com/home (login flow, X_LOGIN_URL in constants.ts)
  • 本地工作目录: File read/write and artifact output: x-to-markdown/{username}/{tweet-id}.md (or path specified by -o)
Audit Notes: (Classified as a capability/policy-level finding, not malicious injection). (a) Reverse engineering + official client impersonation: SKILL.md states it uses a reverse-engineered X API instead of the official API, where graphql.ts directly queries X's private endpoints authenticated with account cookies. (b) Credential surface: Reads and uses user account cookies X_AUTH_TOKEN/X_CT0 (from env, local cookie file, or falling back to Chrome login via cookies.ts read through CDP/browser); SKILL.md notes risks including "Possible account restrictions". (c) Command surface: The fallback path spawns local Chrome/Chromium to retrieve cookies. Scope qualification: No TLS verification downgrades detected, no anti-automation countermeasures detected, no targeted batch scraping, and no arbitrary code execution; media download only occurs with --download-media. Classification rationale is based on "reverse-engineered private endpoints + web client impersonation + private credentials".

5Second-Pass Verification

  • [ok] 逆向 API 而非官方 API(red 主因之一) — SKILL.md 有 DISCLAIMER「This tool uses a reverse-engineered X API, NOT official.」,并据此设 consent 门禁。
  • [ok] 读取账号 cookie(red 主因之二) — SKILL.md 列出环境变量 X_AUTH_TOKEN/X_CT0 为首选来源、Chrome 登录为兜底;cookies.ts 内含 child_process spawn。
  • [ok] 媒体下载范围受限 — --download-media 为显式开关,ask 流程要求先出 markdown 再询问,非默认批量下载。
  • [ok] 两道用户门禁 — consent.json(accepted + disclaimerVersion)与 EXTEND.md 首次设置(BLOCKING,禁止静默默认)均在 SKILL.md 写明。
  • [ok] 数据目录跨平台解析 — paths.ts 按 win32/darwin/其他分派 APPDATA / Application Support / XDG_DATA_HOME,并支持 X_DATA_DIR 等覆盖。
  • [unlocatable] GraphQL 与媒体模块内部实现 — graphql.ts / media-localizer.ts 正文未在证据包展开,仅依据 §1 文件清单与 §3 扫描行定位其存在与职责;未据此提升或降低档位。

6Verdict & Scenarios

  • Archive-friendly: Produces a consistent directory structure and YAML front matter, ideal for long-term X content archival or site generation.
  • Optional media localization: One-click saving of images and videos to local relative paths ensures offline archives keep all media.
  • Flexible credential retrieval: Supports env variables, local cookie files, and browser login, making it viable for both CI and local setups.
  • Strict gating: Forces interactive confirmation for reverse-engineering disclaimers and initial preferences instead of silently using defaults.
  • Resilient Article extraction: Falls back to fetching independently by article id when embedded entities are missing.
  • Best for: Suitable for individuals doing content archiving or material collection: converting long threads and X Articles into searchable markdown (paired with --download-media for complete offline copies), or as an ingestion step before writing articles.
    Not for: Not suitable for corporate compliance environments or high-frequency usage on primary accounts; not suitable for batch collection requiring official support and stable SLAs (entry point takes a single URL, no batch mode); not suitable for scenarios where storing cookies, consent, or archive files on the local machine is undesirable.
    Install Agent-Ready
    ① Verified Mirror 2026-10-10
    Option A · Direct DownloadDownload canghe-danger-x-to-markdown.tar.gz
    sha256: f839fffff58e69c9…
    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 dd0bf35595.