Communitygithub.com

Plankton 程式碼品質技能

使用 Plankton 實現寫入時程式碼品質強制 — 在每次檔案編輯時透過掛鉤自動格式化、進行 lint 檢查,並由 Claude 修復問題。適用於設定寫入時的格式化、lint 檢查或自動修復掛鉤。

Plankton 程式碼品質技能 是什麼?

Plankton 是一個專為 Claude Code 設計的寫入時程式碼品質強制系統。它會在每次檔案編輯後,透過 PostToolUse 掛鉤自動執行格式化與 lint 工具(例如 ruff、biome、shellcheck 等)。當檢查發現違規時,Plankton 不會直接中斷工作流程,而是會自動生成 Claude 子程序來修復這些問題。該系統採用三階段架構:第一階段進行靜默自動格式化,第二階段收集無法自動修復的違規並轉換為結構化 JSON,第三階段則根據違規的複雜度(風格、邏輯或型別)自動路由給最合適的 Claude 模型(Haiku、Sonnet 或 Opus)進行修復。Plankton 還內建了設定檔保護機制,防止 LLM 修改 linter 設定檔來逃避檢查。支援多種語言,包括 Python、TypeScript、Shell、YAML、JSON、TOML、Markdown 與 Dockerfile,並可與 ECC 等其他工具搭配使用。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/plankton-code-quality

在你喜歡的 AI 中提問

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

說明文件

Plankton 程式碼品質技能 是做什麼的?

Plankton(致謝:@alxfazio)的整合參考,這是一個專為 Claude Code 設計的寫入時程式碼品質強制系統。Plankton 會在每次檔案編輯後透過 PostToolUse 掛鉤執行格式化與 lint 工具,然後生成 Claude 子程序來修復代理未捕捉到的違規。

使用時機

  • 你希望在每次檔案編輯時(而不僅是在提交時)自動進行格式化與 lint 檢查
  • 你需要防止代理修改 linter 設定檔來繞過檢查,而不是真正修復程式碼
  • 你需要分層模型路由來修復問題(Haiku 處理簡單風格,Sonnet 處理邏輯,Opus 處理型別)
  • 你同時使用多種語言(Python、TypeScript、Shell、YAML、JSON、TOML、Markdown、Dockerfile)

運作原理

三階段架構

每次 Claude Code 編輯或寫入檔案時,Plankton 的 multi_linter.sh PostToolUse 掛鉤就會執行:

階段 1:自動格式化(靜默)
├─ 執行格式化工具(ruff format、biome、shfmt、taplo、markdownlint)
├─ 靜默修復 40-50% 的問題
└─ 不向主代理輸出

階段 2:收集違規(JSON)
├─ 執行 lint 工具並收集無法修復的違規
├─ 返回結構化 JSON:{line, column, code, message, linter}
└─ 仍不向主代理輸出

階段 3:委派 + 驗證
├─ 生成 claude -p 子程序並傳入違規 JSON
├─ 根據違規複雜度路由到對應模型層級:
│   ├─ Haiku:格式化、匯入、風格(E/W/F 程式碼)— 120 秒超時
│   ├─ Sonnet:複雜度、重構(C901、PLR 程式碼)— 300 秒超時
│   └─ Opus:型別系統、深度推理(unresolved-attribute)— 600 秒超時
├─ 重新執行階段 1+2 以驗證修復
└─ 若無違規則退出 0,若有殘留違規則退出 2(報告給主代理)

主代理所見

情境代理所見掛鉤退出碼
無違規無0
子程序全部修復無0
子程序修復後仍有違規[hook] N 個違規殘留2
建議(重複、過時工具)[hook:advisory] ...0

主代理只會看到子程序無法修復的問題。大多數品質問題都會被透明地處理。

設定檔保護(防止繞過規則)

LLM 會修改 .ruff.toml 或 biome.json 來停用規則,而不是修復程式碼。Plankton 透過三層機制來阻止此行為:

  1. PreToolUse 掛鉤 — protect_linter_configs.sh 在編輯發生前就阻止對所有 linter 設定檔的修改
  2. Stop 掛鉤 — stop_config_guardian.sh 在工作階段結束時透過 git diff 偵測設定檔變更
  3. 受保護檔案清單 — .ruff.toml、biome.json、.shellcheckrc、.yamllint、.hadolint.yaml 等

套件管理器強制

一個用於 Bash 的 PreToolUse 掛鉤會封鎖舊版套件管理器:

  • pip、pip3、poetry、pipenv → 已封鎖(請使用 uv)
  • npm、yarn、pnpm → 已封鎖(請使用 bun)
  • 允許的例外:npm audit、npm view、npm publish

設定

快速開始

注意: Plankton 需要從其儲存庫手動安裝。安裝前請先檢視程式碼。

# 安裝核心相依套件
brew install jaq ruff uv

# 安裝 Python linter
uv sync --all-extras

# 啟動 Claude Code — 掛鉤會自動啟用
claude

