cd /news/ai-agents/show-hn-self-improving-claude-code-w… · home › topics › ai-agents › article
[ARTICLE · art-181435] src=github.com ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Show HN: Self-improving Claude Code with turn-counter hook

A developer released a Claude Code skill, claude-skill-self-improve, that runs a recurring retro reviewing recent work, extracting reusable lessons into ~/.claude/ (CLAUDE.md, rules, memory, skills, agents) and pruning stale entries. A UserPromptSubmit hook script increments a per-session counter in ~/.claude/state/self-improve/<session_id>.count and prints a [self-improve] line every N turns, defaulting to 20 and configurable via SELF_IMPROVE_EVERY (0 disables it), or the retro can be triggered manually with /self-improve. Each retro writes its summary to ~/.claude/state/self-improve/last-retro.md for the next retro to read, and lessons belonging in a project repo are listed as proposals rather than applied.

key takeaway

Install the self-improve skill and its UserPromptSubmit hook to trigger a retro every 20 turns by default, tune cadence with SELF_IMPROVE_EVERY, and reset counters by deleting ~/.claude/state/self-improve/*.count.

read1 min views1 publishedDec 3, 2026
Show HN: Self-improving Claude Code with turn-counter hook
Image: Michielbdejong (auto-discovered)

A Claude Code skill that runs a recurring retro: it reviews recent work, extracts general, reusable lessons and folds them into ~/.claude/ (CLAUDE.md, rules, memory, skills, agents), pruning stale entries as it goes. A UserPromptSubmit hook nudges it every N turns; it can also be run by hand with /self-improve.

Note

This skill is a starting point, not a finished product. It is meant to be adapted to your own use case: edit SKILL.md to match where your lessons should live, what counts as a good lesson for your work, and how often the retro should run.

SKILL.md                          the skill
scripts/self-improve-counter.sh   turn-counter hook

Clone the skill into your skills folder:

git clone git@github.com:JonnaMat/claude-skill-self-improve.git ~/.claude/skills/self-improve

Install the hook script:

mkdir -p ~/.claude/hooks && cp ~/.claude/skills/self-improve/scripts/self-improve-counter.sh ~/.claude/hooks/ && chmod +x ~/.claude/hooks/self-improve-counter.sh

Register the hook in ~/.claude/settings.json (merge with any hooks you already have):

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/self-improve-counter.sh"
          }
        ]
      }
    ]
  }
}

Restart Claude Code and check /hooks lists theUserPromptSubmit entry.

On every prompt the script reads session_id from the hook's JSON payload, increments ~/.claude/state/self-improve/<session_id>.count, and every N-th turn prints a [self-improve] line, which Claude Code adds to the conversation as context. The skill then runs the retro (in the background when a subagent tool is available).

  • Cadence: SELF_IMPROVE_EVERY=30 claude (default 20).
  • Disable without removing the hook: SELF_IMPROVE_EVERY=0 .
  • Reset counters: delete ~/.claude/state/self-improve/*.count .
  • Each retro writes its summary to ~/.claude/state/self-improve/last-retro.md , which the next retro reads.

The retro writes only under ~/.claude/. Lessons that belong in a project repo are listed in its report as proposals for you to apply.

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/show-hn-self-improvi…] indexed:0 read:1min 2026-12-03 · —