Agent Self-Correction
Protocols for the agent to autonomously detect failures, analyze root causes, and attempt recovery strategies before requesting user intervention.
by majiayu000★ 31 GitHub stars
Install Agent Self-Correction in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Agent Self-Correction
[Context: Errors and roadblocks are inevitable. An efficient agent does not stop at the first sign of failure; it analyzes the error, adjusts its approach, and retries. This skill defines the cognitive loop for autonomous self-correction.]
1. Core Principles
- Analyze First: Never retry the exact same action without understanding why it failed.
- Fail Fast, recover Faster: Identify failure modes immediately (tech stack mismatch, syntax error, hallucination).
- Graceful Escalation: Attempt 2-3 autonomous fixes before escalating to the user.
- State Preservation: Don't destroy partial progress when fixing a specific bug.
2. Step-by-Step Implementation
Phase 1: Failure Detection & Analysis
When a tool returns an error or a check fails:
- Stop: Do not proceed to the next step of the plan.
- Read: Analyze the error message thoroughly.
- Is it a syntax error? -> Fix code.
- Is it a logic error? -> Rethink algorithm.
- Is it a tool misuse? -> Check tool definition.
- Is it environmental? -> Check paths/permissions.
- Hypothesize: Formulate a hypothesis for the fix.
Phase 2: autonomous Recovery Loop
- Attempt 1 (Quick Fix): Address the obvious error (e.g., install missing package, fix typo).
- Verify: Run the verification command (e.g.,
npm run buildorpytest). - Attempt 2 (Alternative Approach): If Attempt 1 fails, try a different distinct strategy (e.g., switch library, rewrite logic).
- Attempt 3 (Simplify): Reduce complexity or scope to isolate the issue.
Phase 3: Escalation
If Attempt 3 fails:
- Gather Context: Collect error logs and the 3 failed attempts.
- Propose solution: Present the user with the situation and a proposed manual intervention or request for clarification.
3. Templates & Examples
Internal Monologue for Debugging
ERROR DETECTED: [Error Message]
ANALYSIS: The error implies [Cause].
HYPOTHESIS: If I change [X] to [Y], it should resolve.
ACTION: Applying fix [X->Y].
Self-Correction Checklist
- Did I read the entire error message?
- Have I checked if the file path is correct?
- Did I verify the library version compatibility?
- Is this a hallucinated import?
4. Common Pitfalls
- Don't: Blindly loop the same command hoping it works eventually.
- Don't: Delete the user's codebase to "start over" without permission.
- Do: Use
common_senseto judge if an error is a simple typo or a fundamental design flaw.
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- metadata.json
FAQ
What does the Agent Self-Correction skill do?
Protocols for the agent to autonomously detect failures, analyze root causes, and attempt recovery strategies before requesting user intervention.
How do I install the Agent Self-Correction skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the Agent Self-Correction skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…