plankton-code-quality
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlankton Code Quality Skill
Plankton 代码质量 Skill
Integration reference for Plankton (credit: @alxfazio), a write-time code quality enforcement system for Claude Code. Plankton runs formatters and linters on every file edit via PostToolUse hooks, then spawns Claude subprocesses to fix violations the agent didn't catch.
Plankton(致谢:@alxfazio)的集成参考文档,这是一款面向Claude Code的编写时代码质量管控系统。Plankton通过PostToolUse钩子在每次文件编辑时运行格式化工具与代码检查工具,随后启动Claude子进程修复Agent未发现的问题。
When to Use
适用场景
- You want automatic formatting and linting on every file edit (not just at commit time)
- You need defense against agents modifying linter configs to pass instead of fixing code
- You want tiered model routing for fixes (Haiku for simple style, Sonnet for logic, Opus for types)
- You work with multiple languages (Python, TypeScript, Shell, YAML, JSON, TOML, Markdown, Dockerfile)
- 希望在每次文件编辑时自动格式化与代码检查(而非仅在提交时)
- 需要防止Agent修改代码检查工具配置以绕过规则,而非修复代码
- 希望根据问题复杂度分层路由模型进行修复(Haiku处理简单样式问题,Sonnet处理逻辑问题,Opus处理类型问题)
- 涉及多语言开发(Python、TypeScript、Shell、YAML、JSON、TOML、Markdown、Dockerfile)
How It Works
工作原理
Three-Phase Architecture
三阶段架构
Every time Claude Code edits or writes a file, Plankton's PostToolUse hook runs:
multi_linter.shPhase 1: Auto-Format (Silent)
├─ Runs formatters (ruff format, biome, shfmt, taplo, markdownlint)
├─ Fixes 40-50% of issues silently
└─ No output to main agent
Phase 2: Collect Violations (JSON)
├─ Runs linters and collects unfixable violations
├─ Returns structured JSON: {line, column, code, message, linter}
└─ Still no output to main agent
Phase 3: Delegate + Verify
├─ Spawns claude -p subprocess with violations JSON
├─ Routes to model tier based on violation complexity:
│ ├─ Haiku: formatting, imports, style (E/W/F codes) — 120s timeout
│ ├─ Sonnet: complexity, refactoring (C901, PLR codes) — 300s timeout
│ └─ Opus: type system, deep reasoning (unresolved-attribute) — 600s timeout
├─ Re-runs Phase 1+2 to verify fixes
└─ Exit 0 if clean, Exit 2 if violations remain (reported to main agent)每当Claude Code编辑或写入文件时,Plankton的 PostToolUse钩子会启动运行:
multi_linter.shPhase 1: Auto-Format (Silent)
├─ Runs formatters (ruff format, biome, shfmt, taplo, markdownlint)
├─ 静默修复40-50%的问题
└─ 不向主Agent输出任何内容
Phase 2: Collect Violations (JSON)
├─ 运行代码检查工具并收集无法自动修复的问题
├─ 返回结构化JSON数据:{line, column, code, message, linter}
└─ 仍不向主Agent输出任何内容
Phase 3: Delegate + Verify
├─ 启动claude -p子进程并传入问题JSON数据
├─ 根据问题复杂度路由至对应模型层级:
│ ├─ Haiku:格式化、导入、样式问题(E/W/F类代码)——超时时间120秒
│ ├─ Sonnet:复杂度、重构问题(C901、PLR类代码)——超时时间300秒
│ └─ Opus:类型系统、深度推理问题(unresolved-attribute)——超时时间600秒
├─ 重新运行Phase 1+2以验证修复效果
└─ 若问题全部修复则返回Exit 0,若仍有问题则返回Exit 2(并向主Agent报告)What the Main Agent Sees
主Agent可见内容
| Scenario | Agent sees | Hook exit |
|---|---|---|
| No violations | Nothing | 0 |
| All fixed by subprocess | Nothing | 0 |
| Violations remain after subprocess | | 2 |
| Advisory (duplicates, old tooling) | | 0 |
The main agent only sees issues the subprocess couldn't fix. Most quality problems are resolved transparently.
| 场景 | Agent可见内容 | 钩子退出码 |
|---|---|---|
| 无问题 | 无 | 0 |
| 所有问题被子进程修复 | 无 | 0 |
| 子进程修复后仍有问题 | | 2 |
| 建议信息(重复项、旧工具) | | 0 |
主Agent仅能看到子进程无法修复的问题。大多数质量问题会被透明地解决。
Config Protection (Defense Against Rule-Gaming)
配置保护(防止规则规避)
LLMs will modify or to disable rules rather than fix code. Plankton blocks this with three layers:
.ruff.tomlbiome.json- PreToolUse hook — blocks edits to all linter configs before they happen
protect_linter_configs.sh - Stop hook — detects config changes via
stop_config_guardian.shat session endgit diff - Protected files list — ,
.ruff.toml,biome.json,.shellcheckrc,.yamllint, and more.hadolint.yaml
大语言模型会修改或等文件来禁用规则,而非修复代码。Plankton通过三层机制阻止此类行为:
.ruff.tomlbiome.json- PreToolUse钩子 — 在编辑发生前阻止对所有代码检查工具配置文件的修改
protect_linter_configs.sh - Stop钩子 — 在会话结束时通过
stop_config_guardian.sh检测配置文件变更git diff - 受保护文件列表 — 、
.ruff.toml、biome.json、.shellcheckrc、.yamllint等.hadolint.yaml
Package Manager Enforcement
包管理器强制管控
A PreToolUse hook on Bash blocks legacy package managers:
- ,
pip,pip3,poetry→ Blocked (usepipenv)uv - ,
npm,yarn→ Blocked (usepnpm)bun - Allowed exceptions: ,
npm audit,npm viewnpm publish
针对Bash的PreToolUse钩子会阻止使用旧版包管理器:
- 、
pip、pip3、poetry→ 被阻止(请使用pipenv)uv - 、
npm、yarn→ 被阻止(请使用pnpm)bun - 允许的例外情况:、
npm audit、npm viewnpm publish
Setup
安装配置
Quick Start
快速开始
Note: Plankton requires manual installation from its repository. Review the code before installing.
bash
undefined注意: Plankton需要从其代码仓库手动安装。安装前请先查看代码内容。
bash
undefinedInstall core dependencies
安装核心依赖
brew install jaq ruff uv
brew install jaq ruff uv
Install Python linters
安装Python代码检查工具
uv sync --all-extras
uv sync --all-extras
Start Claude Code — hooks activate automatically
启动Claude Code——钩子会自动激活
claude
No install command, no plugin config. The hooks in `.claude/settings.json` are picked up automatically when you run Claude Code in the Plankton directory.claude
无需安装命令或插件配置。当你在Plankton目录中运行Claude Code时,`.claude/settings.json`中的钩子会被自动加载。Per-Project Integration
多项目集成
To use Plankton hooks in your own project:
- Copy directory to your project
.claude/hooks/ - Copy hook configuration
.claude/settings.json - Copy linter config files (,
.ruff.toml, etc.)biome.json - Install the linters for your languages
要在你自己的项目中使用Plankton钩子:
- 将目录复制到你的项目中
.claude/hooks/ - 复制中的钩子配置
.claude/settings.json - 复制代码检查工具配置文件(、
.ruff.toml等)biome.json - 为你的开发语言安装对应的代码检查工具
Language-Specific Dependencies
各语言依赖
| Language | Required | Optional |
|---|---|---|
| Python | | |
| TypeScript/JS | | |
| Shell | | — |
| YAML | | — |
| Markdown | | — |
| Dockerfile | | — |
| TOML | | — |
| JSON | | — |
| 语言 | 必填依赖 | 可选依赖 |
|---|---|---|
| Python | | |
| TypeScript/JS | | |
| Shell | | — |
| YAML | | — |
| Markdown | | — |
| Dockerfile | | — |
| TOML | | — |
| JSON | | — |
Pairing with ECC
与ECC搭配使用
Complementary, Not Overlapping
互补而非重叠
| Concern | ECC | Plankton |
|---|---|---|
| Code quality enforcement | PostToolUse hooks (Prettier, tsc) | PostToolUse hooks (20+ linters + subprocess fixes) |
| Security scanning | AgentShield, security-reviewer agent | Bandit (Python), Semgrep (TypeScript) |
| Config protection | — | PreToolUse blocks + Stop hook detection |
| Package manager | Detection + setup | Enforcement (blocks legacy PMs) |
| CI integration | — | Pre-commit hooks for git |
| Model routing | Manual ( | Automatic (violation complexity → tier) |
| 关注点 | ECC | Plankton |
|---|---|---|
| 代码质量管控 | PostToolUse钩子(Prettier、tsc) | PostToolUse钩子(20+代码检查工具 + 子进程修复) |
| 安全扫描 | AgentShield、security-reviewer agent | Bandit(Python)、Semgrep(TypeScript) |
| 配置保护 | — | PreToolUse阻止 + Stop钩子检测 |
| 包管理器 | 检测 + 配置 | 强制管控(阻止旧版包管理器) |
| CI集成 | — | Git的pre-commit钩子 |
| 模型路由 | 手动( | 自动(根据问题复杂度分配层级) |
Recommended Combination
推荐组合
- Install ECC as your plugin (agents, skills, commands, rules)
- Add Plankton hooks for write-time quality enforcement
- Use AgentShield for security audits
- Use ECC's verification-loop as a final gate before PRs
- 安装ECC作为你的插件(包含Agent、Skill、命令、规则)
- 添加Plankton钩子实现编写时代码质量管控
- 使用AgentShield进行安全审计
- 在提交PR前使用ECC的验证循环作为最终检查
Avoiding Hook Conflicts
避免钩子冲突
If running both ECC and Plankton hooks:
- ECC's Prettier hook and Plankton's biome formatter may conflict on JS/TS files
- Resolution: disable ECC's Prettier PostToolUse hook when using Plankton (Plankton's biome is more comprehensive)
- Both can coexist on different file types (ECC handles what Plankton doesn't cover)
如果同时运行ECC和Plankton钩子:
- ECC的Prettier钩子与Plankton的biome格式化工具可能在JS/TS文件上产生冲突
- 解决方案:使用Plankton时禁用ECC的Prettier PostToolUse钩子(Plankton的biome功能更全面)
- 两者可在不同文件类型上共存(ECC处理Plankton未覆盖的场景)
Configuration Reference
配置参考
Plankton's controls all behavior:
.claude/hooks/config.jsonjson
{
"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
}
}Key settings:
- Disable languages you don't use to speed up hooks
- — violations > this count auto-escalate to a higher model tier
volume_threshold - — skip Phase 3 entirely (just report violations)
subprocess_delegation: false
Plankton的控制所有行为:
.claude/hooks/config.jsonjson
{
"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 - — 完全跳过Phase 3(仅报告问题)
subprocess_delegation: false
Environment Overrides
环境变量覆盖
| Variable | Purpose |
|---|---|
| Skip Phase 3, report violations directly |
| Override tier timeout |
| Log model selection decisions |
| Bypass package manager enforcement |
| 变量 | 用途 |
|---|---|
| 跳过Phase 3,直接报告问题 |
| 覆盖层级超时时间 |
| 记录模型选择决策 |
| 绕过包管理器强制管控 |
References
参考资料
- Plankton (credit: @alxfazio)
- Plankton REFERENCE.md — Full architecture documentation (credit: @alxfazio)
- Plankton SETUP.md — Detailed installation guide (credit: @alxfazio)
- Plankton(致谢:@alxfazio)
- Plankton REFERENCE.md — 完整架构文档(致谢:@alxfazio)
- Plankton SETUP.md — 详细安装指南(致谢:@alxfazio)
ECC v1.8 Additions
ECC v1.8 新增功能
Copyable Hook Profile
可复制的钩子配置文件
Set strict quality behavior:
bash
export ECC_HOOK_PROFILE=strict
export ECC_QUALITY_GATE_FIX=true
export ECC_QUALITY_GATE_STRICT=true设置严格的质量管控行为:
bash
export ECC_HOOK_PROFILE=strict
export ECC_QUALITY_GATE_FIX=true
export ECC_QUALITY_GATE_STRICT=trueLanguage Gate Table
语言管控表
- TypeScript/JavaScript: Biome preferred, Prettier fallback
- Python: Ruff format/check
- Go: gofmt
- TypeScript/JavaScript:优先使用Biome,Prettier作为备选
- Python:使用Ruff格式化/检查
- Go:使用gofmt
Config Tamper Guard
配置篡改防护
During quality enforcement, flag changes to config files in same iteration:
- ,
biome.json,.eslintrc*,prettier.config*,tsconfig.jsonpyproject.toml
If config is changed to suppress violations, require explicit review before merge.
在质量管控过程中,标记同一迭代中对配置文件的修改:
- 、
biome.json、.eslintrc*、prettier.config*、tsconfig.jsonpyproject.toml
如果配置文件被修改以抑制问题,合并前需要明确的审核。
CI Integration Pattern
CI集成模式
Use the same commands in CI as local hooks:
- run formatter checks
- run lint/type checks
- fail fast on strict mode
- publish remediation summary
在CI中使用与本地钩子相同的命令:
- 运行格式化检查
- 运行代码检查/类型检查
- 严格模式下快速失败
- 发布修复总结
Health Metrics
健康指标
Track:
- edits flagged by gates
- average remediation time
- repeat violations by category
- merge blocks due to gate failures
跟踪:
- 被管控标记的编辑次数
- 平均修复时间
- 按类别统计的重复问题
- 因管控失败导致的合并阻塞次数