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钩子在每次文件编辑时运行格式化工具和linter,然后启动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为了通过检查而修改linter配置而非修复代码
- 你需要分等级的模型路由来处理修复任务(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)
├─ 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)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
LLM会修改或来禁用规则,而不是修复代码。Plankton通过三层机制阻止这种行为:
.ruff.tomlbiome.json- PreToolUse钩子 — 会在编辑行为发生前阻止对所有linter配置的修改
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
快速开始
bash
undefinedbash
undefinedClone Plankton into your project (or a shared location)
Clone Plankton到你的项目(或共享目录)
Note: Plankton is by @alxfazio
注意:Plankton作者为@alxfazio
git clone https://github.com/alexfazio/plankton.git
cd plankton
git clone https://github.com/alexfazio/plankton.git
cd plankton
Install core dependencies
安装核心依赖
brew install jaq ruff uv
brew install jaq ruff uv
Install Python linters
安装Python linters
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 - 复制linter配置文件(、
.ruff.toml等)biome.json - 安装对应语言的linters
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+ linters + 子进程修复) |
| 安全扫描 | AgentShield、安全审查Agent | Bandit(Python)、Semgrep(TypeScript) |
| 配置保护 | — | PreToolUse拦截 + Stop钩子检测 |
| 包管理器 | 检测 + 配置 | 强制管控(阻止旧版包管理器) |
| CI集成 | — | Git预提交钩子 |
| 模型路由 | 手动( | 自动(根据违规复杂度分配等级) |
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做安全审计
- 使用ECC的验证循环作为PR前的最终检查关卡
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 - — 完全跳过第三阶段(仅上报违规问题)
subprocess_delegation: false
Environment Overrides
环境变量覆写
| Variable | Purpose |
|---|---|
| Skip Phase 3, report violations directly |
| Override tier timeout |
| Log model selection decisions |
| Bypass package manager enforcement |
| 变量 | 用途 |
|---|---|
| 跳过第三阶段,直接上报违规问题 |
| 覆写模型等级超时时间 |
| 打印模型选择决策日志 |
| 绕过包管理器强制管控 |
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)