Skip to Content

/moai mx

Scans the codebase and adds @MX code-level annotations. Automatically inserts comments so AI agents can quickly understand code context.

One-line summary: /moai mx automatically installs “code navigation signs”. It marks dangerous code, important functions, and missing tests with @MX tags so AI agents understand your code better.

Slash Command: Type /moai:mx in Claude Code to run this command directly. Type /moai alone to see the full list of available subcommands.

Overview

@MX tags are metadata annotations attached to code. They help AI agents instantly identify important functions, dangerous patterns, and incomplete work. /moai mx analyzes the codebase with a 3-pass scan and automatically inserts appropriate tags.

@MX Tag Types

TagPurposeWhen to Use
@MX:ANCHORInvariant contractfan_in >= 3 (called from 3+ locations)
@MX:WARNDanger zoneComplexity >= 15, goroutine/async patterns
@MX:NOTEContext deliveryMagic constants, business rule explanations
@MX:TODOIncomplete workMissing tests, unimplemented SPEC

Usage

# Scan entire codebase > /moai mx --all # Preview (check without modifying) > /moai mx --dry # P1 priority only (high fan_in functions) > /moai mx --priority P1 # Force overwrite existing tags > /moai mx --all --force # Scan specific languages only > /moai mx --all --lang go,python # Lower threshold for more coverage > /moai mx --all --threshold 2

Supported Flags

FlagDescriptionExample
--allScan entire codebase (all languages, all P1+P2 files)/moai mx --all
--dryPreview only - show tags without modifying files/moai mx --dry
--priority P1-P4Filter by priority level (default: all)/moai mx --priority P1
--forceOverwrite existing @MX tags/moai mx --force
--exclude PATTERNAdditional exclude patterns (comma-separated)/moai mx --exclude "vendor/**"
--lang LANGSScan only specified languages (default: auto-detect)/moai mx --lang go,ts
--threshold NOverride fan_in threshold (default: 3)/moai mx --threshold 2
--no-discoverySkip Phase 0 codebase discovery/moai mx --no-discovery
--teamParallel scan by language (Agent Teams mode)/moai mx --team

Priority Levels

PriorityConditionTag Type
P1fan_in >= 3 (called from 3+ locations)@MX:ANCHOR
P2goroutine/async, complexity >= 15@MX:WARN
P3Magic constants, missing docstrings@MX:NOTE
P4Missing tests@MX:TODO

Execution Process

/moai mx executes in 3 passes.

Phase 0: Codebase Discovery

Auto-detection supporting 16 languages:

LanguageIndicator FilesComment Prefix
Gogo.mod, go.sum//
Pythonpyproject.toml, requirements.txt#
TypeScripttsconfig.json//
JavaScriptpackage.json//
RustCargo.toml//
Javapom.xml, build.gradle//
Kotlinbuild.gradle.kts//
RubyGemfile#
Elixirmix.exs#
C++CMakeLists.txt//
SwiftPackage.swift//
+5 moreLanguage-specific config filesVaries

Pass 1: Full File Scan

Scans all source files and generates a priority queue:

  • Fan-in Analysis: Count function/method reference counts
  • Complexity Detection: Lines, branches, nesting depth
  • Pattern Detection: Language-specific danger patterns (goroutines, async, threading, unsafe)

Pass 2: Selective Deep Read

Deep analysis of P1 and P2 files to generate accurate tag descriptions. Leverages project context (tech.md, structure.md, product.md).

Pass 3: Batch Edit

Inserts tags with 1 Edit call per file. Existing @MX tags are preserved (unless --force).

Batch Checkpoint

Large scans (50+ files) use batch processing:

  • Batch size: 50 files per iteration
  • Auto-commit: Intermediate results committed after each batch
  • Progress tracking: .moai/cache/mx-scan-progress.json
  • Resumable: Continue from where an interrupted scan stopped

When a rate limit is detected, the current batch is saved and the scan stops gracefully. Running /moai mx again resumes from the last checkpoint.

Agent Delegation Chain

Integration with Other Workflows

WorkflowMX Integration
/moai syncMX validation runs automatically during sync (SPEC-MX-002)
/moai editAuto-validates @MX tags on file edits (v2.7.8+)
/moai runAuto-triggers during DDD ANALYZE phase
/moai reviewIncludes MX tag compliance check

Frequently Asked Questions

Q: Do @MX tags affect code execution?

No, @MX tags exist only as comments. They have zero impact on code execution or performance.

Q: What happens with existing tags?

By default, existing tags are preserved. Use --force to overwrite them.

Q: Are auto-generated files tagged?

No. Generated files, vendor directories, and mock files are automatically skipped based on exclude patterns in .moai/config/sections/mx.yaml.

Last updated on