Skip to main content
skill CX Codex

reflexion — Claude Code skill: self-correcting code loop

A skill that runs implement, validate, self-critique and retry up to three times, then escalates with a written list of what is still broken.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add haabe/mycelium --skill reflexion -a claude-code
Open on GitHub

What reflexion does

The skill gives the agent a fixed order of work. It produces the deliverable first: code, a document or a config. Then it validates. For software that means linters, the test suite, the type checker and a security pass, plus accessibility checks when there is a UI. For written content it means checking facts, editorial standards and captions. Next comes self-critique against a checklist covering DRY, KISS, YAGNI, edge cases, error handling and whether the names say what they mean. Everything clean means done. Otherwise the agent fixes the gaps and loops again, with a hard stop at three rounds.

Verification moves from cheap to expensive. Deterministic rules such as eslint and yamllint run first, then anything that executes code such as pytest or npm test, and only after that do probabilistic checks like an LLM judge show up. Hit the third round with problems left and the skill stops fixing and starts reporting: attempts per round, severity of what remains, and which items block release.

This skill is built to run inside the Mycelium framework. Used alone it skips the canvas state, theory gates and harness behaviour it assumes, so install the framework too: /plugin install mycelium@haabe-mycelium. The loop also leans on corrections.md, patterns.md and delivery-journal.md — past mistakes, known patterns and the round-by-round log all live there.

What it helps with

  • run lint, tests and type checks before handing code to a reviewer
  • catch unescaped input, hardcoded secrets and vulnerable dependencies
  • check a UI for keyboard access, contrast and semantic markup
  • walk through edge cases before a user runs into them
  • stop after three attempts and write down what still blocks the work

Example prompts for the agent

  • Implement the POST /orders endpoint against the acceptance criteria and run the reflexion loop
  • Build the signup form and put it through the self-critique checklist
  • Audit this module for OWASP issues and print the iteration report

How to install reflexion

1Skills CLI (Vercel)

npx skills add haabe/mycelium --skill reflexion -a claude-code

2Manually: put the files in place

~/.claude/skills/reflexion/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/reflexion/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about reflexion

How do I install reflexion in Claude Code?

Run npx skills add haabe/mycelium --skill reflexion -a claude-code. The skill lands at ~/.claude/skills/reflexion/SKILL.md.

What does reflexion do?

It drives the agent through implement, validate, self-critique and decide. Three rounds at most, then it escalates with the remaining issues documented.

Does reflexion need the Mycelium framework?

Yes. It relies on the framework's canvas state, theory gates and harness. Install the framework with /plugin install mycelium@haabe-mycelium.

Source text

SKILL.md · MIT
---
name: reflexion
description: "Use for self-correcting implementation. Implements the reflexion loop: implement, validate, self-critique, retry (max 3 iterations)."
metadata:
  instruction_budget: "52"
  framework_dependency: "mycelium"
  framework_dependency_note: "This skill is designed to run within the Mycelium framework (https://github.com/haabe/mycelium). Standalone use will skip the canvas state, theory gates, and harness behavior the skill assumes. Install: /plugin install mycelium@haabe-mycelium."
---

# Reflexion Skill

Self-correcting implementation loop from the n-trax pattern.

## Workflow

### Iteration Loop (max 3)

**Step 1: Implement**
- Create the deliverable according to the specification/acceptance criteria.
  - Software: write code. Content: write/produce content. AI tool: write prompts/configs. Service: document workflow.
- Follow ${CLAUDE_PLUGIN_ROOT}/harness/engineering-principles.md (principles apply to all product types).
- Apply patterns from patterns.md.
- Check corrections.md for relevant past mistakes.

**Step 2: Validate**
- Software: Run tests, linter, type checker, security scan, accessibility checks (if UI).
  - **Security validation (OWASP)**: Check input validation, output encoding, parameterized queries, no hardcoded secrets, authentication/authorization patterns, dependency vulnerabilities. Reference OWASP Top 10:2025 categories for each check.
