claude-md-forge

Generate or optimize a CLAUDE.md and .claude/ infrastructure for a repository. Use when user says "create CLAUDE.md", "optimize CLAUDE.md", "set up .claude", "audit my CLAUDE.md", or is bootstrapping a new project.

6 stars

Best use case

claude-md-forge is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generate or optimize a CLAUDE.md and .claude/ infrastructure for a repository. Use when user says "create CLAUDE.md", "optimize CLAUDE.md", "set up .claude", "audit my CLAUDE.md", or is bootstrapping a new project.

Teams using claude-md-forge should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/claude-md-forge/SKILL.md --create-dirs "https://raw.githubusercontent.com/alxxpersonal/forge/main/skills/claude-md-forge/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/claude-md-forge/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How claude-md-forge Compares

Feature / Agentclaude-md-forgeStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generate or optimize a CLAUDE.md and .claude/ infrastructure for a repository. Use when user says "create CLAUDE.md", "optimize CLAUDE.md", "set up .claude", "audit my CLAUDE.md", or is bootstrapping a new project.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# CLAUDE.md Forge

Generate the best possible CLAUDE.md and .claude/ infrastructure for a repository. Research-backed principles, patterns from top open-source repos.

## When to Use

- Bootstrapping a new project
- Optimizing an existing CLAUDE.md
- Setting up .claude/ directory (rules, skills, settings, hooks)
- Auditing current CLAUDE.md for anti-patterns

## Process

Target repository: $ARGUMENTS (if blank, use current working directory).

### Step 1: Analyze the Repository

Read the codebase to understand:
- Languages and frameworks used
- Build system and package manager
- Test framework and commands
- Project structure (monorepo vs single package)
- Existing CLAUDE.md, .claude/, AGENTS.md, CONTRIBUTING.md
- CI/CD setup
- Linting and formatting tools

### Step 2: Apply Research-Backed Principles

The following principles are derived from 23+ academic papers and official Anthropic documentation.

#### Attention and Positioning

**Primacy effect dominates.** Evidence shows LLMs attend most strongly to the beginning and end of context, with 30%+ accuracy drop for middle content. The primacy effect is stronger than recency.

**Action:** Put the 3-5 most critical behavioral rules at the TOP of CLAUDE.md. Put the "Do NOT" prohibitions at the BOTTOM. Reference material goes in the middle where lower attention is acceptable.

#### Length and Density

**More context hurts even with perfect retrieval.** Evidence shows performance degrades 13-85% as input length increases, regardless of content quality.

**Instruction following degrades with count.** Studies across 20 frontier models show threshold decay at ~150 instructions for reasoning models, linear decay for Claude Sonnet. Errors shift from "wrong thing" to "forgetting entirely" above ~100 instructions.

**Action:** Target under 200 lines per CLAUDE.md (official Anthropic guidance). Target 30-70 distinct instructions (sweet spot). Apply the pruning test: "Would removing this line cause Claude to make mistakes?" If no, cut it.

#### Formatting

**Markdown formatting improves performance up to 40%** compared to unformatted text for Claude-class models.

**Action:** Use `##` headers for sections, `-` bullets for lists, backtick code blocks for commands. Max 2 levels of heading nesting.

#### Instruction Framing

**Negative instructions are disproportionately forgotten** under cognitive load. Evidence shows excessive constraints can cause advanced models to over-focus on avoidance instead of achieving goals.

**Positive instructions outperform negative ones.** "All SQL in .sql files via QueryLoader" beats "Do NOT write inline SQL."

**Action:** State rules positively in their relevant sections. Reserve "Do NOT" for 3-5 genuinely critical prohibitions that have no positive equivalent. Use ALWAYS/NEVER/PREFER/AVOID verb prefixes for unambiguous scanning (astral-sh/uv pattern).

#### Context Persistence

**CLAUDE.md survives compaction.** It is re-injected fresh on every API request. It is the single most durable piece of project context.

**At 70% context utilization, instruction precision drops.** At 90%+, behavior becomes erratic. Shorter CLAUDE.md = more room for actual work.

**Action:** Keep CLAUDE.md short. Add a "Compact Instructions" section telling the compaction process what to preserve.

#### Instruction Hierarchy

