Agent skill

Moai Workflow Loop

by modu-ai in modu-ai/moai-adk

Ralph Engine - Automated feedback loop with LSP diagnostics and AST-grep integration for continuous code quality improvement.

Apache-2.0Auto-check: notesDevelopment

Install Moai Workflow Loop

skills CLI
$ npx skills add modu-ai/moai-adk --skill moai-workflow-loop -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install modu-ai/moai-adk moai-workflow-loop --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/modu-ai/moai-adk.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/moai-workflow-loop .claude/skills/moai-workflow-loop && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
moai-workflow-loop
GitHub stars
1.2k
Token cost
~3.2k tokens
SKILL.md length
1,526 words
Files
3 (incl. references)
Skills in repo
48
Repo updated
First seen
Licence
Apache-2.0

At a glance

Ralph Engine - Automated feedback loop with LSP diagnostics and AST-grep integration for continuous code quality improvement.

  • Implementing error-driven development
  • SKILL.md covers Preset Architecture — the…, Quick Reference, Implementation Guide and Advanced Patterns, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Automated fixing

What it does

Moai Workflow Loop is an agent skill from modu-ai/moai-adk. Ralph Engine - Automated feedback loop with LSP diagnostics and AST-grep integration for continuous code quality improvement. Use when implementing error-driven development, automated fixing, or continuous quality validation workflows.

Its SKILL.md is about 3.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files, including reference files (for example `references/examples.md` and `references/reference.md`). Compatibility notes: Designed for Claude Code

It sits in Development, covering Code quality. The repository describes itself as: Agentic development harness for Claude Code — SPEC-driven plan/run/sync, TRUST 5 quality gates, model+effort routing, and Claude×GLM multi-LLM cost control. Single Go binary, 16… The licence is Apache-2.0.

When your agent uses it

  • Implementing error-driven development
  • Automated fixing
  • Continuous quality validation workflows

Example prompts

  • “/moai-workflow-loop”

Requirements

  • Compatibility (from SKILL.md): Designed for Claude Code
  • Pre-approved tools (allowed-tools): Read, Write, Edit, Bash, Grep, Glob

What it can do on your machine

Read from SKILL.md and the folder at commit 6c55321. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Bash
    • Grep
    • Glob

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Designed for Claude Code

    From compatibility in the SKILL.md frontmatter.

Context cost

Moai Workflow Loop loads about 3.2k tokens when it runs, and up to ~17k if it reads all its reference files. Until then it costs about 64 tokens; SKILL.md has 1,526 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~64
When it runs · the whole SKILL.md, loaded when a task matches
~3.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~17k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Edit, Bash, Grep, Glob

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from modu-ai/moai-adk at commit 6c55321, republished under its Apache-2.0 licence (© modu-ai). 1,526 words, ~3,189 tokens.

Download SKILL.mdSave it as .claude/skills/moai-workflow-loop/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
moai-workflow-loop
description
Ralph Engine - Automated feedback loop with LSP diagnostics and AST-grep integration for continuous code quality improvement. Use when implementing error-driven development, automated fixing, or continuous quality validation workflows.
allowed-tools
Read, Write, Edit, Bash, Grep, Glob
compatibility
Designed for Claude Code
license
Apache-2.0
effort
low
user-invocable
false
metadata.version
1.2.0
metadata.category
workflow
metadata.status
active
metadata.updated
2026-01-11
metadata.tags
lsp, ast-grep, feedback-loop, code-quality, automation, diagnostics, ralph

Ralph Engine

Automated feedback loop system integrating LSP diagnostics, AST-grep security scanning, and test validation for continuous code quality improvement.

Preset Architecture — the Ralph Engine as a goal preset

The /moai loop skill (.claude/skills/moai/workflows/loop.md) re-expresses this Ralph engine as a goal preset built ON the goal engine: a scan stage builds a finite issue queue, and the iterate-until-done decision is delegated to the goal engine (stop-goal) with the pre-filled condition "queue drained + diagnostics clean". In this preset architecture, this SKILL.md documents the underlying LSP / AST-grep / test / coverage diagnostic machinery that the goal-preset sweep drives; the preset layers the goal-engine composition on top of that machinery WITHOUT changing it. The four loop quadrants (goal-based sweep, turn-based /moai fix, time-based cadence, proactive CI-watch) are presets on the one goal engine, not independent engines.

