Skip to content

Thomaszhou22/self-refine-skill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺž Self-Refine Skill

Systematic self-reflection for AI agents.

Make every AI response better β€” before the user sees it.

License: MIT OpenClaw Claude Code Cursor GitHub Copilot Codex CLI Gemini CLI Windsurf JetBrains Benchmarked


What It Does

Most AI responses are first drafts. This skill adds an invisible self-review step before every response:

GENERATE β†’ CRITIQUE β†’ REFINE β†’ CHECK β†’ DELIVER

Based on peer-reviewed research showing ~20% quality improvement from iterative self-refinement (Madaan et al., 2023).

One file. Zero dependencies. Zero API cost. The host AI acts as its own critic.


Proven Results

Benchmarked on 20 questions across 5 categories with controlled before/after evaluation. β†’ Full report

Metric Result
Overall improvement +21.2%
Questions improved 20/20 (100%)
Best single improvement +43.9%

Per-dimension improvement:

Dimension Ξ”
Conciseness +27.7%
Actionability +25.0%
Response Completeness +24.8%
Logical Completeness +23.7%
Factual Accuracy +14.8%
Internal Consistency +11.9%

πŸ“– Read the full benchmark report β†’


Before & After

Example 1 β€” Code Debugging

User: "My React app crashes on page load. Error: Cannot read properties of undefined (reading 'map')"

❌ Without Self-Refine:

This error typically occurs when you try to call .map() on an undefined value. In React, this usually happens when you're trying to render a list but the data hasn't loaded yet. You should check if the variable is defined before mapping over it. You can use optional chaining or a conditional check. Here's an example:

{data && data.map(item => <div key={item.id}>{item.name}</div>)}

Also, make sure your state is initialized properly...

βœ… With Self-Refine:

The crash is .map() on undefined. Two fixes:

Quick fix:

{data?.map(item => <div key={item.id}>{item.name}</div>)}

Root cause:

const [data, setData] = useState([]);  // not useState() or null

Likely useState() returns undefined β†’ .map() throws.

Example 2 β€” Architecture Decision

User: "Redis or PostgreSQL for session storage?"

❌ Without Self-Refine:

Both are great options and the choice depends on your needs. Redis is fast and in-memory. PostgreSQL is durable but slower. Redis is generally preferred for sessions. But if you already have PostgreSQL, it works fine too. Consider speed, persistence, and complexity.

βœ… With Self-Refine:

Redis. Here's why:

Redis PostgreSQL
Latency ~0.1ms ~2-5ms
TTL Built-in Manual cleanup
Scale Millions, no schema cost Row bloat, VACUUM

Use PostgreSQL only if <100 users and you don't want Redis.

npm install connect-redis express-session
Example 3 β€” Concise Explanation

User: "Explain JWT in 3 sentences."

❌ Without Self-Refine:

JWT (JSON Web Token) is a popular method for handling authentication in web applications. It works by creating a signed token that contains user information and is sent with each request. The server can verify the token without needing to store session data, making it stateless and scalable. JWTs consist of three parts: a header, a payload, and a signature, all encoded in Base64...

βœ… With Self-Refine:

JWT is a signed JSON token (header.payload.signature) proving identity. After login, the server issues one; the client sends it in Authorization: Bearer <token> on every request. The server verifies the signature β€” no session storage needed.


How It Works

6 Reflection Dimensions

# Dimension Catches
1 Logical Completeness Broken reasoning chains
2 Factual Accuracy Unverified claims
3 Response Completeness Ignored sub-questions
4 Conciseness Redundancy, filler
5 Actionability Vague advice without steps
6 Internal Consistency Self-contradictions

4 Depth Levels (Auto-Selected)

Level When Rounds Token Cost
0 Simple Q&A 0 +0%
1 Most conversations 1 ~15%
2 Complex technical 2 ~30%
3 High-stakes / adversarial 3 ~50%

No configuration. The agent picks the right depth automatically based on task complexity.

Cross-Session Learning (Reflexion)

When the agent discovers a recurring error pattern during self-review, it saves a note to memory. Next session, it avoids the same mistake. Based on Shinn et al. (2023).


Installation

OpenClaw (recommended)
# Copy to your skills directory
cp -r self-refine-skill/ ~/.openclaw/skills/

That's it. OpenClaw auto-detects skills.

Claude Code
# Copy to your project
cp -r self-refine-skill/ skills/

# Add to CLAUDE.md
echo "Read and follow skills/self-refine-skill/SKILL.md" >> CLAUDE.md
Cursor
# Copy to project root
cp -r self-refine-skill/ skills/

# Add to .cursorrules
echo "Read and follow skills/self-refine-skill/SKILL.md" >> .cursorrules
Gemini CLI
# Copy to project, add to GEMINI.md
cp -r self-refine-skill/ skills/
echo "Read and follow skills/self-refine-skill/SKILL.md" >> GEMINI.md
GitHub Copilot
# Add to your repository's Copilot instructions
mkdir -p skills && cp -r self-refine-skill/ skills/
echo "Read and follow skills/self-refine-skill/SKILL.md" >> .github/copilot-instructions.md
Codex CLI (OpenAI)
cp -r self-refine-skill/ skills/
echo "Read and follow skills/self-refine-skill/SKILL.md" >> AGENTS.md
Windsurf
cp -r self-refine-skill/ skills/
echo "Read and follow skills/self-refine-skill/SKILL.md" >> .windsurfrules
Cline / AI Coding Assistants