**System/user priority is unreliable.** Even simple formatting conflicts produce inconsistent behavior in choosing which instruction wins across all major LLMs (Control Illusion, 2025).

**Action:** Make CLAUDE.md instructions non-conflicting with likely user requests. Do not depend on CLAUDE.md always overriding user messages.

### Step 3: Apply Structural Patterns from Top Repos

Based on analysis of React (240k stars), Deno (103k stars), PyTorch (90k stars), uv (55k stars), Next.js (138k stars), Biome (17k stars), Crush (21k stars), LangChain (105k stars), and Anthropic's own repos.

#### CLAUDE.md Structure (target 80-150 lines)

```markdown
# Project Name (use proper capitalized display name, e.g. "Exo Teams" not "exo-teams")
One-line description.

## Critical Rules
3-5 ALWAYS/NEVER rules that matter most. Primacy effect = maximum attention here.

## Architecture
Stack decisions that affect daily coding. 5-10 bullets, NOT a directory tree.
Claude explores filesystems natively - do not waste lines on project structure.

## Stack Decisions (Locked)
Prevent the model from second-guessing locked choices.

## Commands
Build, test, lint, deploy. Only commands Claude cannot guess from the codebase.

## Implementation Pitfalls
What WILL break if you are not careful. Non-obvious gotchas.
(Pattern from Anthropic's claude-code-action repo.)

## Commit Style
Convention + any repo-specific rules. NEVER add co-author tags.

## Compact Instructions
Tell the compaction process what to preserve (e.g. "always keep: current task, file paths being edited, test results, architectural decisions made this session").

## Do NOT
3-5 hard prohibitions. Benefits from recency effect at bottom of file.
```

#### What to EXCLUDE from CLAUDE.md

These are explicitly called out by Anthropic's official documentation as anti-patterns:

- Project structure trees (Claude explores filesystems)
- Standard language conventions Claude already knows
- Detailed API documentation (link to docs instead)
- Information that changes frequently (entity types, enum values)
- Long explanations or tutorials
- File-by-file codebase descriptions
- Self-evident practices ("write clean code")
- Code conventions details (put in path-scoped rules instead)

#### .claude/ Directory Infrastructure

Before generating, **analyze the codebase** and determine which path-scoped rules are needed based on:
- What languages/frameworks exist in the repo
- What file patterns need specific conventions
- What testing patterns are used
- What database/query patterns exist

Only create rules for languages and patterns that actually exist in the codebase. Don't generate a `go.md` rule for a Python-only project.

```
.claude/
├── settings.json          # hooks, deny list, project metadata
├── rules/                 # path-scoped rules (auto-load by file pattern)
│   ├── python.md          # paths: ["**/*.py"] - only if Python in repo
│   ├── typescript.md      # paths: ["**/*.ts", "**/*.tsx"] - only if TS in repo
│   ├── go.md              # paths: ["**/*.go"] - only if Go in repo
│   ├── sql.md             # paths: ["**/queries/**/*.sql"] - only if SQL queries exist
│   └── testing.md         # paths: ["**/tests/**", "**/*_test.*"] - only if tests exist
└── skills/                # on-demand invokable skills
    └── code-conventions/
        └── SKILL.md       # full style guide with examples
```

Each rule file should contain the **specific conventions, linters, formatters, and patterns** for that language as used in THIS codebase. Read existing code to extract the actual patterns being followed, don't assume generic defaults.

**settings.json patterns to include:**

```json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "command": "auto-format.sh \"$CLAUDE_FILE_PATH\""
      }
    ]
  },
  "permissions": {
    "deny": ["wrong-package-manager", "git push --force", "git reset --hard"]
  }
}
```

The PostToolUse auto-format hook (from uv, React, Anthropic repos) eliminates "run the formatter" reminders entirely. The deny list prevents wrong tools. Detect the actual formatter from the repo (ruff for Python, gofmt for Go, prettier for TS/JS, biome, etc.) and wire it into the auto-format script.

**Path-scoped rules vs CLAUDE.md vs skills:**

| Put here | When |
|----------|------|
| CLAUDE.md | Rule applies to ALL work in the repo, every session |
| .claude/rules/ | Rule applies only when touching specific file types |
| .claude/skills/ | Detailed reference or workflow invoked on demand |