Quick Reference

Core Capabilities:

  • LSP Integration: Real-time diagnostics from language servers
  • AST-grep Scanning: Structural code analysis and security checks
  • Feedback Loop: Iterative error correction until completion conditions met
  • Hook System: PostToolUse and Stop hooks for seamless Claude Code integration

Key Components:

  • .claude/hooks/moai/handle-post-tool.sh (PostToolUse): LSP diagnostics after Write/Edit operations
  • .claude/hooks/moai/handle-stop.sh (Stop): Loop iteration control
  • ralph.yaml: Configuration settings

Commands:

  • /moai: One-click Plan-Run-Sync automation (default)
  • /moai loop: Start feedback loop
  • /moai fix: One-time auto-fix

When to Use:

  • Implementing features with zero-error goal
  • Automated code quality improvement
  • Continuous integration workflows
  • Error-driven development patterns

Implementation Guide

Architecture Overview

The Ralph Engine follows a layered architecture. User commands such as /moai:loop, /moai:fix, and /moai enter the Command Layer. The Command Layer invokes the Hook System, which contains the PostToolUse Hook for LSP diagnostics and the Stop Hook for loop control. The Hook System connects to Backend Services including the LSP Client (MoAILSPClient), AST-grep Scanner, and Test Runner. Backend Services feed into Completion Check which evaluates whether errors are zero, tests pass, and coverage is met. Based on the Completion Check result, the system either continues the loop or completes.

Configuration

The ralph.yaml configuration file contains the following sections and settings.

Under the ralph section, enabled controls whether Ralph is active (true by default).

Under the lsp section, auto_start controls automatic language server startup (true by default), timeout_seconds sets the connection timeout (30 seconds default), and graceful_degradation enables fallback to linters when LSP unavailable (true by default).

Under the ast_grep section, enabled controls AST-grep integration (true by default), security_scan enables security rule checking (true by default), and quality_scan enables code quality rule checking (true by default).

Under the loop section, max_iterations sets the maximum loop iterations (10 by default), auto_fix controls automatic fix application (false by default requiring confirmation), and require_confirmation requires user approval before fixes (true by default).

Under the completion subsection of loop, zero_errors requires no LSP or compiler errors (true by default), zero_warnings requires no warnings (false by default as optional), tests_pass requires all tests to pass (true by default), and coverage_threshold sets minimum coverage percentage (85 by default).

Under the hooks section, post_tool_lsp has enabled (true by default) and severity_threshold (error by default). The stop_loop_controller has enabled set to true by default.

Hook Integration
PostToolUse Hook

The PostToolUse hook is triggered after Write and Edit operations. When invoked, Claude Code provides hook input containing the tool_name (such as Write) and tool_input containing the file_path and content.

The hook processes diagnostics and returns hook output with hookSpecificOutput containing the hookEventName (PostToolUse) and additionalContext describing the diagnostic results. For example, the context might report LSP found 2 errors and 3 warnings in file.py, with specific error messages including line numbers.

Exit code 0 indicates no action needed. Exit code 2 indicates attention needed due to errors found.

Stop Hook for Loop Controller

The Stop hook is triggered after each Claude response. The hook reads the loop state file located at .moai/cache/.moai_loop_state.json. This state contains active status (true or false), current iteration number, max_iterations limit, last_error_count from previous iteration, and completion_reason when finished.

The hook returns output with hookSpecificOutput containing hookEventName (Stop) and additionalContext reporting loop status. For example, it might report Ralph Loop CONTINUE at Iteration 3 of 10 with 2 Errors, and next actions to fix the remaining errors.

Exit code 0 indicates loop complete or inactive. Exit code 1 indicates continue loop with more work needed.

LSP Client Usage

The Go LSP client is integrated into the hook system. LSP diagnostics are automatically collected via the post-tool hook (moai hook post-tool-use).

To get diagnostics for a file, call the get_diagnostics method asynchronously with the file path.

Process the returned diagnostics by iterating through each diagnostic object. Check the severity property against DiagnosticSeverity.ERROR to identify errors. Access the line number from diag.range.start.line and the message from diag.message.

Completion Conditions

The loop completes when all enabled conditions are met.

