Captures a team convention or best practice and adds it to the appropriate .claude/rules/ or .claude/agents/ file
59
67%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./.claude/skills/add-rule/SKILL.mdFormalize a convention, best practice, or correction into the project's .claude/rules/ or .claude/agents/ files so it applies automatically for all team members.
The user provides a convention in natural language. Examples:
/add-rule "prefer require.NoError over t.Fatal for error assertions"/add-rule "use context.Background() in tests, not context.TODO()"/add-rule "CLI commands must support --format json"If no argument is provided, ask: "What convention would you like to add?"
Parse the user's input to identify:
Rules vs Agents — key principle: Rules define conventions; agents reference rules. Never duplicate rule content in agent files.
.claude/rules/): Auto-loaded based on paths: frontmatter globs when Claude touches matching files. These define the canonical conventions (style, testing patterns, error handling, etc.)..claude/agents/): Define agent-specific behavior — persona, review checklist, output format, workflow steps. Agents inherit the full conversation context (including CLAUDE.md), so they already have access to all loaded rules. Agent files should reference rules (e.g., "Follows conventions in .claude/rules/testing.md"), never restate them.Match the convention to an existing file based on scope:
| Scope | Target file | What goes here |
|---|---|---|
| General Go code | .claude/rules/go-style.md | Style, naming, error handling conventions |
| Test files | .claude/rules/testing.md | Testing patterns, framework usage |
| CLI commands | .claude/rules/cli-commands.md | CLI architecture, flag conventions |
| Kubernetes operator | .claude/rules/operator.md | CRD, controller conventions |
| PR creation | .claude/rules/pr-creation.md | PR format, review expectations |
| Agent workflow/persona | .claude/agents/<agent-name>.md | Agent-specific behavior, checklists, output format |
If no existing file fits, propose creating a new rule file with appropriate paths: frontmatter. New rule files need a glob pattern that determines when they auto-load.
If the convention is about code (how to write Go, test patterns, error handling), it belongs in a rules file — even if it's most relevant to a specific agent. The agent can reference the rule.
Read the target file and draft the new content:
Format examples:
Simple rule:
- Use `context.Background()` in tests, not `context.TODO()` — tests have no caller to propagate cancellation fromRule with example:
## Prefer Table-Driven Tests
Use table-driven tests over repeated test functions:
` ``go
// Good
tests := []struct{ name string; input int; want int }{...}
// Avoid: separate TestFoo1, TestFoo2, TestFoo3 functions
` ``Show the user:
.claude/rules/testing.md? (y/n)"Use the Edit tool to add the rule to the target file. After applying:
~/.claude/ memory instead."cd373ec
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.