agentleFS
yangwhaleyangwhale/CloseCrab/skills/vscode-reference/SKILL.md

vscode-reference

Skill5 starsChanged 3 months agoApache-2.0View on GitHub

Study Claude Code official source (CLI npm package) as golden reference for CloseCrab. Check updates, reverse-engineer patterns, distill improvements.

  • Installs packages

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Compaction: Default contextTokenThreshold = 100K (JZ7=1e5), configurable via autoCompactWindow

    line 117

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Claude Code Official Source — Golden Reference

Claude Code CLI 和 VS Code extension 共享同一套 JS 代码(@anthropic-ai/claude-code npm 包)。这是 CloseCrab 的 golden source。CloseCrab 的 IPC、stream 处理、控制流应尽可能对齐官方实现。

Architecture

                    Claude API (云端模型)
                          ↑
               Claude Code Core (JS 核心库)
               @anthropic-ai/claude-code
                          ↑
          ┌───────────────┼───────────────┐
          │               │               │
     Terminal UI      VS Code UI     socketpair IPC
     (同进程,无IPC)   (同代码+UI层)  (--input-fd/--output-fd)
     你敲 claude      VS Code 插件          ↑
                                      CloseCrab Bot
                                    (Discord/飞书 UI)

三者都是同一个 JS 核心库的不同前端。Terminal 是同进程直接调用,VS Code 和 CloseCrab 是子进程模式通过 socketpair 通信。

Code Locations

1. CLI npm 包 (Golden Source — 总是最新)

# 实际文件位置(跟随 nvm 路径)
GOLDEN_JS=$(dirname $(readlink -f $(which claude)))/cli.js

# 或直接
~/.nvm/versions/node/v20.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js
  • 安装/更新: npm install -g @anthropic-ai/claude-code(或 deploy.sh --npm)
  • 查版本: claude --version
  • 不需要 VS Code。CLI 就是最新代码。

2. VS Code Extension (可能过时,仅供参考)

ls -d ~/.vscode/extensions/anthropic.claude-code-* | sort -V | tail -1
  • 需要在 VS Code 界面手动点 Update,版本可能落后 CLI

3. GitHub / npm

  • Repo: github.com/anthropics/claude-code
  • npm: npmjs.com/package/@anthropic-ai/claude-code
  • Releases: gh release list -R anthropics/claude-code --limit 10

Workflow: Check for Updates

1. Version Comparison

# 当前安装的 CLI 版本
claude --version

# npm 上最新版本
npm info @anthropic-ai/claude-code version

# 最近 5 个 release
gh release list -R anthropics/claude-code --limit 5

2. Changelog Review

# 查看特定 release 的更新内容
gh release view -R anthropics/claude-code <TAG>

# 最近 10 个版本号
npm info @anthropic-ai/claude-code versions --json | python3 -c "import json,sys; v=json.load(sys.stdin); print('\n'.join(v[-10:]))"

3. Diff Key Patterns

用 golden source 对比 CloseCrab 实现:

GOLDEN_JS=$(dirname $(readlink -f $(which claude)))/cli.js
Areagrep patternCloseCrab File
IPC / socketpairinput-fd|output-fdworkers/claude_code.py
Stream JSONreadMessages|parseJSONworkers/claude_code.py
control_requestcontrol_request|control_response_reader_loop()
Result handling"result"|session_idsend()
Compactioncompact|compaction|contextTokenThresholdN/A (CLI-level)
Background tasksrun_in_background|task_notification_handle_background_event()
Process lifecyclespawn|kill|terminate|SIGTERMstart() / stop()
keep_alivekeep_alive_reader_loop()

Reverse Engineering Minified JS

cli.js 是 minified 的(变量名被 mangle),但字符串字面量保留原文。

Search Techniques

GOLDEN_JS=$(dirname $(readlink -f $(which claude)))/cli.js

# 搜索特定模式(字符串字面量不会被 mangle)
grep -oP '.{0,200}control_request.{0,200}' "$GOLDEN_JS" | head -5
grep -oP '.{0,200}keep_alive.{0,200}' "$GOLDEN_JS" | head -5

# 扩大上下文理解逻辑
grep -oP '.{0,500}PATTERN.{0,500}' "$GOLDEN_JS" | head -3

Known Patterns (from reverse engineering)

  • Stream reader: Async iterable class, line-delimited JSON from socket
  • Event routing: readMessages() routes by event type
  • Control handler: Immediate at reader level, never enqueued
  • Result consumer: First result event = end of turn, no system:init check
  • Compaction: Default contextTokenThreshold = 100K (JZ7=1e5), configurable via autoCompactWindow

CloseCrab Alignment Checklist

  • control_request handled at reader level (not enqueued)
  • keep_alive silently consumed at reader level
  • control_cancel_request logged and consumed at reader level
  • Result handling does NOT depend on system:init
  • Graceful stop uses SIGTERM before SIGKILL
  • Background events only handle task_notification and result
  • No polling/draining — continuous reader loop with asyncio.Queue

Key Lessons Learned

  1. 不检查 system:init。Claude CLI 可能合并 background task 和 user message 到一轮,只发一个 result。检查 system:init 会导致 stall。
  2. Control messages 永不入队。Reader level 立即处理,因为 CLI BLOCKS 等 control_response。入队 = 死锁。
  3. 不需要 buffer polling。连续 async reader loop,事件路由到 queue(active)或 background handler(idle)。
  4. Line-delimited JSON。每行一个完整 JSON。注意不完整行需要 buffer 到换行符。

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.