The zero_errors condition (default true) requires no LSP or compiler errors.

The zero_warnings condition (default false) optionally requires no warnings.

The tests_pass condition (default true) requires all tests to pass.

The coverage_threshold condition (default 85) requires minimum coverage percentage.

Advanced Patterns

Custom Completion Conditions

Extend the loop controller with custom conditions by implementing a check function. For example, create a function to count TODO comments in the codebase and return true only when the count reaches zero.

Integration with CI/CD

For GitHub Actions integration, create a workflow step that runs Claude with the /moai:loop command and max-iterations flag. Set the MOAI_LOOP_ACTIVE environment variable to true to enable loop mode.

Graceful Degradation

When LSP is unavailable, the system falls back to linter-based diagnostics using tools like ruff or eslint, then to compiler error detection, and finally to test failure detection.

Troubleshooting

Show full SKILL.md (620 more words)Show less
Loop Not Starting

Check that ralph.enabled is set to true in configuration. Verify MOAI_DISABLE_LOOP_CONTROLLER environment variable is not set. Ensure the state file location is writable.

LSP Diagnostics Missing

Check LSP server configuration in .moai/config/sections/lsp.yaml. Verify the language server is installed for your language. Check that MOAI_DISABLE_LSP_DIAGNOSTIC environment variable is not set.

Loop Stuck

Review the max_iterations setting to ensure it allows sufficient iterations. Review completion conditions to verify they are achievable. Send any message to interrupt the loop, or delete the state file (.moai/cache/.moai_loop_state.json) to reset.

Works Well With

Skills:

  • moai-foundation-quality: TRUST 5 validation
  • moai ast-grep / moai ast-edit: security scanning patterns and rewrites
  • moai-workflow-testing: DDD integration
  • .claude/rules/moai/languages/python.md: Python-specific patterns (auto-loaded via paths frontmatter)
  • .claude/rules/moai/languages/typescript.md: TypeScript patterns (auto-loaded via paths frontmatter)

Agents:

  • manager-develop: DDD implementation
  • manager-develop (cycle_type=autofix): complex debugging and fix proposal (former manager-quality debug role)
  • /moai gate skill or sync-phase-quality-gate.sh Stop hook: quality validation (former manager-quality gate role)

Commands:

  • /moai:run: DDD implementation
  • /moai:sync: Documentation sync

Reference

Environment Variables

MOAI_DISABLE_LSP_DIAGNOSTIC disables the LSP hook when set.

MOAI_DISABLE_LOOP_CONTROLLER disables the loop hook when set.

MOAI_LOOP_ACTIVE indicates whether the loop is currently active.

MOAI_LOOP_ITERATION contains the current iteration number.

CLAUDE_PROJECT_DIR contains the project root path.

File Locations

Configuration is stored at .moai/config/sections/ralph.yaml.

Loop state is stored at .moai/cache/.moai_loop_state.json.

The LSP hook is located at .claude/hooks/moai/handle-post-tool.sh.

The loop hook is located at .claude/hooks/moai/handle-stop.sh.

Supported Languages

LSP diagnostics are available for all 16 MoAI-supported languages: C++, C#, Elixir, Flutter, Go, Java, JavaScript, Kotlin, PHP, Python, R, Ruby, Rust, Scala, Swift, and TypeScript. Ralph detects the project language via marker files (for example go.mod for Go, pyproject.toml for Python, tsconfig.json for TypeScript, Cargo.toml for Rust, pubspec.yaml for Flutter) and spawns the matching language server on demand. Users install only the servers their projects actually need; missing servers trigger a warn-and-skip with an install hint, never a hard failure. See references/reference.md for the complete language-server-to-binary mapping table. Per .claude/rules/moai/development/coding-standards.md § Language Policy (16-language neutrality contract), no language receives priority over another.


Version: 1.2.0 Status: Active Integration: Claude Code Hooks, LSP Protocol, AST-grep Skill Name: moai-workflow-loop (formerly moai-ralph)

<!-- moai:evolvable-start id="rationalizations" -->

Common Rationalizations

