Analyze Wat
Compile a source file to WAT and analyze the output for codegen inefficiencies. Use after a codegen change to verify the output is clean, when investigating performance issues, or when creating optimization issues from real compiler output.
Get the complete skill folder, including its scripts and reference files.
When to use this skill
Use Analyze Wat when an AI agent needs a reusable SKILL.md workflow for this job: Compile a source file to WAT and analyze the output for codegen inefficiencies. Use after a codegen change to verify the output is clean, when investigating performance issues, or when creating optimization issues from real compiler output.
When not to use it
Skip Analyze Wat when the task is outside the coding category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.
How to install
Where will you use it?
mkdir -p ~/.claude/skills/analyze-wat # Save SKILL.md to ~/.claude/skills/analyze-wat/SKILL.md
- Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/analyze-wat/SKILL.md. For a shared project, commit the folder at .claude/skills/analyze-wat/ instead.
- Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
- For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.
Full install guide for Claude, Cursor, and Codex →
Try a starter prompt
After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.
Use the Analyze Wat skill for this task: After implementing a codegen change, to verify the output is clean. Confirm any required inputs or files before making changes.
What supports this recommendation?
80/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.
- Documentation
- 87/100
- Practical detail
- 92/100
- Source evidence
- 58/100
- Source signals
- 70/100
Model compatibility evidence
- claudeinferred
The skill text mentions Claude or a closely associated term. This is keyword-derived compatibility; no hands-on model test is recorded.
- chatgptuntested
No model-specific signal or recorded compatibility test was found.
- geminiuntested
No model-specific signal or recorded compatibility test was found.
- copilotuntested
No model-specific signal or recorded compatibility test was found.
- llamauntested
No model-specific signal or recorded compatibility test was found.
- perplexityuntested
No model-specific signal or recorded compatibility test was found.
- mistraluntested
No model-specific signal or recorded compatibility test was found.
- grokuntested
No model-specific signal or recorded compatibility test was found.
Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.
What this skill does
# Analyze WAT Output
Compile a source file to WAT and analyze the output for codegen inefficiencies.
## When to use - After implementing a codegen change, to verify the output is clean - When investigating performance issues - When creating optimization issues from real compiler output
## Steps
1. Compile the source to WAT: ```bash node --input-type=module -e " import { compile } from './scripts/compiler-bundle.mjs'; import fs from 'fs'; const src = fs.readFileSync('SOURCE_FILE', 'utf8'); const result = compile(src, { fileName: 'test.ts', emitWat: true }); if (!result.success) { console.log('ERRORS:', result.errors.slice(0,5).map(e => e.message).join('\n')); process.exit(1); } fs.writeFileSync('/tmp/output.wat', result.wat); console.log('WAT:', result.wat.length, 'chars | Binary:', result.binary.length, 'bytes'); " ```
2. Check for known inefficiency patterns:
| Pattern | How to detect | Severity | |---------|--------------|----------| | Duplicate locals | Same `(local $name` appearing twice with different types | Medium — bloats binary | | Infinity guard on constant modulo | `f64.abs` + `f64.const Infinity` + `f64.eq` near `f64.div`/`f64.trunc` | High — 10 extra instructions per `%` | | Dead drops | `local.tee N` followed later by `drop` with no intervening use | Medium — wasted stack ops | | TDZ flags unused | `(local $__tdz_` that are set to 1 but never checked | Low — extra locals | | String concat chains | Multiple consecutive `call $concat_import` | Medium — N-1 intermediate strings | | If-chain → br_table candidate | Same `local.get` + `f64.const N` + `f64.eq` + `if` repeated 3+ times | High — O(n) vs O(1) | | f64↔i32 roundtrip | `f64.convert_i32_s` immediately followed by `i32.trunc_sat_f64_s` | High — pure waste | | Redundant null guards | `ref.is_null` + `if` on provably non-null values (literals, new, struct.new) | Medium — unnecessary branches |
3. For each pattern found, note: - Source line that produced it - WAT line numbers - How many instructions could be saved - Which codegen file to fix
4. Create or update issues in `plan/issues/` citing specific source code and WAT output.
## Example
```bash # Analyze the default playground example node --input-type=module -e " import { compile } from './scripts/compiler-bundle.mjs'; import fs from 'fs'; const src = fs.readFileSync('playground/examples/dom/calendar.ts', 'utf8'); const result = compile(src, { fileName: 'calendar.ts', emitWat: true }); fs.writeFileSync('/tmp/calendar.wat', result.wat); console.log('Binary:', result.binary.length, 'bytes'); " # Then inspect: grep -n 'f64.const Infinity' /tmp/calendar.wat ```
Intended uses
- After implementing a codegen change, to verify the output is clean
- When investigating performance issues
- When creating optimization issues from real compiler output
Implementation notes
- Review the source instructions and adapt inputs before running the workflow.
Try it, then tell us how it went
A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.