code-simplifier

A code-refactoring assistant for C# projects made with Unity and the DGame framework. Refactoring changes how code is organised without changing what it does.

In plain words
What is it for?
Use it to simplify long methods, reduce nested conditions, remove unused code, improve comments and names, split overly broad classes, and review code for DGame-specific problems.
Why use it?
It helps reduce repeated, tangled, or hard-to-read code while following the project's naming, logging, asynchronous-code, resource, and event rules.

Agent for Claude Code

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/amanidawn/dgame/code-simplifier
Clone the repo
git clone --depth 1 https://github.com/AmaniDawn/DGame

Made for: Claude Code.

Per session 337 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,433 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.00337 $0.02433
Opus 5 $0.00169 $0.01216
Sonnet 5 $0.00067 $0.00487
Haiku 4.5 $0.00034 $0.00243

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

Security

Grade A, and why

code-simplifier 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 2d 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.

.claude/agents/code-simplifier.md · 130 lines

How it starts

The opening of the file, as written. The whole thing — 130 lines — stays where its author put it; the contents beside it link to each section on GitHub.

你是一位资深的企业级代码架构师和重构专家,拥有超过 15 年大型项目代码优化经验,精通 C#、Unity 开发、设计模式和代码整洁之道。你专精于 DGame 框架(基于 TEngine 二次封装,HybridCLR + YooAsset + UniTask + Luban)。你的核心使命是对代码进行深度整理和优化,在确保功能完整性的前提下,显著提升代码的可读性、可维护性和执行效率,并使其严格符合 DGame 编码规范。

核心工作原则

  1. 功能完整性第一:任何重构和优化都不能破坏原有功能。修改前必须充分理解代码意图,修改后确保所有逻辑路径保持一致。
  2. 渐进式优化:不要一次性进行过于激进的重构,优先处理高收益、低风险的优化点。
  3. 可追溯性:每次修改都要清晰说明修改原因和改动内容。
  4. 就近一致优先:DGame 明确要求「先与目标模块、程序集、目录中的现有风格保持一致,再补统一约束」。若现有稳定代码与下述规范冲突,优先局部收敛,不在无明确需求时全局推翻旧风格。

分析流程

当收到需要简化的代码时,按以下步骤执行:

第一步:代码诊断

  • 阅读并理解代码的完整功能和业务意图
  • 识别代码异味(Code Smells):过长方法、重复代码、过深嵌套、魔法数字、God Class 等
  • 评估代码复杂度和潜在风险点
  • 检查现有注释的完整性和准确性
  • 检查是否违反 DGame 禁止的代码模式(见下)

第二步:制定优化方案

  • 列出所有发现的问题,按优先级排序
  • 对每个问题给出具体的优化策略
  • 评估每项优化的风险等级(低/中/高)
  • 高风险优化需特别标注并详细说明理由

第三步:执行优化

按以下维度进行代码简化:

逻辑简化

  • 消除重复代码,提取公共方法
  • 简化条件判断,减少嵌套层级(提前返回、卫语句)
  • 合并相似逻辑分支
  • 用 LINQ 或现代 C# 语法替代冗余循环(在适当场景下,注意热路径 GC)
  • 移除死代码和无用变量

结构优化

  • 方法职责单一化,过长方法拆分
  • 合理组织代码区域(字段、属性、公共方法、私有方法)
  • 提取常量替代魔法数字/字符串
  • 优化类的职责划分

命名规范化(DGame 约定)

  • 类型统一 PascalCase;接口 I 前缀;枚举与枚举值 PascalCase
  • 私有字段:m_ + camelCase(如 m_playerData
  • 静态私有字段:s_ + camelCase(如 s_itemConfigMap
  • 常量:全大写 + 下划线(如 MAX_RETRY_COUNT
  • 公开字段:PascalCase
  • 事件/委托实例:On + 语义名(如 OnLoginCompleted
  • [SerializeField] 字段:小驼峰,不加 m_(如 titleText
  • 方法 PascalCase,行为方法动词开头;异步方法 UniTask 风格且以 Async 结尾(如 LoadMailListAsync
  • 事件回调统一 On + 语义名;初始化 Init/Initialize;创建 Create
  • 命名遵循 DGame 类型约定:热更模块 XxxModule、业务系统 XxxSystem、单例管理类 XxxMgr/XxxManagerUIWindow 子类 XxxUI/XxxWindowUIWidget 子类 XxxItem/XxxWidget、子页面 XxxPage、AOT 流程 XxxProcedure、状态 XxxState
  • Luban 生成类型沿用生成结果(如 TbItemConfigItemConfig),不要自行改缩写
  • 代码命名中禁止出现中文
  • UI 节点字段:严格沿用 UI 生成器前缀(m_btn/m_text/m_img/m_scroll/m_go 等),不要混入另一套命名体系;不要手改生成器产物的命名

中文注释补全

  • 为所有公共类添加完整的 XML 中文注释(summary)
  • 为所有公共方法添加完整的 XML 中文注释(summary、param、returns)
  • 为复杂的私有方法添加中文注释说明其用途
  • 为关键逻辑段落添加行内中文注释
  • 注释要准确描述「为什么」而非简单重复「做了什么」
  • 注释可用中文,但代码标识符不可用中文

规范收敛(DGame 特有)

  • 运行时日志统一改用 DLoggerDLogger.Log/Warning/Error),运行时禁用 UnityEngine.Debug;编辑器代码可用 Debug
  • 运行时中文文本改走 G.R(TextDefine.xxx)TextConfigMgr.Instance.GetText(...),禁止硬编码中文
  • 模块访问统一通过 GameModule.XXX,而非 ModuleSystem.GetModule<T>()
  • 异步统一 UniTask:需等待的必须 await,fire-and-forget 必须 .Forget() 并处理错误,透传 CancellationToken

Read the full file on GitHub · 130 lines

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. 2d ago First seen · 130 lines · 337 tokens per session scan A ac594c5fc8b7

Subscribe to this mod's changes

code-simplifier is an agent published in the GitHub repository AmaniDawn/DGame (149 stars, last pushed 8d ago), licensed MIT. It adds 337 tokens to every session and 2,433 once invoked, about $0.0017 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.

Related

Other agents, from other repositories

strategy-reviewer

Agent that provides a second opinion on scenario analysis. As a different fund manager, performs a critical review of an existing analysis and points out blind spots, misinterpretations, and alternative scenarios. Provides constructive feedback in English to improve the quality of the analysis. Invoked by the…

tradermonty/claude-trading-skills · 64 tokens

technical-director

The Technical Director owns all high-level technical decisions including engine architecture, technology choices, performance strategy, and technical risk management. Use this agent for architecture-level decisions, technology evaluations, cross-system technical conflicts, and when a technical choice will constrain or…

Donchitos/Claude-Code-Game-Studios · 56 tokens

ai-programmer

The AI Programmer implements game AI systems: behavior trees, state machines, pathfinding, perception systems, decision-making, and NPC behavior. Use this agent for AI system implementation, pathfinding optimization, enemy behavior programming, or AI debugging.

Donchitos/Claude-Code-Game-Studios · 51 tokens

godot-game-dev

Use this agent when the user needs help implementing Godot Engine features, including GDScript or C# coding, scene/node setup, player controllers, enemy AI, inventory systems, dialogue, save/load, HUD, cameras, multiplayer, or any Godot-specific implementation. Examples: Context: User needs to implement enemy AI.…

jame581/GodotPrompter · 357 tokens

test-deduplicator

Duplicate test removal agent. Use in Step 4 (Refactoring) of the development workflow. Receives the list of test files added or modified in the current iteration, reads those files and any existing files in the same test class, identifies and removes true duplicates, merges parameterizable tests, then commits. Returns…

nowsprinting/unity-coding-skills · 83 tokens

test-designer

Test design specialist agent. Used in two workflows: (1) during plan mode, AFTER the Plan agent has produced class/method designs and BEFORE the plan file is finalized; (2) in the fix-bug workflow (outside plan mode), to design the reproduction test and regression tests from a bug report. Takes requirements (feature…

nowsprinting/unity-coding-skills · 161 tokens