create-plugin

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Plugin

创建插件

Build an oh-my-claude statusline plugin — from idea to working output in one pass.
构建oh-my-claude状态行插件——从构思到可用产出一步完成。

Workflow

工作流程

  1. Clarify the plugin's purpose — ask what it should display, when to hide, and any config the user wants. See PATTERNS.md for data fields and common patterns.
  2. Choose plugin type — JS plugin (default, in-process, fast) or script plugin (any language, runs as subprocess). Use JS unless the user specifies a language or the task needs external tools. See PATTERNS.md.
  3. Scaffold the plugin — run
    omc create <name>
    (or
    omc create <name> --script --lang=python|bash
    ). This creates the directory structure at
    ~/.claude/oh-my-claude/plugins/<name>/
    .
  4. Implement render logic — edit the generated
    plugin.js
    (or
    plugin
    script). Follow the contract in PATTERNS.md. Always use optional chaining. Always return null when data is missing.
  5. Set default config — add any configurable values to
    meta.defaultConfig
    (JS) or
    plugin.json
    (script). Use concrete defaults, not empty strings.
  6. Test the plugin — run
    omc test <name>
    . Verify it returns
    { text, style }
    with mock data and returns
    null
    with empty data.
  7. Wire it up — run
    omc add <name>
    (with
    --line N
    and
    --left
    if needed). Run
    omc show
    to verify placement.
  8. Verify end-to-end — run
    omc doctor
    to confirm no errors. Run
    omc show
    to see the live preview.
  1. 明确插件用途 —— 询问插件需要展示的内容、隐藏时机,以及用户需要的任何配置项。数据字段和通用模式请参考PATTERNS.md
  2. 选择插件类型 —— JS插件(默认,进程内运行,速度快)或脚本插件(支持任意语言,作为子进程运行)。除非用户指定了语言或任务需要用到外部工具,否则优先使用JS。参考PATTERNS.md
  3. 生成插件骨架 —— 运行
    omc create <name>
    (或
    omc create <name> --script --lang=python|bash
    )。该命令会在
    ~/.claude/oh-my-claude/plugins/<name>/
    路径下创建目录结构。
  4. 实现渲染逻辑 —— 编辑生成的
    plugin.js
    (或
    plugin
    脚本)。遵循PATTERNS.md中定义的规范。始终使用可选链语法。数据缺失时始终返回null。
  5. 设置默认配置 —— 将所有可配置项添加到
    meta.defaultConfig
    (JS插件)或
    plugin.json
    (脚本插件)中。使用具体的默认值,不要用空字符串。
  6. 测试插件 —— 运行
    omc test <name>
    。验证插件在使用模拟数据时返回
    { text, style }
    ,数据为空时返回
    null
  7. 接入状态行 —— 运行
    omc add <name>
    (如有需要可搭配
    --line N
    --left
    参数)。运行
    omc show
    验证插件位置是否正确。
  8. 端到端验证 —— 运行
    omc doctor
    确认没有错误。运行
    omc show
    查看实时预览效果。

Self-review checklist

自检清单

Before delivering, verify ALL:
  • meta.name
    matches the directory name
  • meta.description
    is a single clear sentence
  • render()
    uses optional chaining for every data access (
    data?.field?.subfield
    )
  • render()
    returns
    null
    when required data is missing (never crashes)
  • omc test <name>
    succeeds — shows text with mock data, returns null with empty data
  • omc doctor
    reports no errors for this plugin
  • Shell commands (if any) use
    cachedExec
    from
    src/cache.js
    , never raw
    execSync
  • Config keys have sensible defaults in
    defaultConfig
    (no empty strings or nulls for required values)
  • Plugin text is short — fits in a statusline segment (under ~30 chars typical)
  • omc show
    confirms the plugin appears where the user wants it
交付前请确认所有项都已满足:
  • meta.name
    与目录名一致
  • meta.description
    是清晰的单句描述
  • render()
    中所有数据访问都使用可选链语法(
    data?.field?.subfield
  • 所需数据缺失时
    render()
    返回
    null
    (永远不会崩溃)
  • omc test <name>
    运行成功——使用模拟数据时返回文本,数据为空时返回null
  • omc doctor
    未报告该插件存在任何错误
  • 如有Shell命令,使用
    src/cache.js
    提供的
    cachedExec
    ,绝不使用原生
    execSync
  • 配置项在
    defaultConfig
    中有合理的默认值(必填项不要使用空字符串或null)
  • 插件文本简短——适合放在状态行分段中(通常不超过30个字符)
  • omc show
    确认插件显示在用户期望的位置

Golden rules

黄金准则

Hard rules. Never violate these.
  1. Never crash the statusline. Every data access uses optional chaining. Every render returns
    { text, style }
    or
    null
    . No exceptions, no throws. A plugin that crashes breaks the entire statusbar for the user.
  2. Null means hide. Return
    null
    when data is unavailable. Never return empty strings, placeholder text, or fallback values that clutter the bar.
  3. Cache all shell commands. Use
    cachedExec(key, command, ttlMs)
    from
    src/cache.js
    . Raw
    execSync
    in render blocks the entire statusline pipeline.
  4. Test before wiring. Always run
    omc test <name>
    before
    omc add <name>
    . A broken plugin silently disappears — testing catches errors the statusline would swallow.
  5. Keep text short. Statusline segments share a single terminal line. Aim for under 30 characters. Use abbreviations, symbols, and rounding (e.g.
    42%
    not
    42.53%
    ,
    $2.41
    not
    $2.4100
    ).
  6. Config has real defaults. Every key in
    defaultConfig
    must have a usable value. Users override config — they don't fill in required blanks.
  7. Match name to directory.
    meta.name
    must exactly match the plugin directory name. Mismatches cause the plugin to silently not load.
硬性规则,绝对不能违反。
  1. 绝对不能导致状态行崩溃。 所有数据访问都使用可选链语法。所有渲染结果要么返回
    { text, style }
    ,要么返回
    null
    。没有例外,不要抛出异常。崩溃的插件会导致用户的整个状态栏无法使用。
  2. Null代表隐藏。 数据不可用时返回
    null
    。不要返回空字符串、占位文本,或者其他会让状态栏变得杂乱的回退值。
  3. 所有Shell命令都要缓存。 使用
    src/cache.js
    提供的
    cachedExec(key, command, ttlMs)
    。渲染逻辑中的原生
    execSync
    会阻塞整个状态行处理流程。
  4. 接入前先测试。 运行
    omc add <name>
    之前务必先运行
    omc test <name>
    。损坏的插件会静默消失,测试可以捕获状态行可能忽略的错误。
  5. 保持文本简短。 状态行分段共享同一终端行。尽量控制在30个字符以内。使用缩写、符号和舍入处理(例如用
    42%
    而不是
    42.53%
    ,用
    $2.41
    而不是
    $2.4100
    )。
  6. 配置要有真实默认值。
    defaultConfig
    中的每个键都必须有可用值。用户是覆盖配置,而不是填写必填空项。
  7. 名称与目录匹配。
    meta.name
    必须与插件目录名完全一致。不匹配会导致插件静默加载失败。

Reference files

参考文件

FileContents
PATTERNS.mdData fields, plugin templates, cachedExec usage, script plugin format, style tokens, common patterns
文件内容
PATTERNS.md数据字段、插件模板、cachedExec用法、脚本插件格式、样式标记、通用模式