Teaching Claude Code to Discover and Automate Reusable Skills
- Authors

- Name
- Nino
- Occupation
- Senior Tech Editor
In a previous discussion, we explored the architecture of splitting Claude Code’s memory into four distinct layers. This article dives into the practical implementation of a self-evolving system: a setup where Claude Code discovers "reusable procedures" and accumulates them as skills over time. After operating this environment for several months, my ~/.claude/skills/auto/ directory now hosts over 64 auto-generated skills, significantly reducing the cognitive load of repetitive debugging and configuration.
The Problem: The "Amnesia" of LLM Sessions
Claude Code is exceptionally capable within a single session. However, across different sessions, it often suffers from a form of amnesia. It forgets the specific sequence of commands required to fix a launchd exit 78 error, the precise steps to bake a favicon with png-to-ico, or the nuanced configuration needed to trim the RSC payload in a Next.js project.
Re-solving these problems from scratch is a waste of tokens and time. While one could manually update CLAUDE.md, this "whoever notices, writes it" workflow is fragile and rarely scales. To solve this, I designed a system where Claude Code is responsible for identifying its own successful procedures and codifying them into a permanent skill library. This is where using a high-performance aggregator like n1n.ai becomes essential, as the frequent background processing requires stable, high-concurrency API access.
The Two-Tiered Skill Generation Architecture
The system is split into two layers to balance immediate utility with long-term organization.
| Tier | Timing | Cost | Owner |
|---|---|---|---|
| In-session generation | Real-time during work | Free / Instant | Claude itself (via CLAUDE.md) |
| Nightly batch generation | Daily cron at 3:30 AM | Consumes Max quota | skill-harvest.sh (headless) |
Tier 1: In-Session Reactivity
The first layer resides in the CLAUDE.md file. By providing specific instructions, Claude is empowered to create a new skill file the moment it realizes it has solved a non-trivial problem. The prompt logic is critical: we must prevent "skill bloat."
CLAUDE.md Configuration Excerpt:
## Auto-Skill Generation Rules
If you discover a procedure with high reuse value, generate a skill without being asked.
However, do not overproduce.
### Generation Triggers:
- Completion of a non-obvious task requiring > 5 tool calls.
- Finding a working workaround after hitting a dead end/error.
- After a user corrects your approach (to prevent repeating the mistake).
- Discovery of a specific sequence of commands or workflow that is environment-agnostic.
Tier 2: The Nightly Harvester
Procedures that were missed during a live session are captured by a nightly batch process. This script, skill-harvest.sh, uses the claude -p (headless) command. Because this involves heavy processing of conversation logs, routing these requests through a reliable provider like n1n.ai ensures that the batch job doesn't fail due to rate limits or unexpected downtime.
The Pipeline Logic:
- Watermarking: Read
.harvest-watermarkto find where the last scan ended. - Extraction: Pull the diff of conversation logs (
raw/conversations/*.md). - Analysis: Use Claude in headless mode to identify frequent patterns (appearing > 5 times).
- Deduplication: Compare candidates against the 64 existing skills using kebab-case name matching.
- Validation: Write to
<name>/SKILL.mdwith structured Frontmatter.
Namespace Isolation and the Curator
To prevent auto-generated skills from interfering with hand-written ones, I use a dedicated namespace: ~/.claude/skills/auto/. This isolation is crucial for two reasons:
- Safety: Tools like
npx skills updateoften wipe the standard skill directory. Theauto/path is excluded from these global resets. - Management: The "Curator" script only targets files where
author: autois present in the frontmatter.
The Skill Metadata Structure:
---
name: nextjs-rsc-payload-trim
description: Steps to reduce React Server Component payload size
author: auto
created: 2024-05-30
version: 1.0.0
status: active
---
The Curator: Fighting Skill Rot
Skills, like code, rot over time. A weekly skill-curate.sh script manages the lifecycle of these autonomous files:
- Snapshots: Creates a
tar.gzbackup before any changes. - Demotion: If a skill hasn't been invoked in 30 days, status is changed to
stale. - Archival: If unused for 90 days, it is moved to
.archive/. - Consolidation: The curator generates a
.curator-proposals.mdfile suggesting merges for overlapping skills (e.g., merginggit-rebase-fixandgit-conflict-resolver).
Observed Generation Curve
Data from the last quarter shows a fascinating trend. In the first 72 hours of enabling this system, 28 skills were generated in a massive burst. These were the "unverbalized procedures" that Claude had already been performing but hadn't yet codified. After this initial spike, the rate stabilized to roughly 0.5 to 1 skill per day.
- Day 1-3: 28 skills (The "Release" phase)
- Week 2-4: 12 skills (The "Refinement" phase)
- Month 2+: ~5 skills/month (The "Steady State")
This logarithmic growth suggests the system successfully captures the "long tail" of specific technical workflows without spiraling into infinite noise.
Pro-Tips for Implementation
- Token Management: When running
claude -pfor harvesting, the system prompt can be massive. UseMAX_THINKING_TOKENS=10000to ensure the model has enough "brain space" to analyze logs without hitting limits. For high-volume token needs, n1n.ai offers the most cost-effective scaling options. - Watermark Integrity: If you forget to advance the watermark, the harvester will re-process old logs, leading to duplicates. Always wrap the watermark update in a
try-catchblock in your shell script. - Headless MCP: Loading all Model Context Protocol (MCP) servers in headless mode is slow. I recommend maintaining a
harvest-minimal-config.jsonthat only loads essential filesystem tools.
Conclusion
Building a self-replicating agent environment isn't about creating a "god-like" AI; it's about building a system that respects its own past successes. By automating the verbalization of procedures, you transform Claude Code from a stateless tool into a personalized engineering partner that grows alongside your codebase.
Get a free API key at n1n.ai