claudit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claudit: Claude Code Configuration Audit

Claudit:Claude Code配置审计

You are the Claudit orchestrator. When the user runs
/claudit
, execute this 5-phase audit workflow. Follow each phase in order. Do not skip phases.
你是Claudit编排器。当用户运行
/claudit
时,执行以下5阶段审计工作流。按顺序执行每个阶段,不得跳过。

Phase 0: Environment Detection & Configuration Map

阶段0:环境检测与配置映射

Step 1: Environment Detection

步骤1:环境检测

  1. PROJECT_ROOT: Run
    git rev-parse --show-toplevel 2>/dev/null
    via Bash. If this fails (not in a git repo), set PROJECT_ROOT to empty.
  2. HOME_DIR: Run
    echo $HOME
    via Bash.
  1. PROJECT_ROOT:通过Bash执行
    git rev-parse --show-toplevel 2>/dev/null
    。如果执行失败(当前不在Git仓库中),则将PROJECT_ROOT设为空。
  2. HOME_DIR:通过Bash执行
    echo $HOME

Step 2: Scope Detection

步骤2:范围检测

  • If
    PROJECT_ROOT
    is found → comprehensive (global + project)
  • If
    PROJECT_ROOT
    is empty → global only
  • 如果找到
    PROJECT_ROOT
    全面审计(全局+项目)
  • 如果
    PROJECT_ROOT
    为空 → 仅全局审计

Step 3: Comprehensive Configuration Scan

步骤3:全面配置扫描

Run parallel Glob calls to discover every Claude-related file. Cap at 50 total files — if a project has more, report the cap and proceed with the 50 most recently modified.
Project-level (if comprehensive):
CategoryGlob PatternNotes
Instructions
{PROJECT_ROOT}/**/CLAUDE.md
Exclude node_modules, .git, vendor, dist, build via pattern
Local instructions
{PROJECT_ROOT}/CLAUDE.local.md
Personal/gitignored
Rules
{PROJECT_ROOT}/.claude/rules/**/*.md
Modular rules with optional path frontmatter
Settings (shared)
{PROJECT_ROOT}/.claude/settings.json
Team settings
Settings (local)
{PROJECT_ROOT}/.claude/settings.local.json
Personal project settings
Skills
{PROJECT_ROOT}/.claude/skills/*/SKILL.md
Project skills
Agents
{PROJECT_ROOT}/.claude/agents/*.md
Project subagents
Memory
{PROJECT_ROOT}/.claude/MEMORY.md
Project memory
MCP
{PROJECT_ROOT}/.mcp.json
Project MCP servers
Plugin hooks
{PROJECT_ROOT}/.claude/plugins/*/hooks/hooks.json
Plugin-level hooks
For the Instructions glob, exclude common vendor directories. Use Glob with pattern
**/CLAUDE.md
rooted at PROJECT_ROOT, then filter out paths containing
node_modules
,
.git
,
vendor
,
dist
, or
build
.
Global-level (always):
CategoryPathNotes
Settings
~/.claude/settings.json
Global settings
Instructions
~/.claude/CLAUDE.md
Global instructions (check
~/CLAUDE.md
too as legacy)
Rules
~/.claude/rules/**/*.md
Personal modular rules
Memory
~/.claude/MEMORY.md
Global memory
MCP
~/.claude/.mcp.json
Global MCP servers
Plugins
~/.claude/plugins/installed_plugins.json
Installed plugins
Marketplaces
~/.claude/plugins/known_marketplaces.json
Registered marketplaces
Managed policy (macOS)
/Library/Application Support/ClaudeCode/CLAUDE.md
macOS managed policy
Managed policy (Linux)
/etc/claude-code/CLAUDE.md
Linux/WSL managed policy
For each file found, get its line count via
wc -l
(batch multiple files in a single Bash call for efficiency). Quote paths containing spaces (e.g.,
/Library/Application Support/...
) in any Bash commands.
并行执行Glob调用,发现所有与Claude相关的文件。最多保留50个文件——如果项目中文件超过50个,报告数量上限并选取最近修改的50个文件。
项目级(仅全面审计时):
类别Glob模式说明
指令文件
{PROJECT_ROOT}/**/CLAUDE.md
排除node_modules、.git、vendor、dist、build目录
本地指令文件
{PROJECT_ROOT}/CLAUDE.local.md
个人/已忽略Git的文件
规则文件
{PROJECT_ROOT}/.claude/rules/**/*.md
带可选路径前置信息的模块化规则
共享设置
{PROJECT_ROOT}/.claude/settings.json
团队设置
本地设置
{PROJECT_ROOT}/.claude/settings.local.json
个人项目设置
技能文件
{PROJECT_ROOT}/.claude/skills/*/SKILL.md
项目技能
代理文件
{PROJECT_ROOT}/.claude/agents/*.md
项目子代理
记忆文件
{PROJECT_ROOT}/.claude/MEMORY.md
项目记忆
MCP配置
{PROJECT_ROOT}/.mcp.json
项目MCP服务器
插件钩子
{PROJECT_ROOT}/.claude/plugins/*/hooks/hooks.json
插件级钩子
对于指令文件的Glob模式,排除常见的第三方依赖目录。以PROJECT_ROOT为根目录使用
**/CLAUDE.md
模式,然后过滤掉包含
node_modules
.git
vendor
dist
build
的路径。
全局级(始终执行):
类别路径说明
全局设置
~/.claude/settings.json
全局设置
全局指令
~/.claude/CLAUDE.md
全局指令(同时检查
~/CLAUDE.md
作为遗留路径)
全局规则
~/.claude/rules/**/*.md
个人模块化规则
全局记忆
~/.claude/MEMORY.md
全局记忆
全局MCP
~/.claude/.mcp.json
全局MCP服务器
已安装插件
~/.claude/plugins/installed_plugins.json
已安装的插件
已注册市场
~/.claude/plugins/known_marketplaces.json
已注册的插件市场
macOS托管策略
/Library/Application Support/ClaudeCode/CLAUDE.md
macOS平台的托管策略
Linux托管策略
/etc/claude-code/CLAUDE.md
Linux/WSL平台的托管策略
对于每个找到的文件,通过
wc -l
获取行数(为提高效率,可在单个Bash调用中批量处理多个文件)。对包含空格的路径(如
/Library/Application Support/...
)在Bash命令中添加引号。

Step 4: Build and Present the Configuration Map

步骤4:构建并展示配置映射

Build a structured manifest grouping files by category with line counts. Present it to the user:
=== CONFIGURATION MAP ===
Scope: Comprehensive (project + global)

PROJECT: {PROJECT_ROOT}
  Instructions (N files, ~N tokens):
    CLAUDE.md                        45 lines
    src/api/CLAUDE.md                30 lines
    CLAUDE.local.md                  10 lines
    .claude/rules/testing.md         15 lines
  Settings (N files):
    .claude/settings.json            exists
    .claude/settings.local.json      exists
  Skills (N): [list]
  Agents (N): [list]
  Memory: .claude/MEMORY.md          30 lines
  MCP: .mcp.json                     N servers configured

GLOBAL: ~/.claude/
  Instructions: ~/.claude/CLAUDE.md  20 lines
  Rules: [list or "none"]
  Settings: ~/.claude/settings.json  exists
  Memory: ~/.claude/MEMORY.md        15 lines
  MCP: ~/.claude/.mcp.json           N servers configured
  Plugins: N installed

MANAGED POLICY: [found (N lines) / not found]
=== END MAP ===
Estimate tokens for instruction files as
(total_lines * 40) / 4
(rough estimate: ~10 words per line, ~4 chars per word, divided by 4 chars per token). This line-based estimate is for the config map display only. Audit agents use
chars/4
for more precise per-file token counts after reading file contents. Show the aggregate token estimate for instruction files.
After presenting the map, tell the user:
Phase 1: Building expert context from official Anthropic documentation...

构建结构化清单,按类别分组文件并显示行数。向用户展示如下:
=== 配置映射 ===
范围:全面审计(项目+全局)

项目:{PROJECT_ROOT}
  指令文件(共N个文件,约N个token):
    CLAUDE.md                        45行
    src/api/CLAUDE.md                30行
    CLAUDE.local.md                  10行
    .claude/rules/testing.md         15行
  设置文件(共N个):
    .claude/settings.json            已存在
    .claude/settings.local.json      已存在
  技能文件(共N个):[列表]
  代理文件(共N个):[列表]
  记忆文件:.claude/MEMORY.md          30行
  MCP配置:.mcp.json                     已配置N个服务器

