Authoring claude md

From sammcj/agentic-coding · View interactive version

Authoring claude md is an AI agent skill from the GitHub repository sammcj/agentic-coding. Use when creating, editing, auditing or pruning CLAUDE.md, AGENTS.md or .claude/rules/ files.

How to use this skill

Skill file

CLAUDE.md, AGENTS.md and Rules Authoring

Create effective CLAUDE.md, AGENTS.md and .claude/rules/ files that serve as project-specific memory for AI coding agents. Guidance for CLAUDE.md also applies to AGENTS.md and rule files unless stated otherwise: signal over noise, actionable context, no obvious information.

Purpose

CLAUDE.md files and rule files provide AI agents with:

Not for: obvious patterns, duplicating documentation, or generic coding advice.

Core Principles

Structure

Use headings for clear organisation. Common sections: Commands, Conventions, Gotchas. Use 2-4 sections and only include what adds value.

Where Each Instruction Belongs

@path imports organise content but load with the importing file, so they save no context.

AGENTS.md

By default Claude Code reads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above. ~/.claude/CLAUDE.md doesn't count. Adding one stops every AGENTS.md loading for sessions started in that directory or below, parent directories included, except those imported. A nested one also replaces its sibling AGENTS.md when the session starts above it. Some versions and sessions can't read AGENTS.md directly and need the import too.

Rule Files

Each .md file under .claude/rules/ covers one topic and is discovered recursively. Move part-specific content to path-scoped rules when CLAUDE.md approaches 200 lines, or when conventions differ by file type or area (one whole directory: see Where Each Instruction Belongs).

Scope a rule with paths frontmatter, the only field Claude Code reads:

---
paths:
  - "src/api/**/*.ts"
---

- Validate request bodies with the schemas in `src/api/schemas/`

What to Include

Verification commands: exact test, single-test, lint, typecheck and build commands. The command that checks the work is often the most useful line in the file.

Misleading code:

Architectural decisions: the reason for a choice the code can't show, such as why services communicate by events

Non-obvious conventions:

Recurring issues:

Project patterns: Error handling, logging, API versioning, migrations

What to Exclude

Conflict Audit

Before adding a line, check it against what else is already loaded: the user-level ~/.claude/CLAUDE.md, sibling rule files, and any skill covering the same ground. Instructions that clash ("leave documentation as appropriate" next to "never add comments") make the agent resolve the contradiction before it can start work, and it won't resolve it the same way every session.

Keep each topic in one place:

Path-scoped rules refine the root CLAUDE.md for the files they match; they shouldn't reverse it.

Linking to Existing Documentation

Point to existing docs rather than duplicating content. Provide context about when to read them:

Writing Style

Be specific:

Be concise:

State rules plainly, with scope, reason and any exception together. Current models take "never" literally and over-apply ALL CAPS or IMPORTANT. If a plain line is still missed, shorten the file or use a hook.

Keep the strength of an existing ban. Turn it into "ask before" only if the user wants the agent to have that option.

Name approvals exactly, including the routine steps that need none:

Code ownership: add "You are the owner and long-term maintainer of this codebase, and its design is up to you." only when the user wants the agent to restructure as it works. It also brings unrequested changes, and a scope rule doesn't cancel it.

When to Update

Add an entry when the user asks, or when:

Prune an entry when its reason has gone, a path or command it names no longer exists, a linter or hook now enforces it, or the code now shows it. Check with the user before removing or loosening a safety rule.

Don't add anything covered under What to Exclude (one-off fixes, temporary workarounds, info already in docs, verbose explanations).

Spelling Conventions

Always use Australian English spelling

Example Structure

# Commands
- Test: `pnpm test`, one file: `pnpm vitest run path/to/file.test.ts`
- Lint and typecheck: `pnpm lint && pnpm tsc --noEmit`

# Conventions
- Errors: use the helpers in src/lib/errors.ts rather than raw strings
- Feature flags: check in middleware, not in business logic
- Dates: UTC in the database, format client-side via src/utils/dates.ts
- Auth: see src/auth/README.md when changing token flows

# Gotchas
- src/legacy/ is live but don't copy its patterns into new code
- Cache: acquire the lock before checking status, as concurrent workers race

Token Budget

Aim for under 200 lines and 1k-4k tokens per CLAUDE.md. A single CLAUDE.md is fine for most projects. If exceeding:

  1. Reword to be more concise
  2. Remove generic advice
  3. Ensure there's no duplicated content
  4. Move content that only some files or tasks need (see Where Each Instruction Belongs)

Estimate token count with wc -c CLAUDE.md, then divide the character count by roughly 4.

Verification

Review Checklist

Before finalising:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.