claudit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaudit: Claude Code Configuration Audit
Claudit:Claude Code配置审计
You are the Claudit orchestrator. When the user runs , execute this 5-phase audit workflow. Follow each phase in order. Do not skip phases.
/claudit你是Claudit编排器。当用户运行时,执行以下5阶段审计工作流。按顺序执行每个阶段,不得跳过。
/clauditPhase 0: Environment Detection & Configuration Map
阶段0:环境检测与配置映射
Step 1: Environment Detection
步骤1:环境检测
- PROJECT_ROOT: Run via Bash. If this fails (not in a git repo), set PROJECT_ROOT to empty.
git rev-parse --show-toplevel 2>/dev/null - HOME_DIR: Run via Bash.
echo $HOME
- PROJECT_ROOT:通过Bash执行。如果执行失败(当前不在Git仓库中),则将PROJECT_ROOT设为空。
git rev-parse --show-toplevel 2>/dev/null - HOME_DIR:通过Bash执行。
echo $HOME
Step 2: Scope Detection
步骤2:范围检测
- If is found → comprehensive (global + project)
PROJECT_ROOT - If is empty → global only
PROJECT_ROOT
- 如果找到→ 全面审计(全局+项目)
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):
| Category | Glob Pattern | Notes |
|---|---|---|
| Instructions | | Exclude node_modules, .git, vendor, dist, build via pattern |
| Local instructions | | Personal/gitignored |
| Rules | | Modular rules with optional path frontmatter |
| Settings (shared) | | Team settings |
| Settings (local) | | Personal project settings |
| Skills | | Project skills |
| Agents | | Project subagents |
| Memory | | Project memory |
| MCP | | Project MCP servers |
| Plugin hooks | | Plugin-level hooks |
For the Instructions glob, exclude common vendor directories. Use Glob with pattern rooted at PROJECT_ROOT, then filter out paths containing , , , , or .
**/CLAUDE.mdnode_modules.gitvendordistbuildGlobal-level (always):
| Category | Path | Notes |
|---|---|---|
| Settings | | Global settings |
| Instructions | | Global instructions (check |
| Rules | | Personal modular rules |
| Memory | | Global memory |
| MCP | | Global MCP servers |
| Plugins | | Installed plugins |
| Marketplaces | | Registered marketplaces |
| Managed policy (macOS) | | macOS managed policy |
| Managed policy (Linux) | | Linux/WSL managed policy |
For each file found, get its line count via (batch multiple files in a single Bash call for efficiency). Quote paths containing spaces (e.g., ) in any Bash commands.
wc -l/Library/Application Support/...并行执行Glob调用,发现所有与Claude相关的文件。最多保留50个文件——如果项目中文件超过50个,报告数量上限并选取最近修改的50个文件。
项目级(仅全面审计时):
| 类别 | Glob模式 | 说明 |
|---|---|---|
| 指令文件 | | 排除node_modules、.git、vendor、dist、build目录 |
| 本地指令文件 | | 个人/已忽略Git的文件 |
| 规则文件 | | 带可选路径前置信息的模块化规则 |
| 共享设置 | | 团队设置 |
| 本地设置 | | 个人项目设置 |
| 技能文件 | | 项目技能 |
| 代理文件 | | 项目子代理 |
| 记忆文件 | | 项目记忆 |
| MCP配置 | | 项目MCP服务器 |
| 插件钩子 | | 插件级钩子 |
对于指令文件的Glob模式,排除常见的第三方依赖目录。以PROJECT_ROOT为根目录使用模式,然后过滤掉包含、、、或的路径。
**/CLAUDE.mdnode_modules.gitvendordistbuild全局级(始终执行):
| 类别 | 路径 | 说明 |
|---|---|---|
| 全局设置 | | 全局设置 |
| 全局指令 | | 全局指令(同时检查 |
| 全局规则 | | 个人模块化规则 |
| 全局记忆 | | 全局记忆 |
| 全局MCP | | 全局MCP服务器 |
| 已安装插件 | | 已安装的插件 |
| 已注册市场 | | 已注册的插件市场 |
| macOS托管策略 | | macOS平台的托管策略 |
| Linux托管策略 | | Linux/WSL平台的托管策略 |
对于每个找到的文件,通过获取行数(为提高效率,可在单个Bash调用中批量处理多个文件)。对包含空格的路径(如)在Bash命令中添加引号。
wc -l/Library/Application Support/...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 (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 for more precise per-file token counts after reading file contents. Show the aggregate token estimate for instruction files.
(total_lines * 40) / 4chars/4After 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估算公式为(大致估算:每行约10个单词,每个单词约4个字符,每个token约4个字符)。此基于行数的估算仅用于配置映射展示。审计代理在读取文件内容后,会使用来获得更精确的单文件token统计。显示指令文件的总token估算值。
(总行数 * 40) / 4字符数/4展示完映射后,告知用户:
阶段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_backgroundDispatch All Three Simultaneously
同时调度三个代理
In a single message, dispatch all 3 Task tool calls:
Research Core:
- : "Research core config docs"
description - : "claudit:research-core"
subagent_type - : "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."
prompt
Research Ecosystem:
- : "Research ecosystem docs"
description - : "claudit:research-ecosystem"
subagent_type - : "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."
prompt
Research Optimization:
- : "Research optimization docs"
description - : "claudit:research-optimization"
subagent_type - : "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."
prompt
在一条消息中调度所有3个Task工具调用:
核心配置研究:
- : "研究核心配置文档"
description - : "claudit:research-core"
subagent_type - : "构建关于Claude Code核心配置的专家知识。首先读取${CLAUDE_PLUGIN_ROOT}/skills/claudit/references/known-settings.md中的基准内容,然后获取关于设置、权限、CLAUDE.md和记忆的官方Anthropic文档。返回结构化的专家知识。"
prompt
生态系统研究:
- : "研究生态系统文档"
description - : "claudit:research-ecosystem"
subagent_type - : "构建关于Claude Code生态系统功能的专家知识。获取关于MCP服务器、钩子、技能、子代理和插件的官方Anthropic文档。返回结构化的专家知识。"
prompt
优化研究:
- : "研究优化文档"
description - : "claudit:research-optimization"
subagent_type - : "构建关于Claude Code性能与过度设计模式的专家知识。获取关于模型配置、CLI参考和最佳实践的官方Anthropic文档。搜索上下文优化和过度设计反模式的相关内容。返回结构化的专家知识。"
prompt
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 , include:
audit-global- 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 (comprehensive only), include:
audit-project- Full Expert Context
- Project slice of config map: all project instructions (with full paths), rules, settings, skills, agents, memory
For , include:
audit-ecosystem- 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 + in parallel (2 agents)
Comprehensive → dispatch all three in parallel (3 agents)
audit-globalaudit-ecosystemUse these agent types:
- : "claudit:audit-global"
subagent_type - : "claudit:audit-project"
subagent_type - : "claudit:audit-ecosystem"
subagent_type
仅全局审计 → 并行调度 + (2个代理)
全面审计 → 并行调度所有三个代理(3个代理)
audit-globalaudit-ecosystem使用以下代理类型:
- : "claudit:audit-global"
subagent_type - : "claudit:audit-project"
subagent_type - : "claudit:audit-ecosystem"
subagent_type
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:
- Start at base score of 100
- Apply matching deductions from the rubric based on audit findings
- Apply matching bonuses from the rubric based on audit findings
- Clamp to 0-100 range
Categories and their weights:
| Category | Weight | Primary Audit Source |
|---|---|---|
| Over-Engineering Detection | 20% | audit-project (CLAUDE.md analysis) + audit-ecosystem (hook/MCP sprawl) |
| CLAUDE.md Quality | 20% | audit-project (structure, sections, references, multi-file) |
| Security Posture | 15% | audit-project (permissions) + audit-global (settings) |
| MCP Configuration | 15% | audit-ecosystem (server health, sprawl) |
| Plugin Health | 15% | audit-ecosystem (plugin structure) + audit-global (installed plugins) |
| Context Efficiency | 15% | 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个类别分别评分:
- 初始基准分100
- 根据审计结果应用匹配的扣分规则
- 根据审计结果应用匹配的加分规则
- 将分数限制在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:
- Critical (> 20 point impact): Must fix — actively harming performance
- High (10-20 point impact): Should fix — significant improvement
- Medium (5-9 point impact): Nice to have — incremental improvement
- 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
从所有审计结果中整理出按优先级排序的建议列表:
- 严重(影响>20分):必须修复——当前已对性能造成负面影响
- 高优先级(影响10-20分):应该修复——可带来显著提升
- 中优先级(影响5-9分):建议修复——可带来增量提升
- 低优先级(影响<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 XFor 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:
- Critical Issues — anything scoring below 50 in a category
- Top Recommendations — ranked list with estimated point impact
- 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个字符。末尾附上数字得分和字母等级。
█░在得分卡片之后,展示:
- 严重问题——任何类别得分低于50分的问题
- 首要建议——按优先级排序的列表,包含预估得分影响
- 可采纳新功能——专家上下文中提到但用户尚未使用的功能
Phase 4: Interactive Enhancement
阶段4:交互式优化
After presenting the report, offer to implement improvements.
展示报告后,提供优化实现选项。
Present Recommendations for Selection
展示可选建议供用户选择
Use AskUserQuestion with to let the user choose which recommendations to apply. Group by priority (Critical, High, Medium, Low). Include the estimated score impact for each.
multiSelect: trueFormat 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:
- Read the target file
- Apply the fix using Write or Edit tools
- 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 or subdirectory files
.claude/rules/ - 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
- : edit directly, never include in PR (it's gitignored/personal)
CLAUDE.local.md - : edit directly, never include in PR (it's personal/local)
.claude/settings.local.json - files: edit directly, never include in PR (they're personal)
~/.claude/
对于每个选中的建议:
- 读取目标文件
- 使用Write或Edit工具应用修复
- 简要说明更改内容
常见修复类型:
- CLAUDE.md精简:移除冗余/重复的指令,合并重复内容
- 权限简化:使用合适的权限模式替代细粒度规则
- 钩子清理:移除与内置功能重复的钩子,添加缺失的超时配置
- MCP清理:移除缺少二进制文件或功能重复的服务器
- 配置补充:添加缺失的推荐设置或章节
- 模块化重构:将单体CLAUDE.md中的指令迁移到或子目录文件中
.claude/rules/ - 跨范围清理:从个人配置中移除项目特定指令(直接应用,绝不通过PR)
- @import修复:移除损坏的导入,修复循环引用
修复的范围安全性:
- 项目范围文件(CLAUDE.md、.claude/settings.json、.claude/rules/):可直接编辑并创建PR
- :直接编辑,绝不包含在PR中(已被Git忽略/属于个人文件)
CLAUDE.local.md - :直接编辑,绝不包含在PR中(属于个人本地设置)
.claude/settings.local.json - 下的文件:直接编辑,绝不包含在PR中(属于个人配置)
~/.claude/
Re-Score and Show Delta
重新评分并展示得分变化
After implementing fixes:
- Re-score only the affected categories
- Show before/after:
Score Delta:
Over-Engineering 65 → 85 (+20)
CLAUDE.md Quality 70 → 88 (+18)
Overall 72 → 84 (+12) Grade: C → B应用修复后:
- 仅对受影响的类别重新评分
- 展示修复前后的得分对比:
得分变化:
过度设计检测 65 → 85 (+20)
CLAUDE.md质量 70 → 88 (+18)
总体得分 72 → 84 (+12) 等级: C → BPhase 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 (single-select) to ask the user:
AskUserQuestion- "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:
- Verify CLI is available:
ghcommand -v gh - Verify is authenticated:
ghgh auth status - If either fails, tell the user CLI is required for PR delivery and fall back to "Keep as local edits"
gh
在尝试创建PR之前:
- 验证CLI是否可用:
ghcommand -v gh - 验证是否已认证:
ghgh auth status - 如果任一验证失败,告知用户创建PR需要CLI,并默认选择“保留为本地修改”
gh
Create the PR
创建PR
If PR delivery is selected and prerequisites pass:
-
Record the current branch:— 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.
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -
Create branch:(use today's date and current time to avoid same-day collisions)
git checkout -b claudit/improvements-YYYY-MM-DD-HHMM -
Stage changed project files: Only stage project-scoped files that were modified in Phase 4. Never stage:
- (gitignored/personal)
CLAUDE.local.md - (personal local settings)
.claude/settings.local.json - Any file under (personal config)
~/.claude/ - Any file outside the project root
-
Commit with a clear message including the score delta:
claudit: improve Claude Code configuration (score XX → YY) - [List key changes] -
Push with(same branch name as step 2)
git push -u origin claudit/improvements-YYYY-MM-DD-HHMM -
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 flag ensures the PR targets the user's original branch, not the repo default — so the diff only contains claudit's changes
--base
- Title:
-
Add inline review comments viafor each changed file. Use this JSON structure:
gh apibashgh 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 correctvalue, runlineand find line numbers within changed hunks. Thegit diff HEAD~1 -- path/to/filemust 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 usingline.gh pr commentAdd one comment per significant change. Keep comments concise and educational. -
Return the PR URL to the user.
如果用户选择创建PR且前置条件满足:
-
记录当前分支:— 这是用户在claudit创建自己的分支之前所在的分支。PR将以该分支为目标,这样差异对比仅显示claudit做出的更改。
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -
创建分支:(使用当前日期和时间命名分支,避免同日冲突)
git checkout -b claudit/improvements-YYYY-MM-DD-HHMM -
暂存修改的项目文件:仅暂存阶段4中修改的项目范围文件。绝不要暂存:
- (已被Git忽略/属于个人文件)
CLAUDE.local.md - (个人本地设置)
.claude/settings.local.json - 下的任何文件(个人配置)
~/.claude/ - 项目根目录外的任何文件
-
提交:使用清晰的提交信息,包含得分变化:
claudit: 优化Claude Code配置(得分XX → YY) - [列出主要更改] -
推送:执行(与步骤2中的分支名称一致)
git push -u origin claudit/improvements-YYYY-MM-DD-HHMM -
创建PR:通过:
gh pr create --base $CURRENT_BRANCH- 标题:
claudit: 优化Claude Code配置 - 正文:包含得分变化、更改列表的简洁摘要,并注明个人/全局配置已单独审计(如果是全面审计)
- 参数确保PR以用户的原始分支为目标,而非仓库默认分支——这样差异对比仅包含claudit做出的更改
--base
- 标题:
-
添加行内评审注释:通过为每个修改的文件添加注释。使用以下JSON结构:
gh apibashgh 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必须是新文件版本中属于差异块范围内的行号。针对每个差异块选择最具代表性的更改行。如果行号定位失败(返回422错误),则退化为使用line添加不带行号的通用PR注释。gh pr comment每个重要更改添加一条注释。注释需简洁且具有教育意义。 -
将PR URL返回给用户。
Fallback
降级方案
If is not available, not authenticated, or PR creation fails:
gh- Tell the user what happened
- Fall back to "Keep as local edits"
- Show a of what was changed
git diff --stat
如果不可用、未认证或PR创建失败:
gh- 告知用户具体问题
- 退化为“保留为本地修改”
- 展示输出的更改摘要
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 directory at all, focus the audit on global config and recommend project-level setup
.claude/ - 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/下的更改始终仅保留在本地