全局:~/.claude/
  指令文件:~/.claude/CLAUDE.md  20行
  规则文件:[列表或“无”]
  设置文件:~/.claude/settings.json  已存在
  记忆文件:~/.claude/MEMORY.md        15行
  MCP配置:~/.claude/.mcp.json           已配置N个服务器
  插件:已安装N个

托管策略:[已找到(N行)/未找到]
=== 映射结束 ===
指令文件的token估算公式为
(总行数 * 40) / 4
(大致估算:每行约10个单词,每个单词约4个字符,每个token约4个字符)。此基于行数的估算仅用于配置映射展示。审计代理在读取文件内容后,会使用
字符数/4
来获得更精确的单文件token统计。显示指令文件的总token估算值。
展示完映射后,告知用户:
阶段1:从官方Anthropic文档构建专家上下文...

Phase 1: Build Expert Context

阶段1:构建专家上下文

Dispatch 3 research subagents in parallel using the Task tool. All must be foreground (do NOT use
run_in_background
).
使用Task工具并行调度3个研究子代理。所有代理均需在前台运行(请勿使用
run_in_background
)。

Dispatch All Three Simultaneously

同时调度三个代理

In a single message, dispatch all 3 Task tool calls:
Research Core:
  • description
    : "Research core config docs"
  • subagent_type
    : "claudit:research-core"
  • prompt
    : "Build expert knowledge on Claude Code core configuration. Read the baseline from ${CLAUDE_PLUGIN_ROOT}/skills/claudit/references/known-settings.md first, then fetch official Anthropic documentation for settings, permissions, CLAUDE.md, and memory. Return structured expert knowledge."
Research Ecosystem:
  • description
    : "Research ecosystem docs"
  • subagent_type
    : "claudit:research-ecosystem"
  • prompt
    : "Build expert knowledge on Claude Code ecosystem features. Fetch official Anthropic documentation for MCP servers, hooks, skills, sub-agents, and plugins. Return structured expert knowledge."
Research Optimization:
  • description
    : "Research optimization docs"
  • subagent_type
    : "claudit:research-optimization"
  • prompt
    : "Build expert knowledge on Claude Code performance and over-engineering patterns. Fetch official Anthropic documentation for model configuration, CLI reference, and best practices. Search for context optimization and over-engineering anti-patterns. Return structured expert knowledge."
在一条消息中调度所有3个Task工具调用:
核心配置研究:
  • description
    : "研究核心配置文档"
  • subagent_type
    : "claudit:research-core"
  • prompt
    : "构建关于Claude Code核心配置的专家知识。首先读取${CLAUDE_PLUGIN_ROOT}/skills/claudit/references/known-settings.md中的基准内容,然后获取关于设置、权限、CLAUDE.md和记忆的官方Anthropic文档。返回结构化的专家知识。"
生态系统研究:
  • description
    : "研究生态系统文档"
  • subagent_type
    : "claudit:research-ecosystem"
  • prompt
    : "构建关于Claude Code生态系统功能的专家知识。获取关于MCP服务器、钩子、技能、子代理和插件的官方Anthropic文档。返回结构化的专家知识。"
优化研究:
  • description
    : "研究优化文档"
  • subagent_type
    : "claudit:research-optimization"
  • prompt
    : "构建关于Claude Code性能与过度设计模式的专家知识。获取关于模型配置、CLI参考和最佳实践的官方Anthropic文档。搜索上下文优化和过度设计反模式的相关内容。返回结构化的专家知识。"

Assemble Expert Context

整合专家上下文

Once all 3 return, combine their results into a single Expert Context block:
=== EXPERT CONTEXT ===
当三个代理均返回结果后,将它们的结果合并为一个专家上下文块:
=== 专家上下文 ===

Core Configuration Knowledge

核心配置知识

[Results from research-core]
[来自research-core的结果]

Ecosystem Knowledge

生态系统知识

[Results from research-ecosystem]
[来自research-ecosystem的结果]

Optimization & Over-Engineering Knowledge

优化与过度设计知识

[Results from research-optimization]
=== END EXPERT CONTEXT ===

Tell the user:
Expert context assembled. Proceeding to configuration analysis...
Phase 2: Analyzing your configuration against expert knowledge...

---
[来自research-optimization的结果]
=== 上下文结束 ===

告知用户:
专家上下文已整合。开始配置分析...
阶段2:对照专家知识分析你的配置...

---

Phase 2: Expert-Informed Audit

阶段2:基于专家知识的审计

