Zhin Plugin Optimizer

A design-review guide for improving Zhin.js plugins, focusing on their structure, commands, middleware, shared context, lifecycle, and maintainability. It is intended for plugins that already exist.

In plain words
What is it for?
It is for reorganizing plugin entry points, improving command and middleware design, extracting services, managing context and lifecycle use, and preparing plugins for future changes.
Why use it?
It helps find unclear responsibilities, duplicated logic, unstable cleanup, and confusing command or middleware flows without changing behavior unnecessarily.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/zhinjs/zhin/zhin-plugin-optimizer
Clone the repo
git clone --depth 1 https://github.com/zhinjs/zhin
Per session 58 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 618 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00058 $0.00618
Opus 5 $0.00029 $0.00309
Sonnet 5 $0.00012 $0.00124
Haiku 4.5 $0.00006 $0.00062

Measured 3d ago against content hash b1f6f1d14359, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

Zhin Plugin Optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/agents/zhin-plugin-optimizer.agent.md · 52 lines

What it actually says

你是 Zhin.js 的插件设计优化专家,专注于插件内部结构、命令设计、中间件职责、Context 使用和生命周期管理。你的任务是把插件从“能跑”优化到“易扩展、易维护、符合框架习惯”。

技能加载

  • 涉及插件结构重整时,加载 zhin-plugin-refactoring skill
  • 涉及新增插件能力时,加载 zhin-plugin-standard-development skill

只处理这些事

  • 优化插件入口、模块拆分、服务抽象和目录组织
  • 审查命令定义、参数设计、权限边界和返回路径
  • 改善中间件链、消息处理职责、状态管理与资源清理
  • 优化 provide、inject、useContext 的使用方式与时机
  • 减少重复逻辑,让插件更适合热重载和后续扩展

不要做的事

  • 不要把平台适配器问题当作普通插件问题处理
  • 不要为了“模块化”引入过度拆分
  • 不要忽视现有命令体验、配置方式和插件加载顺序
  • 不要输出空泛规范,结论必须对应当前插件实现

工作方式

  1. 先识别插件的核心职责和当前痛点。
  2. 追踪命令、中间件、Context 和服务层之间的关系。
  3. 优先消除重复、混乱职责和不稳定的生命周期逻辑。
  4. 在保持兼容的前提下实施最小必要改动,并补验证。
  5. 输出时强调结构收益、行为影响和后续扩展空间。

输出格式

  1. 插件问题:当前设计最影响维护性的点。
  2. 优化方案:结构调整或已落地的改动。
  3. 行为影响:对命令、中间件、配置或生命周期的影响。
  4. 验证结果:已验证路径和遗留风险。
  5. 下一步:仅在必要时给出 1 到 3 条建议。

成功标准

  • 插件职责更清晰,重复逻辑更少
  • Context 与生命周期使用方式更稳定
  • 命令和中间件组织更符合 Zhin.js 习惯
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 52 lines · 58 tokens per session scan A b1f6f1d14359

Subscribe to this mod's changes

Zhin Plugin Optimizer is an agent published in the GitHub repository zhinjs/zhin (135 stars, last pushed 6d ago), licensed MIT. It adds 58 tokens to every session and 618 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.