Borrowing it
Nothing to install: this file belongs to Awesome-Embedded-Learning-Studio/CFDesktop. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/Awesome-Embedded-Learning-Studio/CFDesktop/main/.claude/commands/optimize.mdgit clone --depth 1 https://github.com/Awesome-Embedded-Learning-Studio/CFDesktopWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/commands/awesome-embedded-learning-studio/cfdesktop/optimize)<a href="https://agentmods.dev/commands/awesome-embedded-learning-studio/cfdesktop/optimize"><img src="https://agentmods.dev/badge/commands/awesome-embedded-learning-studio/cfdesktop/optimize/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/commands/awesome-embedded-learning-studio/cfdesktop/optimize"><img src="https://agentmods.dev/badge/commands/awesome-embedded-learning-studio/cfdesktop/optimize.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00000 | $0.00865 |
| Opus 5.5 | $0.00000 | $0.00346 |
| Sonnet 5.5 | $0.00000 | $0.00173 |
| Haiku 4.5 | $0.00000 | $0.00086 |
Grade A, and why
optimize 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 2mo 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.
What it actually says
/optimize — 代码优化
基于 C++23 和现代 C++ 工程实践,对代码进行逼近零开销的小改动优化。
触发方式
/optimize <文件/函数>— 优化指定代码- Review 输出对接 — 用户基于审查报告请求优化
硬约束 (MUST)
- 每项优化改动 1-5 行
- 禁止改变公共 API 签名(破坏 ABI)
- 禁止改变行为(只做优化)
- 禁止大规模重构
- 必须通过
-Wall -Wextra -Wpedantic编译 - 必须通过现有测试
- 每文件每轮最多 10 项优化
- 不确定时加
@note FIXME而非猜测
优化流程
Step 1: 读取目标代码
- 读取指定文件完整内容
- 读取相关头文件和测试文件
- 理解类层次和使用上下文
Step 2: 优化检查清单
2.1 constexpr 提升
- 编译期可计算的函数 →
constexpr - 魔数 →
constexpr常量 - 类型特征和辅助工具 →
constexpr优先于模板元编程 if constexpr替代运行时分支(类型分发场景)
2.2 移动语义
- 按值返回 vs 显式
std::move(NRVO 场景不要 move,会阻碍优化) - Sink 参数用按值传递 +
std::move进成员 - 构造函数中用
std::move初始化成员 - 不要对返回局部变量
std::move(阻碍 RVO/NRVO)
2.3 零开销抽象
- 编译期可确定的多态 → 模板参数替代虚分派
- 小函数隐式内联(头文件定义)
- CRTP 替代虚分派(静态多态)
- 固定大小容器 →
std::array替代std::vector
2.4 [[nodiscard]] 标注
- 所有 const getter
- 返回所有权的工厂函数
- 返回
expected<T>或错误码的函数 - 忽略返回值会导致 bug 的函数
2.5 智能指针优化
- 独占所有权 →
std::unique_ptr(零开销) - 共享所有权 →
std::shared_ptr(仅在必要时) std::make_unique/std::make_shared优于裸new- 观察者模式 → 裸指针/引用,不用智能指针
2.6 Qt 特定优化
QString→ 使用QStringView/qsizetype- Signal/Slot → 新式连接 (
&Class::method) - 避免
QString::fromStdString不必要转换 - 像素操作 →
QImage优于QPixmap Q_FOREACH→ 范围 for 循环
Step 3: 输出格式 (中文)
# 优化建议: <file_name>
## 优化 1: <标题>
- **类别**: constexpr/移动语义/零开销/[[nodiscard]]/智能指针/Qt
- **当前代码**:
```cpp
// file:line
- 优化后代码:
// 修改后 - 原理: ...
- 影响范围: 低/中
- 验证方法: 编译 + 运行测试
优化 2: ...
总结
- 优化项数: N
- 预估性能提升: ...
- 风险等级: 整体低/中
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.
- 2mo ago First seen · 94 lines · 0 tokens per session scan A 442332c5abc0
optimize is a command published in the GitHub repository Awesome-Embedded-Learning-Studio/CFDesktop (11 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 865 tokens. 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-31.
Other commands, from other repositories
verify-claim
A command for checking whether a C++ claim is true by compiling and running a small example, with reference material when needed.
explain
A command that teaches a C++ concept using the repository's existing learning materials and examples. It explains both why the concept matters and how it works, with a small compilable example.
cpp-test
Enforce TDD workflow for C++. Write GoogleTest tests first, then implement. Verify coverage with gcov/lcov.
lift-class
Batch-lift all methods of a C++ class with shared type context, producing a single cohesive .cpp output file with struct definitions, constants, and all methods in dependency order. Uses assembly as ground truth to ensure 100% functional equivalence.
reconstruct-types
Reconstruct C/C++ struct and class definitions from a module's decompiled code by scanning memory access patterns, vtable contexts, and mangled names across all functions. Generates compilable C++ header files with per-field confidence annotations.
list
List all GUI-Anything harnesses in the current repository.