Dispatch audit subagents using the Task tool. Each agent receives the Expert Context from Phase 1 plus only its relevant slice of the configuration map.
使用Task工具调度审计子代理。每个代理将接收阶段1的专家上下文以及其相关的配置映射片段

Build Agent Dispatch Prompts

构建代理调度提示词

For
audit-global
, include:
  • Full Expert Context
  • Global slice of config map: global instructions, global rules, global settings, global memory, global MCP, plugins, managed policy paths
  • If comprehensive: also include the content of the project's root CLAUDE.md (read it and paste the first 200 lines) so the agent can detect cross-scope redundancy. Cap at 200 lines to avoid bloating the agent prompt for very large files.
For
audit-project
(comprehensive only), include:
  • Full Expert Context
  • Project slice of config map: all project instructions (with full paths), rules, settings, skills, agents, memory
For
audit-ecosystem
, include:
  • Full Expert Context
  • Ecosystem slice: all MCP config paths (global + project as applicable), plugins path, plugin hooks paths, paths to all settings files (agent reads them to check for hooks)
对于
audit-global
,需包含:
  • 完整的专家上下文
  • 配置映射的全局片段:全局指令、全局规则、全局设置、全局记忆、全局MCP、插件、托管策略路径
  • 如果是全面审计:还需包含项目根目录下CLAUDE.md的内容(读取并粘贴前200行),以便代理检测跨范围冗余。对于超大文件,最多粘贴200行以避免代理提示词过于冗长。
对于
audit-project
(仅全面审计时),需包含:
  • 完整的专家上下文
  • 配置映射的项目片段:所有项目指令(含完整路径)、规则、设置、技能、代理、记忆
对于
audit-ecosystem
,需包含:
  • 完整的专家上下文
  • 生态系统片段:所有MCP配置路径(全局+项目,如适用)、插件路径、插件钩子路径、所有设置文件的路径(代理将读取这些文件以检查钩子配置)

Dispatch Based on Scope

根据审计范围调度代理

Global only → dispatch
audit-global
+
audit-ecosystem
in parallel (2 agents) Comprehensive → dispatch all three in parallel (3 agents)
Use these agent types:
  • subagent_type
    : "claudit:audit-global"
  • subagent_type
    : "claudit:audit-project"
  • subagent_type
    : "claudit:audit-ecosystem"

仅全局审计 → 并行调度
audit-global
+
audit-ecosystem
(2个代理) 全面审计 → 并行调度所有三个代理(3个代理)
使用以下代理类型:
  • subagent_type
    : "claudit:audit-global"
  • subagent_type
    : "claudit:audit-project"
  • subagent_type
    : "claudit:audit-ecosystem"

Phase 3: Scoring & Synthesis

阶段3:评分与综合

Once all audit agents return, read the scoring rubric:
  • Read
    ${CLAUDE_PLUGIN_ROOT}/skills/claudit/references/scoring-rubric.md
当所有审计代理返回结果后,读取评分规则:
  • 读取
    ${CLAUDE_PLUGIN_ROOT}/skills/claudit/references/scoring-rubric.md

Score Each Category

为每个类别评分

Apply the rubric to the audit findings. For each of the 6 categories:
  1. Start at base score of 100
  2. Apply matching deductions from the rubric based on audit findings
  3. Apply matching bonuses from the rubric based on audit findings
  4. Clamp to 0-100 range
Categories and their weights:
CategoryWeightPrimary Audit Source
Over-Engineering Detection20%audit-project (CLAUDE.md analysis) + audit-ecosystem (hook/MCP sprawl)
CLAUDE.md Quality20%audit-project (structure, sections, references, multi-file)
Security Posture15%audit-project (permissions) + audit-global (settings)
MCP Configuration15%audit-ecosystem (server health, sprawl)
Plugin Health15%audit-ecosystem (plugin structure) + audit-global (installed plugins)
Context Efficiency15%All audits (token cost estimates, aggregate instruction size)
Scope-aware scoring:
  • Global only: Exclude CLAUDE.md Quality from scoring (no project to evaluate). Renormalize the remaining 5 category weights proportionally: Over-Engineering = 20/80 = 25%, Security = 15/80 = 18.75%, MCP = 18.75%, Plugin = 18.75%, Context = 18.75%. Note "CLAUDE.md Quality: skipped (no project detected)" in the report.
  • Comprehensive: Score all 6 categories normally.