RationalizationReality
"I will fix the remaining errors manually after the loop"Manual follow-up means the loop did not finish its job. Errors left are errors shipped.
"The loop hit max iterations, the remaining issues are minor"Iteration limits exist for cost control, not as a quality seal. Report the unresolved list.
"LSP warnings are not real errors"Warnings that persist across iterations indicate ignored structural issues. Address or explicitly suppress.
"I fixed the root cause, the other diagnostics will clear themselves"Cascading fixes are not guaranteed. Run the diagnostic pass again and verify each resolution.
"ast-grep rules are too strict for this codebase"Rules reflect project conventions. Disable the specific rule with justification, do not skip the entire scan.
"This iteration made no progress, I should stop"Stagnation after 2 iterations triggers escalation, not silent exit. Follow the escalation protocol.

Rule of 500: Changes touching more than 500 lines deserve their own loop iteration with focused diagnostics. Large changes mask individual regressions.

<!-- moai:evolvable-end -->
<!-- moai:evolvable-start id="red-flags" -->

Red Flags

  • Loop exits with unresolved errors and no stagnation report
  • Same diagnostic appears in consecutive iterations without being addressed
  • ast-grep scan disabled entirely instead of disabling specific rules
  • Loop runs without LSP baseline captured at iteration start
  • Manual code changes made between loop iterations without re-running diagnostics
<!-- moai:evolvable-end -->
<!-- moai:evolvable-start id="verification" -->

Verification

  • Every iteration recorded in progress log with error count delta
  • Final iteration shows zero errors or an explicit stagnation report
  • LSP baseline captured at loop start (show diagnostic count)
  • ast-grep scan ran at least once during the loop (show output)
  • Unresolved items documented with reasons they could not be fixed
  • No diagnostic count increased between consecutive iterations
<!-- moai:evolvable-end -->

© modu-ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files (references) in .claude/skills/moai-workflow-loop of modu-ai/moai-adk.

  • SKILL.md
  • references/examples.md
  • references/reference.md

Open the folder on GitHubat commit 6c55321

Compare with similar skills

Moai Workflow Loop next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Moai Workflow Loop compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Moai Workflow Loop this skillmodu-ai/moai-adk1.2k—~3.2kAutomated safety check: NotesApache-2.0
WooCommerce Code Reviewwoocommerce/woocommerce11k3 repos~1.1kAutomated safety check: PassCustom licence
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT
Install Anti-Slop Oxlint Rulesdmmulroy/anti-slop5.2k—~2.2kAutomated safety check: PassMIT
Constraint-Driven Developmentaddyosmani/agent-skills102k2 repos~5.2kAutomated safety check: PassMIT
Skill Doli Code ReviewDolibarr/dolibarr7.7k1 repos~1.1kAutomated safety check: PassMIT

Similar skills

  • WooCommerce Code Review

    woocommerce/woocommerce

    Reviews WooCommerce code changes against the project's standards, flagging backend PHP architecture, naming, documentation, data integrity and testing violations.

    11k GitHub starsUsed in 3 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated 7 days ago
    DevelopmentAuto-check passed
  • Installs, updates or migrates the vendored anti-slop Oxlint plugin in a repository, keeping local rule changes and the plugin's license and provenance files.

    5.2k GitHub stars~2.2k tokensUpdated 27 days ago
    DevelopmentAuto-check passed
  • Constraint-Driven Development

    addyosmani/agent-skills

    Records a project's quality bar in CONSTRAINTS.md and watches diffs for signs an agent quietly weakened it, such as suppressions, skipped tests or lowered thresholds.

    102k GitHub starsUsed in 2 repos~5.2k tokens
    DevelopmentAuto-check passed
  • Skill Doli Code Review

    Dolibarr/dolibarr

    Reviews Dolibarr PHP code for compliance with coding standards and security best practices, and fixes identified issues.

    7.7k GitHub starsUsed in 1 repo~1.1k tokens
    DevelopmentAuto-check passed
  • Dignified Python Standards

    docling-project/docling

    Applies opinionated production Python conventions chosen by the project's Python version: modern type syntax, pathlib, explicit checks and interface guidance.

    68k GitHub stars~1.5k tokensUpdated today
    DevelopmentAuto-check passed

More from modu-ai/moai-adk

