add-rule

Captures a team convention or best practice and adds it to the appropriate .claude/rules/ or .claude/agents/ file

1,689 stars

Best use case

add-rule is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Captures a team convention or best practice and adds it to the appropriate .claude/rules/ or .claude/agents/ file

Teams using add-rule 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/add-rule/SKILL.md --create-dirs "https://raw.githubusercontent.com/stacklok/toolhive/main/.claude/skills/add-rule/SKILL.md"

Manual Installation

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

How add-rule Compares

Feature / Agentadd-ruleStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Captures a team convention or best practice and adds it to the appropriate .claude/rules/ or .claude/agents/ file

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.

Related Guides

SKILL.md Source

# Add Rule — Capture a Team Convention

## Purpose

Formalize a convention, best practice, or correction into the project's `.claude/rules/` or `.claude/agents/` files so it applies automatically for all team members.

## Input

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?"

## Instructions

### 1. Understand the Convention

Parse the user's input to identify:
- **The rule**: What should or should not be done
- **The scope**: Which files or areas it applies to (Go code, tests, CLI, operator, etc.)
- **The reason**: Why this convention exists (ask if not provided — the "why" is critical for future developers to judge edge cases)

### 2. Find the Right Target File

**Rules vs Agents — key principle**: Rules define conventions; agents reference rules. Never duplicate rule content in agent files.

- **Rules 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.).
- **Agent files** (`.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.

### 3. Draft the Addition

Read the target file and draft the new content:
- Match the style and formatting of existing rules in the file
- Place the rule in the most logical section (or propose a new section if needed)
- Keep it concise — one to three lines is ideal
- Include a brief rationale if the "why" isn't obvious from the rule itself
- Use code examples for conventions that benefit from showing good vs bad patterns

**Format examples:**

Simple rule:
```markdown
- Use `context.Background()` in tests, not `context.TODO()` — tests have no caller to propagate cancellation from
```

Rule with example:
```markdown
## 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
` ``
```

### 4. Present the Change

Show the user:
1. **Target file** and the section where the rule will be added
2. **The exact edit** — the lines being added in context
3. **A one-line confirmation prompt**: "Add this rule to `.claude/rules/testing.md`? (y/n)"

### 5. Apply on Confirmation

Use the Edit tool to add the rule to the target file. After applying:
- Verify the file is still well-structured
- If the rule was added to a rules file, mention that agents already pick it up automatically — rules are auto-loaded when matching files are touched, and agents inherit the full context. No agent file edits are needed unless the agent needs to explicitly reference the rule in a checklist.

## Edge Cases

- **Duplicate rule**: If a similar rule already exists, show it to the user and ask whether to update the existing rule or skip
- **Contradicts existing rule**: If the new convention contradicts an existing one, highlight the conflict and ask the user to resolve it
- **Too broad for one file**: If the convention spans multiple scopes, suggest adding it to CLAUDE.md instead or splitting into multiple rule additions
- **Personal preference vs team convention**: If the rule sounds personal (e.g., "I prefer tabs"), ask: "Is this a team-wide convention or a personal preference? Personal preferences go in your `~/.claude/` memory instead."

Related Skills

split-pr

1689
from stacklok/toolhive

Analyzes current changes and suggests how to split them into smaller, reviewable PRs

Workflow & Productivity

toolhive-cli-user

1689
from stacklok/toolhive

Guide for using ToolHive CLI (thv) to run and manage MCP servers and skills. Use when running, listing, stopping, building, or configuring MCP servers locally. Covers server lifecycle, registry browsing, secrets management, client registration, groups, container builds, exports, permissions, network isolation, authentication, and skill management (install, uninstall, list, info, build, push, validate). NOT for Kubernetes operator usage or ToolHive development/contributing.

doc-review

1689
from stacklok/toolhive

Reviews documentation for factual accuracy

pr-review

1689
from stacklok/toolhive

Submit inline review comments to GitHub PRs and reply to/resolve review threads using the GitHub CLI and GraphQL API.

toolhive-release

1689
from stacklok/toolhive

Creates ToolHive release PRs by analyzing commits since the last release, categorizing changes, recommending semantic version bump type (major/minor/patch), and triggering the release workflow. Use when cutting a release, preparing a new version, checking what changed since last release, or when the user mentions "release", "version bump", or "cut a release".

check-contribution

1689
from stacklok/toolhive

Validates operator chart contribution practices (helm template, ct lint, docs generation, version bump) before committing changes.

code-review-assist

1689
from stacklok/toolhive

Augments human code review by summarizing changes, surfacing key review questions, assessing test coverage, and identifying low-risk sections. Use when reviewing a diff, PR, or code snippet as a senior review partner.

deploy-otel

1689
from stacklok/toolhive

Deploy the OpenTelemetry observability stack (Prometheus, Grafana, OTEL Collector) to a Kind cluster for testing toolhive telemetry. Use when you need to set up monitoring, metrics collection, or observability infrastructure.

vmcp-review

1689
from stacklok/toolhive

Reviews vMCP code changes for known anti-patterns that make the codebase harder to understand or more brittle. Use when reviewing PRs, planning features, or refactoring vMCP code.

deploying-vmcp-locally

1689
from stacklok/toolhive

Deploys a VirtualMCPServer configuration locally for manual testing and verification

rules-distill

144923
from affaan-m/everything-claude-code

扫描技能以提取跨领域原则并将其提炼为规则——追加、修订或创建新的规则文件

Agent Management & PersonalizationClaude

hookify-rules

144923
from affaan-m/everything-claude-code

This skill should be used when the user asks to create a hookify rule, write a hook rule, configure hookify, add a hookify rule, or needs guidance on hookify rule syntax and patterns.