無需安裝指令,也無需外掛設定。當您在 Plankton 目錄中執行 Claude Code 時,.claude/settings.json 中的掛鉤會自動被載入。

專案整合

若要在您自己的專案中使用 Plankton 掛鉤:

  1. 將 .claude/hooks/ 目錄複製到您的專案中
  2. 複製 .claude/settings.json 掛鉤設定
  3. 複製 linter 設定檔(.ruff.toml、biome.json 等)
  4. 為您的語言安裝對應的 linter

語言特定相依套件

語言必要選用
Pythonruff、uvty(型別)、vulture(死碼)、bandit(安全)
TypeScript/JSbiomeoxlint、semgrep、knip(未使用的匯出)
Shellshellcheck、shfmt—
YAMLyamllint—
Markdownmarkdownlint-cli2—
Dockerfilehadolint(>= 2.12.0)—
TOMLtaplo—
JSONjaq—

與 ECC 搭配

互補,而非重疊

關注點ECCPlankton
程式碼品質強制PostToolUse 掛鉤(Prettier、tsc)PostToolUse 掛鉤(20+ 個 linter + 子程序修復)
安全掃描AgentShield、安全審查代理Bandit(Python)、Semgrep(TypeScript)
設定檔保護—PreToolUse 封鎖 + Stop 掛鉤偵測
套件管理器偵測 + 設定強制(封鎖舊版 PM)
CI 整合—用於 git 的 Pre-commit 掛鉤
模型路由手動(/model opus)自動(違規複雜度 → 層級)

建議組合

  1. 安裝 ECC 作為您的外掛(代理、技能、指令、規則)
  2. 新增 Plankton 掛鉤用於寫入時品質強制
  3. 使用 AgentShield 進行安全審計
  4. 使用 ECC 的驗證迴圈作為 PR 前的最終關卡

避免掛鉤衝突

如果同時執行 ECC 和 Plankton 掛鉤:

  • ECC 的 Prettier 掛鉤與 Plankton 的 biome 格式化工具可能在 JS/TS 檔案上衝突
  • 解決方案:使用 Plankton 時停用 ECC 的 Prettier PostToolUse 掛鉤(Plankton 的 biome 更全面)
  • 兩者可以在不同檔案類型上共存(ECC 處理 Plankton 未涵蓋的部分)

設定參考

Plankton 的 .claude/hooks/config.json 控制所有行為:

{
  "languages": {
    "python": true,
    "shell": true,
    "yaml": true,
    "json": true,
    "toml": true,
    "dockerfile": true,
    "markdown": true,
    "typescript": {
      "enabled": true,
      "js_runtime": "auto",
      "biome_nursery": "warn",
      "semgrep": true
    }
  },
  "phases": {
    "auto_format": true,
    "subprocess_delegation": true
  },
  "subprocess": {
    "tiers": {
      "haiku":  { "timeout": 120, "max_turns": 10 },
      "sonnet": { "timeout": 300, "max_turns": 10 },
      "opus":   { "timeout": 600, "max_turns": 15 }
    },
    "volume_threshold": 5
  }
}

重要設定:

  • 停用您不使用的語言以加快掛鉤速度
  • volume_threshold — 違規數超過此值時會自動升級到更高模型層級
  • subprocess_delegation: false — 完全跳過階段 3(僅回報違規)

環境變數覆寫

變數用途
HOOK_SKIP_SUBPROCESS=1跳過階段 3,直接回報違規
HOOK_SUBPROCESS_TIMEOUT=N覆寫層級超時
HOOK_DEBUG_MODEL=1記錄模型選擇決策
HOOK_SKIP_PM=1繞過套件管理器強制

參考資料

  • Plankton(致謝:@alxfazio)
  • Plankton REFERENCE.md — 完整架構文件(致謝:@alxfazio)
  • Plankton SETUP.md — 詳細安裝指南(致謝:@alxfazio)

ECC v1.8 新增功能

可複製的掛鉤設定檔

設定嚴格的品質行為:

export ECC_HOOK_PROFILE=strict
export ECC_QUALITY_GATE_FIX=true
export ECC_QUALITY_GATE_STRICT=true

語言關卡表

  • TypeScript/JavaScript:優先使用 Biome,備用為 Prettier
  • Python:Ruff format/check
  • Go:gofmt

設定檔防篡改

在品質強制期間,標記同一迭代中對設定檔的變更:

  • biome.json、.eslintrc*、prettier.config*、tsconfig.json、pyproject.toml

若修改設定檔以壓制違規,則需在合併前進行明確審查。

CI 整合模式

在 CI 中使用與本地掛鉤相同的指令:

  1. 執行格式化檢查
  2. 執行 lint/型別檢查
  3. 在嚴格模式下快速失敗
  4. 發布修復摘要

健康指標

追蹤:

  • 被關卡標記的編輯數
  • 平均修復時間
  • 按類別統計的重複違規
  • 因關卡失敗而導致的合併阻斷

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能