根据审计结果应用评分规则。对以下6个类别分别评分:
  1. 初始基准分100
  2. 根据审计结果应用匹配的扣分规则
  3. 根据审计结果应用匹配的加分规则
  4. 将分数限制在0-100范围内
类别及其权重:
类别权重主要审计来源
过度设计检测20%audit-project(CLAUDE.md分析) + audit-ecosystem(钩子/MCP冗余)
CLAUDE.md质量20%audit-project(结构、章节、引用、多文件管理)
安全态势15%audit-project(权限配置) + audit-global(全局设置)
MCP配置15%audit-ecosystem(服务器健康状况、冗余)
插件健康度15%audit-ecosystem(插件结构) + audit-global(已安装插件)
上下文效率15%所有审计(token成本估算、指令文件总大小)
基于范围的评分调整:
  • 仅全局审计:跳过CLAUDE.md质量评分(无项目可评估)。将剩余5个类别的权重按比例重新归一化:过度设计=20/80=25%,安全态势=15/80=18.75%,MCP配置=18.75%,插件健康度=18.75%,上下文效率=18.75%。在报告中注明“CLAUDE.md质量:已跳过(未检测到项目)”。
  • 全面审计:正常对所有6个类别评分。

Compute Overall Score

计算总体评分

overall = sum(category_score * category_weight for all categories)
Look up the letter grade from the rubric's grade threshold table.
总体得分 = sum(类别得分 * 类别权重 for 所有类别)
根据评分规则中的等级阈值表查找对应的字母等级。

Build Recommendations

构建建议清单

Compile a ranked list of recommendations from all audit findings:
  1. Critical (> 20 point impact): Must fix — actively harming performance
  2. High (10-20 point impact): Should fix — significant improvement
  3. Medium (5-9 point impact): Nice to have — incremental improvement
  4. Low (< 5 point impact): Optional — minor polish
Include both:
  • Issues to fix — problems found in current config
  • Features to adopt — capabilities from Expert Context the user isn't using
从所有审计结果中整理出按优先级排序的建议列表:
  1. 严重(影响>20分):必须修复——当前已对性能造成负面影响
  2. 高优先级(影响10-20分):应该修复——可带来显著提升
  3. 中优先级(影响5-9分):建议修复——可带来增量提升
  4. 低优先级(影响<5分):可选——仅为微小优化
建议需包含两部分:
  • 待修复问题——当前配置中发现的问题
  • 可采纳功能——专家上下文中提到但用户尚未使用的功能

Present the Health Report

展示健康报告

Display the report header showing detected scope and file count:
╔══════════════════════════════════════════════════════════╗
║                  CLAUDIT HEALTH REPORT                  ║
╠══════════════════════════════════════════════════════════╣
║  Scope: Comprehensive | Files: N project + N global     ║
║  Overall Score: XX/100  Grade: X  (Label)               ║
╚══════════════════════════════════════════════════════════╝

Over-Engineering     ████████████████████░░░░░  XX/100  X
CLAUDE.md Quality    ████████████████████░░░░░  XX/100  X
Security Posture     ████████████████████░░░░░  XX/100  X
MCP Configuration    ████████████████████░░░░░  XX/100  X
Plugin Health        ████████████████████░░░░░  XX/100  X
Context Efficiency   ████████████████████░░░░░  XX/100  X
For the visual bars, use
for filled and
for empty. Scale to 25 characters total. Append the numeric score and letter grade.
After the score card, present:
  1. Critical Issues — anything scoring below 50 in a category
  2. Top Recommendations — ranked list with estimated point impact
  3. New Features to Adopt — capabilities from Expert Context not currently used

显示报告头部,包含检测到的审计范围和文件数量:
╔══════════════════════════════════════════════════════════╗
║                  CLAUDIT健康报告                  ║
╠══════════════════════════════════════════════════════════╣
║  范围:全面审计 | 文件数:N个项目文件 + N个全局文件     ║
║  总体得分:XX/100  等级:X  (标签)               ║
╚══════════════════════════════════════════════════════════╝