Rules are more token-efficient than CLAUDE.md because they only load when relevant. A python style rule does not burn context during Go work.

### Step 4: Generate the Files

1. Write CLAUDE.md following the structure above
2. Create settings.json with auto-format hook and deny list
3. Create path-scoped rules for each language/domain in the repo
4. Optionally create skills for complex workflows
5. Create the auto-format script if the repo has linters/formatters

### Step 5: Validate

- Count lines: CLAUDE.md should be under 200
- Count distinct instructions: should be 30-70
- Apply pruning test to every line
- Check for duplication across CLAUDE.md, rules, and skills
- Verify no project structure trees or enumerable data that will go stale
- Confirm critical rules are at the top, prohibitions at the bottom

Related Skills

skill-forge

6
from alxxpersonal/forge

Write or improve an LLM agent skill. Use when user says "create skill", "write a skill", "improve this skill", "new skill", "skill for X", or wants to build a SKILL.md file.

readme-forge

6
from alxxpersonal/forge

Generate a README in alxx's personal style. Use when user says "write a README", "create README", "readme for this project", "update README", or needs a repo README.

prompt-forge

6
from alxxpersonal/forge

Universal prompt engineering guide for writing, reviewing, and optimizing LLM prompts across Claude and OpenAI models. Use when writing system prompts, designing extraction pipelines, building classification or summarization prompts, optimizing for cost/latency, reviewing existing prompts for quality, or any task involving prompt design for production AI systems. Trigger on keywords like "prompt", "system prompt", "few-shot", "extraction prompt", "prompt engineering", "prompt review", or when the user is building any AI-powered feature that needs a well-crafted prompt.

model-forge

6
from alxxpersonal/forge

Pick the right model for a task and the right git strategy for the work. Use when about to dispatch a subagent, start a new feature, or unsure whether to use opus/sonnet/haiku/codex, or whether to branch/worktree/work direct. NOT for actually running the work - this only routes.

commit-forge

6
from alxxpersonal/forge

Write clean, atomic git commits with conventional format. Use when committing code, staging changes, or user says "commit", "commit this", "stage and commit", or is done with a task and needs to commit. NOT for git troubleshooting or branch management.

claude-headless

6
from alxxpersonal/forge

Build custom UIs on top of Claude Code's headless mode. Covers spawning, NDJSON protocol, permission hooks, and session management. Use when building a desktop app, TUI, web UI, or any custom interface that wraps Claude Code as a subprocess.

exo-teams

6
from alxxpersonal/forge

CLI tool for Microsoft Teams internal API - no admin consent required. Use when working with Teams messages, DMs, assignments, class materials, file uploads, calendar, or deadlines. Trigger on "teams", "exo-teams", "microsoft teams", "assignments", "class materials", "send message teams", "teams files", "uni automation", "deadlines", or "submit assignment".

charm-vhs

6
from alxxpersonal/forge

Record terminal sessions as GIF/MP4/WebM from declarative .tape scripts with VHS. Use when creating terminal demos, recording CLI sessions, VHS tape files, or generating terminal GIFs.

charm-ultraviolet

6
from alxxpersonal/forge

Low-level Go terminal primitives - cell-based rendering, input handling, screen management. Use when building custom Go terminal renderers, ultraviolet, cell buffers, or performance-critical TUI work below Bubble Tea's abstraction level.

charm-pop

6
from alxxpersonal/forge

Send emails from the terminal with pop - TUI and CLI modes, SMTP and Resend support, attachments. Use when sending email from terminal, pop, CLI email, or piping email content from shell scripts.

charm-lipgloss

6
from alxxpersonal/forge

CSS-like terminal styling for Go with lipgloss v2 - styles, colors, borders, layout, tables, lists, and trees. Use when styling Go terminal output, lipgloss, terminal layout composition, or building styled tables/lists/trees in Go.

charm-huh

6
from alxxpersonal/forge

Build interactive terminal forms and prompts in Go with huh - input, select, confirm, multiselect, validation, theming. Use when building Go terminal forms, huh, interactive Go prompts, or form fields with validation. NOT for shell script prompts (use gum).