Copy self-refine-skill/ to your project. Reference SKILL.md in your assistant's custom instructions.

JetBrains AI / Junie
  1. Open Settings β†’ Tools β†’ AI Assistant β†’ System Instructions
  2. Add: Read and follow skills/self-refine-skill/SKILL.md
  3. Place the skill folder in your project root
Zed
  1. Open Zed settings
  2. Add to your context or assistant instructions:
Read and follow skills/self-refine-skill/SKILL.md
Kiro
  1. Add skill folder to project
  2. Reference in Kiro's instruction configuration
OpenCode
  1. Add skill folder to project
  2. Add to AGENTS.md: Read and follow skills/self-refine-skill/SKILL.md
ChatGPT Custom GPT
  1. Open your GPT β†’ Settings β†’ Instructions
  2. Paste the contents of SKILL.md
  3. Save

Note: SKILL.md includes inline templates for environments without file access β€” all depth levels work. Reflection memory is in-conversation only (no persistence).

Any AI Tool

Copy SKILL.md into your system prompt or instructions file. That's the only file you need.


Platform Compatibility

Top platforms (most popular by usage):

Platform Rating Reflexion Memory Notes
Claude Code ⭐⭐⭐⭐⭐ βœ… File write #1 coding agent 2026, full support
Cursor ⭐⭐⭐⭐⭐ βœ… File write $2B ARR AI IDE, full support
GitHub Copilot ⭐⭐⭐⭐⭐ βœ… File write Largest user base, full support
Codex CLI ⭐⭐⭐⭐⭐ βœ… File write OpenAI's coding agent, full support
ChatGPT ⭐⭐⭐⭐ ⚠️ In-conversation Inline templates auto-load, all levels
Show all 14 supported platforms
Platform Rating Reflexion Memory Install
OpenClaw ⭐⭐⭐⭐⭐ βœ… memory/ dir Copy to skills/, auto-detect
Claude Code ⭐⭐⭐⭐⭐ βœ… File write Copy to project, add to CLAUDE.md
Cursor ⭐⭐⭐⭐⭐ βœ… File write Copy to project, add to .cursorrules
GitHub Copilot ⭐⭐⭐⭐⭐ βœ… File write Add to .github/copilot-instructions.md
Codex CLI ⭐⭐⭐⭐⭐ βœ… File write Add to AGENTS.md
Gemini CLI ⭐⭐⭐⭐⭐ βœ… File write Add to GEMINI.md
Windsurf ⭐⭐⭐⭐⭐ βœ… File write Add to .windsurfrules
Cline ⭐⭐⭐⭐⭐ βœ… File write Add to custom instructions
JetBrains AI / Junie ⭐⭐⭐⭐½ βœ… File write Add to AI Assistant instructions
Aider ⭐⭐⭐⭐ βœ… File write Place in project, reference with --file
Zed ⭐⭐⭐⭐ βœ… File write Add to Zed settings
ChatGPT GPT ⭐⭐⭐⭐ ⚠️ In-conversation Paste SKILL.md into GPT Instructions
Kiro ⭐⭐⭐⭐ βœ… File write Add to Kiro instructions
OpenCode ⭐⭐⭐⭐ βœ… File write Add to AGENTS.md

Academic Foundations

Paper Year What We Use
Self-Refine — Madaan et al. 2023 Core GENERATE→CRITIQUE→REFINE loop
Reflexion β€” Shinn et al. 2023 Persistent self-reflection memory
Chain-of-Verification β€” Dhuliawala et al. 2023 Verification questions for facts
Self-Calibration β€” Kadavath et al. 2022 Confidence assessment
CRITIC β€” Gou et al. 2023 Tool-interactive self-correction
Agentic Design Patterns β€” Andrew Ng 2024 Reflection as foundational pattern

Full bibliography: references/sources.md


File Structure

self-refine-skill/
β”œβ”€β”€ SKILL.md                          # Core instructions (the only required file)
β”œβ”€β”€ README.md                         # This file
β”œβ”€β”€ LICENSE                           # MIT
└── references/
    β”œβ”€β”€ sources.md                    # Academic sources with URLs
    └── reflection-templates.md       # Ready-to-use internal prompts per depth level

Good answers are like good code: no unnecessary lines, every line serves a purpose.

⭐ Star this repo if it improved your AI's output quality.

About

πŸͺž Systematic self-reflection for AI agents. GENERATE β†’ CRITIQUE β†’ REFINE β†’ CHECK. Based on peer-reviewed research. Zero API cost. Works with Claude Code, Cursor, Copilot, Codex CLI, and 10+ more platforms.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors