# Musk Step 3 Simplify Optimize

> Step 3 of the Musk algorithm. Simplify and optimize what survived deletion. Applies to BOTH brownfield (simplify existing survivors) and greenfield (build the simplest thing that works). Use whenever the user wants to optimize performance, refactor code, reduce complexity, improve a DAX measure, tune a query, restructure a pipeline, or choose the simplest viable implementation for a new feature.…

- **Type:** Skill
- **Install:** `agentstack add skill-wezendy-elon-musk-algorithm-skills-musk-step-3-simplify-optimize`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [wezendy](https://agentstack.voostack.com/s/wezendy)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [wezendy](https://github.com/wezendy)
- **Source:** https://github.com/wezendy/elon-musk-algorithm-skills/tree/main/skills/musk-step-3-simplify-optimize

## Install

```sh
agentstack add skill-wezendy-elon-musk-algorithm-skills-musk-step-3-simplify-optimize
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Step 3: Simplify and Optimize

**Only after steps 1 and 2. Optimizing a thing that should not exist is the most common smart-engineer failure.**

Part of the [[musk-algorithm]]. Third in the strict order.

## Gate

Before this step, verify in the conversation or diff:

* [[musk-step-1-question-requirements]] has produced a list of named, surviving requirements.
* [[musk-step-2-delete-parts]] has produced an explicit deletion list and predicted add-back.

If either is absent, stop. Run the missing step first. **This is the most common skip point. Refuse aggressively.**

## Why this step exists

Schools train convergent logic: answer the question. Engineers instinctively optimize before questioning whether the thing should exist. Musk identifies this as the single most common failure mode in smart engineering teams.

A simplification or optimization of a part that survived steps 1 and 2 is high-leverage. The same work on a part that should have been deleted is wasted, and worse, it hard-codes the unjustified part deeper into the system.

## Protocol

For each surviving part:

1. **Write the justification sentence.** Before any optimization, state in one sentence: *"This exists because [named person from step 1] requires [steelmanned requirement] and removing it causes [specific failure]."* If you cannot write this sentence, return to [[musk-step-1-question-requirements]]. This is the hard gate.
2. **Measure the pre-optimization state.** Parts, lines, parameters, branches, dependencies, special cases. Without this baseline, any "optimization" is unverifiable.
3. **Reduce.** In priority order: parameters, branches, special cases, moving parts, cognitive load, lines.
4. **Match existing style.** Do not refactor adjacent code that is not in scope. Surgical changes only.
5. **Measure the post-optimization state.** Report the complexity delta.

## Output format

```
Part: [what is being simplified]
Justification sentence: "This exists because [named person] requires [requirement] and removing it causes [failure]."
Pre-optimization state:
  - Parts: N
  - Lines: N
  - Parameters: N
  - Branches: N
  - Dependencies: N
  - Special cases: N
Optimization moves:
  1. [move + justification]
  2. [move + justification]
Post-optimization state:
  - Parts: N (delta)
  - Lines: N (delta)
  - Parameters: N (delta)
  - Branches: N (delta)
  - Dependencies: N (delta)
  - Special cases: N (delta)
Out-of-scope code touched: [should be empty, or explicitly justified]
```

## Software-specific guidance

* **Reduce parameters.** A function with 8 parameters is signalling that it does multiple things. Split, or bundle into a structured input.
* **Reduce branches.** Cyclomatic complexity is a proxy for how many states a future reader must hold in their head.
* **Reduce special cases.** Three near-identical code paths with one tiny difference is one code path with one parameter.
* **Reduce indirection.** Adapter calling wrapper calling helper is three layers where one might do.
* **Do not add abstractions for single-use code.** Karpathy's principle applies here.

## Anti-patterns to refuse

* "Let's optimize this query." Verify steps 1 and 2 first. Is the query still needed?
* "Let's refactor this module to use a strategy pattern." For how many strategies? If one, the pattern is bloat.
* "Let's add a config flag for flexibility." For which named user's requirement? If none, the flag is bloat.
* Optimizing adjacent code that was not in scope. Out of scope. Mention it, do not touch it.
* Optimizing a part whose justification sentence cannot be written. Return to step 1.

## Completion criteria

This step is done when:

* Every surviving part has a justification sentence on the record.
* Every optimized part has a measured complexity delta.
* No out-of-scope code has been touched without explicit justification.

Only then can [[musk-step-4-accelerate-cycle-time]] begin.

## See also

* [[musk-algorithm]] (overview)
* [[musk-step-2-delete-parts]] (previous)
* [[musk-step-4-accelerate-cycle-time]] (next)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [wezendy](https://github.com/wezendy)
- **Source:** [wezendy/elon-musk-algorithm-skills](https://github.com/wezendy/elon-musk-algorithm-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-wezendy-elon-musk-algorithm-skills-musk-step-3-simplify-optimize
- Seller: https://agentstack.voostack.com/s/wezendy
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