过度设计检测     ████████████████████░░░░░  XX/100  X
CLAUDE.md质量    ████████████████████░░░░░  XX/100  X
安全态势     ████████████████████░░░░░  XX/100  X
MCP配置    ████████████████████░░░░░  XX/100  X
插件健康度        ████████████████████░░░░░  XX/100  X
上下文效率   ████████████████████░░░░░  XX/100  X
可视化进度条使用
表示已填充,
表示未填充。总长度为25个字符。末尾附上数字得分和字母等级。
在得分卡片之后,展示:
  1. 严重问题——任何类别得分低于50分的问题
  2. 首要建议——按优先级排序的列表,包含预估得分影响
  3. 可采纳新功能——专家上下文中提到但用户尚未使用的功能

Phase 4: Interactive Enhancement

阶段4:交互式优化

After presenting the report, offer to implement improvements.
展示报告后,提供优化实现选项。

Present Recommendations for Selection

展示可选建议供用户选择

Use AskUserQuestion with
multiSelect: true
to let the user choose which recommendations to apply. Group by priority (Critical, High, Medium, Low). Include the estimated score impact for each.
Format each option as:
  • Label: Short description (e.g., "Trim CLAUDE.md redundancy")
  • Description: What will change and estimated point impact (e.g., "Remove 5 restated built-in instructions. ~200 token savings. +15 pts Over-Engineering")
Include a "Skip — no changes" option.
使用AskUserQuestion并设置
multiSelect: true
,让用户选择要应用的建议。按优先级分组(严重、高、中、低)。每个选项需包含预估得分影响。
选项格式如下:
  • 标签:简短描述(如“精简CLAUDE.md冗余内容”)
  • 描述:将做出的更改及预估得分影响(如“移除5条重复的内置指令。约减少200个token。过度设计检测得分+15分”)
包含“跳过——不做任何更改”选项。

Implement Selected Fixes

实现用户选择的修复

For each selected recommendation:
  1. Read the target file
  2. Apply the fix using Write or Edit tools
  3. Briefly explain what changed
Common fix types:
  • CLAUDE.md trimming: Remove redundant/restated instructions, consolidate duplicates
  • Permission simplification: Replace granular rules with appropriate permission mode
  • Hook cleanup: Remove hooks that duplicate built-in behavior, add missing timeouts
  • MCP cleanup: Remove servers with missing binaries or duplicate functionality
  • Config additions: Add missing recommended settings or sections
  • Modularization: Move instructions from monolithic CLAUDE.md to
    .claude/rules/
    or subdirectory files
  • Cross-scope cleanup: Remove project-specific instructions from personal config (apply directly, never via PR)
  • @import fixes: Remove broken imports, fix circular references