All 48 skills in this repo
  • Builds hand-editable SVG diagrams from computed layout coordinates, lints the source and renders a 2x PNG, with rules for when mermaid is the better choice.

    1.2k GitHub stars~5.2k tokensUpdated today
    Auto-check: notes
  • MoAI Foundation Core

    modu-ai/moai-adk

    Reference for MoAI-ADK's core development principles: TRUST 5 quality gates, SPEC-first domain-driven workflow, agent delegation and token budgeting.

    1.2k GitHub stars~5k tokensUpdated today
    Auto-check passed
  • MoAI SPEC Workflow

    modu-ai/moai-adk

    Manages SPEC documents for MoAI-ADK development, with GEARS or EARS requirement notation, acceptance criteria and a link into the Plan-Run-Sync workflow.

    1.2k GitHub stars~5.1k tokensUpdated today
    Auto-check passed
  • MoAI TDD Workflow

    modu-ai/moai-adk

    Drives test-first development through the RED, GREEN, REFACTOR cycle, with a config switch that selects between TDD and a DDD workflow for existing code.

    1.2k GitHub stars~3.1k tokensUpdated today
    Auto-check passed
  • MoAI Worktree Management

    modu-ai/moai-adk

    Gives each SPEC its own Git worktree with a registry of active workspaces, base-branch sync and cleanup of merged ones, inside the MoAI-ADK workflow.

    1.2k GitHub stars~3.9k tokensUpdated today
    Auto-check passed
  • Watches a pull request's CI checks after creation, separates required from auxiliary failures, applies limited safe fixes and escalates anything semantic to you.

    1.2k GitHub stars~2.4k tokensUpdated today
    Auto-check: notes

Categories

Questions about Moai Workflow Loop

What does Moai Workflow Loop do?

Ralph Engine - Automated feedback loop with LSP diagnostics and AST-grep integration for continuous code quality improvement. Moai Workflow Loop is an agent skill from modu-ai/moai-adk. Ralph Engine - Automated feedback loop with LSP diagnostics and AST-grep integration for continuous code quality improvement.

When should I use Moai Workflow Loop?

Moai Workflow Loop fits situations like: implementing error-driven development; automated fixing; continuous quality validation workflows.

How do I install Moai Workflow Loop in Claude Code?

Run `npx skills add modu-ai/moai-adk --skill moai-workflow-loop -a claude-code`. Or copy the skill folder (.claude/skills/moai-workflow-loop in modu-ai/moai-adk) into .claude/skills/moai-workflow-loop in your project. Claude Code loads it when a task matches its description.

How do I install Moai Workflow Loop in Codex?

Run `npx skills add modu-ai/moai-adk --skill moai-workflow-loop -a codex`. Or copy the skill folder (.claude/skills/moai-workflow-loop in modu-ai/moai-adk) into .agents/skills/moai-workflow-loop in your project. Codex loads it when a task matches its description.

Can I use Moai Workflow Loop in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add modu-ai/moai-adk --skill moai-workflow-loop -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/moai-workflow-loop, .gemini/skills/moai-workflow-loop, .github/skills/moai-workflow-loop and .opencode/skills/moai-workflow-loop in your project.

What does Moai Workflow Loop need to run?

SKILL.md names no scripts, command-line tools or credentials: Moai Workflow Loop is instructions for the agent only. Its frontmatter pre-approves these tools: Read, Write, Edit, Bash, Grep, Glob. Compatibility (from SKILL.md): Designed for Claude Code.

Does Moai Workflow Loop access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Moai Workflow Loop safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Moai Workflow Loop use?

Moai Workflow Loop is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Moai Workflow Loop use?

About 3.2k tokens (SKILL.md is roughly 13k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 14k tokens, read only when the agent opens those files.

What are the alternatives to Moai Workflow Loop?

Skills that share tags, products or a category with Moai Workflow Loop: WooCommerce Code Review (woocommerce/woocommerce, 11k stars), Systematic Code Refactoring (luongnv89/claude-howto, 42k stars), Install Anti-Slop Oxlint Rules (dmmulroy/anti-slop, 5.2k stars) and Constraint-Driven Development (addyosmani/agent-skills, 102k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Moai Workflow Loop?

modu-ai (a GitHub organization) maintains it in modu-ai/moai-adk, which has 1,230 GitHub stars. The repository holds 48 skills in this directory. The repository was last updated on October 7, 2026.

Source: modu-ai/moai-adk on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.