Communitygithub.com

lovstudio/clash-tun-doctor-skill

Diagnose Clash TUN connectivity and direct-routing issues

clash-tun-doctor-skill 是什麼?

clash-tun-doctor-skill is a Claude Code agent skill that diagnose Clash TUN connectivity and direct-routing issues.

相容平台~Claude Code~Codex CLI~Cursor
npx skills add lovstudio/clash-tun-doctor-skill

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Clash TUN Doctor

Evidence-first diagnosis and reversible repair for application networking failures behind Clash Verge Rev TUN mode.

When to Use

  • An application works without TUN but fails, stalls, or loses media with TUN.
  • WeChat text works while image uploads or Moments images fail.
  • A rule change makes the symptom worse or the app remains stuck on Loading.
  • The subscription says ipv6: false, but runtime traffic still uses IPv6.
  • Clash logs contain no route to host, context deadline exceeded, or an unexpected rule/strategy for the affected process.

Do not use this skill for generic subscription acquisition, node purchasing, or bypassing organizational network policy.

Workflow (MANDATORY)

Step 0: Resolve the skill and Clash data directories

Resolve SKILL_DIR from the installed skill context. For manual execution:

export SKILL_DIR="/path/to/lovstudio-clash-tun-doctor"

The CLI resolves the Clash Verge Rev data directory in this order:

  1. --data-dir
  2. LOVSTUDIO_CLASH_TUN_DOCTOR_DATA_DIR
  3. macOS Clash Verge Rev default under ~/Library/Application Support/

Never hard-code a user's home directory.

Step 1: Diagnose before proposing a rule

Run the read-only command first:

python3 "$SKILL_DIR/scripts/clash_tun_doctor.py" diagnose --app wechat

Report concrete evidence from all available layers:

  • App-level config.yaml overrides.
  • Generated clash-verge.yaml top-level and DNS IPv6 values.
  • Runtime /configs, /rules, and /connections through Mihomo's Unix socket.
  • Recent service-log failures for the target application.

Treat screenshots and runtime state as truth. A rule saying DIRECT does not prove the connection succeeded.

Step 2: Choose the narrowest repair

Use references/troubleshooting.md to map evidence to a repair. For the proven WeChat pattern, use the built-in repair:

python3 "$SKILL_DIR/scripts/clash_tun_doctor.py" fix-wechat

This is a dry run. It previews:

  • Direct rules for the WeChat processes and media domains.
  • Disabling the app-level IPv6 override that can supersede subscription and extension settings.
  • The exact files that would be backed up and changed.

Do not route the whole application through a proxy merely because direct media failed. First check proxy health and IPv6 errors; a proxy timeout can turn one failed image into a fully stuck application.

Step 3: Apply only with user authorization

If the user explicitly asked to fix/apply, run:

python3 "$SKILL_DIR/scripts/clash_tun_doctor.py" fix-wechat --apply

The command must:

  1. Stop Clash Verge before editing its generated global settings.
  2. Create a timestamped backup and manifest.
  3. Set the global IPv6 override to false.
  4. Prepend persistent WeChat DIRECT rules in the current profile's rule file.
  5. Restart Clash Verge and verify final/runtime state.

If verification fails, report the backup path and do not claim success.

Step 4: Restart the affected application and verify the user path

Close stale connections or restart the affected application. Re-run diagnosis:

python3 "$SKILL_DIR/scripts/clash_tun_doctor.py" diagnose --app wechat --json

For the WeChat IPv6 failure, success requires all of the following:

  • Runtime ipv6 is false.
  • WeChat rules resolve to DIRECT.
  • New WeChat destinations are IPv4.
  • New logs no longer show WeChat no route to host errors.
  • The user can send an image and load Moments images.

Step 5: Roll back when needed

python3 "$SKILL_DIR/scripts/clash_tun_doctor.py" rollback --apply

Rollback restores the newest backup by default. Never delete backups automatically.

CLI Reference

Command / optionDefaultDescription
diagnoseRead configuration, runtime state, connections, and logs.
fix-wechatdry runPreview or apply the proven WeChat repair.
rollbackdry runPreview or restore the latest repair backup.
--data-dir PATHautoClash Verge Rev application data directory.
--socket PATH<data-dir>/mihomo.sock fallbackMihomo controller Unix socket; standard /tmp/verge/verge-mihomo.sock is auto-detected.
--app NAMEwechatApplication filter used by diagnosis.
--applyfalseAuthorize filesystem changes and restart/restore actions.
--no-restartfalseApply changes without restarting Clash Verge.
--jsonfalseEmit machine-readable diagnosis output.

Dependencies

Python 3.8+ standard library only.

相關技能