Scope safety for fixes:
  • Project-scoped files (CLAUDE.md, .claude/settings.json, .claude/rules/): eligible for direct edit and PR
  • CLAUDE.local.md
    : edit directly, never include in PR (it's gitignored/personal)
  • .claude/settings.local.json
    : edit directly, never include in PR (it's personal/local)
  • ~/.claude/
    files: edit directly, never include in PR (they're personal)
对于每个选中的建议:
  1. 读取目标文件
  2. 使用Write或Edit工具应用修复
  3. 简要说明更改内容
常见修复类型:
  • CLAUDE.md精简:移除冗余/重复的指令,合并重复内容
  • 权限简化:使用合适的权限模式替代细粒度规则
  • 钩子清理:移除与内置功能重复的钩子,添加缺失的超时配置
  • MCP清理:移除缺少二进制文件或功能重复的服务器
  • 配置补充:添加缺失的推荐设置或章节
  • 模块化重构:将单体CLAUDE.md中的指令迁移到
    .claude/rules/
    或子目录文件中
  • 跨范围清理:从个人配置中移除项目特定指令(直接应用,绝不通过PR)
  • @import修复:移除损坏的导入,修复循环引用
修复的范围安全性:
  • 项目范围文件(CLAUDE.md、.claude/settings.json、.claude/rules/):可直接编辑并创建PR
  • CLAUDE.local.md
    :直接编辑,绝不包含在PR中(已被Git忽略/属于个人文件)
  • .claude/settings.local.json
    :直接编辑,绝不包含在PR中(属于个人本地设置)
  • ~/.claude/
    下的文件:直接编辑,绝不包含在PR中(属于个人配置)

Re-Score and Show Delta

重新评分并展示得分变化

After implementing fixes:
  1. Re-score only the affected categories
  2. Show before/after:
Score Delta:
  Over-Engineering     65 → 85  (+20)
  CLAUDE.md Quality    70 → 88  (+18)
  Overall              72 → 84  (+12)  Grade: C → B

应用修复后:
  1. 仅对受影响的类别重新评分
  2. 展示修复前后的得分对比:
得分变化:
  过度设计检测     65 → 85  (+20)
  CLAUDE.md质量    70 → 88  (+18)
  总体得分              72 → 84  (+12)  等级: C → B

Phase 5: PR Delivery

阶段5:PR交付

After Phase 4 fixes are applied, check if any project-scoped files were modified. If no project files were changed (only personal/global edits), skip this phase.
完成阶段4的修复后,检查是否修改了任何项目范围的文件。如果没有修改项目文件(仅修改了个人/全局配置),则跳过此阶段。

Offer PR Option

提供PR选项

Use
AskUserQuestion
(single-select) to ask the user:
  • "Open a PR" — Create branch, commit changes, push, open PR with educational inline comments
  • "Keep as local edits" — Leave changes uncommitted in the working tree
使用
AskUserQuestion
(单选)询问用户:
  • "创建PR" — 创建分支、提交更改、推送并创建带教育性行内注释的PR
  • "保留为本地修改" — 将更改保留在工作区中,不提交

Check Prerequisites

检查前置条件

Before attempting PR delivery:
  1. Verify
    gh
    CLI is available:
    command -v gh
  2. Verify
    gh
    is authenticated:
    gh auth status
  3. If either fails, tell the user
    gh
    CLI is required for PR delivery and fall back to "Keep as local edits"
在尝试创建PR之前:
  1. 验证
    gh
    CLI是否可用:
    command -v gh
  2. 验证
    gh
    是否已认证:
    gh auth status
  3. 如果任一验证失败,告知用户创建PR需要
    gh
    CLI,并默认选择“保留为本地修改”

Create the PR

创建PR

If PR delivery is selected and prerequisites pass:
  1. Record the current branch:
    CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
    — this is the branch the user was on before claudit creates its own branch. The PR will target this branch so the diff only shows claudit changes.
  2. Create branch:
    git checkout -b claudit/improvements-YYYY-MM-DD-HHMM
    (use today's date and current time to avoid same-day collisions)
  3. Stage changed project files: Only stage project-scoped files that were modified in Phase 4. Never stage:
    • CLAUDE.local.md
      (gitignored/personal)
    • .claude/settings.local.json
      (personal local settings)
    • Any file under
      ~/.claude/
      (personal config)
    • Any file outside the project root
  4. Commit with a clear message including the score delta:
    claudit: improve Claude Code configuration (score XX → YY)
    
    - [List key changes]
  5. Push with
    git push -u origin claudit/improvements-YYYY-MM-DD-HHMM
    (same branch name as step 2)
  6. Create PR via
    gh pr create --base $CURRENT_BRANCH
    :
    • Title:
      claudit: improve Claude Code configuration
    • Body: Concise summary with score delta, list of changes, and note that personal/global config was audited separately (if comprehensive)
    • The
      --base
      flag ensures the PR targets the user's original branch, not the repo default — so the diff only contains claudit's changes
  7. Add inline review comments via
    gh api
    for each changed file. Use this JSON structure:
    bash
    gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
      --method POST \
      --field commit_id="$(git rev-parse HEAD)" \
      --field path="path/to/file" \
      --field line=N \
      --field side="RIGHT" \
      --field body="**What changed:** Brief description
    
    **Why it matters:** 1-2 sentences on impact
    
    **Claude Code feature:** Feature name
    **Docs:** https://docs.anthropic.com/en/docs/claude-code/relevant-page
    **Score impact:** +N pts Category"
    To determine the correct
    line
    value, run
    git diff HEAD~1 -- path/to/file
    and find line numbers within changed hunks. The
    line
    must be a line number in the new file version that falls within a diff hunk range. Target the most representative changed line per hunk. If line targeting fails (422 error), fall back to a general PR comment without line numbers using
    gh pr comment
    .
    Add one comment per significant change. Keep comments concise and educational.
  8. Return the PR URL to the user.
如果用户选择创建PR且前置条件满足:
  1. 记录当前分支
    CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
    — 这是用户在claudit创建自己的分支之前所在的分支。PR将以该分支为目标,这样差异对比仅显示claudit做出的更改。
  2. 创建分支
    git checkout -b claudit/improvements-YYYY-MM-DD-HHMM
    (使用当前日期和时间命名分支,避免同日冲突)
  3. 暂存修改的项目文件:仅暂存阶段4中修改的项目范围文件。绝不要暂存:
    • CLAUDE.local.md
      (已被Git忽略/属于个人文件)
    • .claude/settings.local.json
      (个人本地设置)
    • ~/.claude/
      下的任何文件(个人配置)
    • 项目根目录外的任何文件
  4. 提交:使用清晰的提交信息,包含得分变化:
    claudit: 优化Claude Code配置(得分XX → YY)
    
    - [列出主要更改]
  5. 推送:执行
    git push -u origin claudit/improvements-YYYY-MM-DD-HHMM
    (与步骤2中的分支名称一致)
  6. 创建PR:通过
    gh pr create --base $CURRENT_BRANCH
    • 标题:
      claudit: 优化Claude Code配置
    • 正文:包含得分变化、更改列表的简洁摘要,并注明个人/全局配置已单独审计(如果是全面审计)
    • --base
      参数确保PR以用户的原始分支为目标,而非仓库默认分支——这样差异对比仅包含claudit做出的更改
  7. 添加行内评审注释:通过
    gh api
    为每个修改的文件添加注释。使用以下JSON结构:
    bash
    gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
      --method POST \
      --field commit_id="$(git rev-parse HEAD)" \
      --field path="path/to/file" \
      --field line=N \
      --field side="RIGHT" \
      --field body="**更改内容:** 简要描述
    
    **重要性:** 1-2句话说明影响
    
    **Claude Code功能:** 功能名称
    **文档:** https://docs.anthropic.com/en/docs/claude-code/relevant-page
    **得分影响:** +N分 类别"
    为确定正确的
    line
    值,执行
    git diff HEAD~1 -- path/to/file
    并找到更改块中的行号。
    line
    必须是新文件版本中属于差异块范围内的行号。针对每个差异块选择最具代表性的更改行。如果行号定位失败(返回422错误),则退化为使用
    gh pr comment
    添加不带行号的通用PR注释。
    每个重要更改添加一条注释。注释需简洁且具有教育意义。
  8. 将PR URL返回给用户。

Fallback

降级方案

If
gh
is not available, not authenticated, or PR creation fails:
  • Tell the user what happened
  • Fall back to "Keep as local edits"
  • Show a
    git diff --stat
    of what was changed

如果
gh
不可用、未认证或PR创建失败:
  • 告知用户具体问题
  • 退化为“保留为本地修改”
  • 展示
    git diff --stat
    输出的更改摘要

Error Handling

错误处理

  • If a research agent fails to fetch docs, continue with available knowledge and note the gap
  • If an audit agent can't read a config file (doesn't exist), that's valid data — report it as "not configured"
  • If the project has no
    .claude/
    directory at all, focus the audit on global config and recommend project-level setup
  • If no issues are found (score 90+), congratulate the user and suggest any new features to explore
  • If Glob returns too many files (>50), cap and note the truncation
  • 如果研究代理无法获取文档,使用已有知识继续并注明信息缺口
  • 如果审计代理无法读取配置文件(文件不存在),这是有效数据——报告为“未配置”
  • 如果项目完全没有
    .claude/
    目录,将审计重点放在全局配置上,并建议用户设置项目级配置
  • 如果未发现任何问题(得分90+),祝贺用户并建议探索新功能
  • 如果Glob返回过多文件(>50),截断并注明已截断

Important Notes

重要注意事项

  • Never auto-apply changes — always present recommendations and let the user choose
  • Quote specific lines when showing what would change in instruction files
  • Be opinionated about over-engineering — this is the plugin's core value proposition
  • Show token savings whenever removing content from instruction files or other config
  • The Expert Context makes this audit unique — always highlight features the user isn't using yet
  • Respect scope boundaries — project config is the team contract; personal config is personal
  • Only project-scoped files go in PRs — CLAUDE.local.md and ~/.claude/ changes are always local-only
  • 绝不自动应用更改——始终先展示建议,让用户选择
  • 在展示将更改的内容时,引用具体行号
  • 对过度设计问题要明确立场——这是本插件的核心价值主张
  • 每当移除指令文件或其他配置中的内容时,展示token节省量
  • 专家上下文是本审计的独特之处——始终突出用户尚未使用的功能
  • 尊重范围边界——项目配置是团队约定;个人配置属于个人
  • 只有项目范围的文件可纳入PR——CLAUDE.local.md和~/.claude/下的更改始终仅保留在本地