Index of every page on this site: llms.txt
All skills
stacklok avatar

/add-rule

@740e467
by stacklokstacklok/toolhive2.4k stars
336
Run it yourself

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

Use this Skill: https://skilld.dev/gh/stacklok/toolhive/add-rule

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈31 tokens for metadata: the name and description. ≈1.2k when used: this file.

Description uses 1.6% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈124 characters, or 1.6%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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:

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

Rule 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
` ``

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

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7mo3 checks · Risk SAFE
  • Gen Agent Trust Hub7mo

    The skill is a utility for managing project-specific rules and conventions. It follows security best practices by implementing a human-in-the-loop confirmation process before modifying files and restricts its operations to specific configuration directories.

  • Socket7mo

    No alerts

  • Snyk7mo

    Risk: LOW · No issues

Signed by skilld at 740e467. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 8 months ago

README badge

README badge for stacklok/toolhive/add-rule