- Content: Review against learning objectives/editorial standards, check accessibility (captions, alt text), fact-check claims.
- AI tool: Run eval test cases, red-team testing, bias assessment.
- Service: Walk through the service blueprint end-to-end, verify documentation completeness.
- All: Verify acceptance criteria.

**Step 3: Self-Critique**
Review the implementation against (select items relevant to product_type):
- [ ] Engineering principles: DRY, KISS, YAGNI, SoC (apply to all product types)
- [ ] Security: Input validation, output encoding, no secrets, parameterized queries (software, ai_tool)
- [ ] Accessibility: Semantic HTML, keyboard nav, contrast, screen reader (software); captions, transcripts, alt text (content)
- [ ] Edge cases: What happens with unexpected input? Empty? Adversarial? (software, ai_tool)
- [ ] Error handling / user recovery: Are errors handled gracefully? Can users recover? (software, service)
- [ ] Quality: Factual accuracy, style consistency, source attribution (content); eval scores, safety scores (ai_tool)
- [ ] Naming / clarity: Do names reveal intent? Would a new reader understand this? (all)
- [ ] Completeness: Is anything missing that the user would expect? (all)

**Step 4: Decide**
- If all validations pass AND self-critique finds no issues: **DONE**
- If issues found AND iteration < 3: **FIX and return to Step 1**
- If iteration = 3 AND issues remain: **ESCALATE** with documented issues

### Escalation Protocol
When max iterations reached without full resolution:
1. Document what was attempted in each iteration.
2. Document remaining issues with severity assessment.
3. Recommend: fix now (blocking) vs. fix later (non-blocking) vs. accept risk.
4. Update corrections.md with learnings.

## Verification Modes

The validate step in the reflexion loop should use the appropriate verification mode:

### Rules-Based (deterministic)
- Linters, formatters, schema validators, type checkers
- Pass/fail is unambiguous — no judgment needed
- Always run first — fastest and cheapest
- Examples: `eslint`, `mypy`, `yamllint`, YAML schema validation against ${CLAUDE_PLUGIN_ROOT}/engine/canvas-guidance.yml

### Computational (deterministic)
- Test runners, build systems, security scanners
- Requires executing code — slower than rules-based
- Results are objective but may need interpretation (flaky tests)
- Examples: `pytest`, `npm test`, `cargo clippy`, OWASP dependency check

### Inferential (probabilistic)
- LLM-as-judge, peer review, heuristic evaluation
- Used when rules-based and computational verification are insufficient
- Results require confidence scoring — never treat as definitive
- Examples: `/mycelium:devils-advocate`, `/mycelium:usability-check`, auto-dogfood evaluation, design review
- The auto-dogfood system is an inferential verification loop

**Order**: Always attempt rules-based → computational → inferential. Only escalate to the next mode when the previous mode cannot verify the property in question.

*Source: Trivedy (Anatomy of an Agent Harness, LangChain blog). Three-mode taxonomy adapted from Böckeler (Harness Engineering, martinfowler.com — computational vs inferential distinction). Note: harnesses continue to matter even as models improve — they engineer systems around model intelligence, not just patch deficiencies.*

## Rules
- Each iteration must show measurable improvement over the previous.
- If the same issue recurs across iterations, investigate root cause rather than patching symptoms.
- Never skip the self-critique step, even if tests pass.
- Log the reflexion loop outcome in delivery-journal.md.
- **NUDGE-AT-FAILURE** (4-layer JIT composition): if the failure being reflexed on is a class a standard tool (linter, SAST, secrets scanner, dep audit) would have caught automatically, append a single-line nudge to the reflexion output: *"This class of failure is what `{tool}` catches automatically — want help wiring it up now?"* Never auto-install. Per `feedback-jit-nudge-not-push` (founder principle, 2026-05-26).

## Theory Citations
- Reflexion pattern (Shinn et al.)
- Clean Code (Martin)
- OWASP secure coding
- WCAG 2.1 AA

© haabe · MIT · haabe/mycelium

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set14

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor