UsageRules is a config-driven dev tool for Elixir projects that manages your AGENTS.md file and agent skills from dependencies. It:
- Gathers and consolidates
usage-rules.mdfiles from your dependencies into an AGENTS.md (or any file) - Generates agent skills (SKILL.md files) from dependency usage rules
- Provides built-in usage rules for Elixir and OTP
- Includes a powerful documentation search task via
mix usage_rules.search_docs
If you have igniter installed:
mix igniter.install usage_rulesOr add usage_rules manually to your mix.exs:
def deps do
[
{:usage_rules, "~> 1.0", only: [:dev]},
{:igniter, "~> 0.6", only: [:dev]}
]
endAll configuration lives in your mix.exs project config. Add a :usage_rules key:
def project do
[
...
usage_rules: usage_rules()
]
end
defp usage_rules do
# Example for those using claude.
[
file: "CLAUDE.md",
# rules to include directly in CLAUDE.md
# use a regex to match multiple deps, or atoms/strings for specific ones
usage_rules: [:ash, ~r/^ash_/],
# If your CLAUDE.md is getting too big, link instead of inlining:
usage_rules: [:ash, {~r/^ash_/, link: :markdown}],
# or use skills
skills: [
location: ".claude/skills",
# build skills that combine multiple usage rules
build: [
"ash-framework": [
# The description tells people how to use this skill.
description: "Use this skill working with Ash Framework or any of its extensions. Always consult this when making any domain changes, features or fixes.",
# Include all Ash dependencies
usage_rules: [:ash, ~r/^ash_/]
],
"phoenix-framework": [
description: "Use this skill working with Phoenix Framework. Consult this when working with the web layer, controllers, views, liveviews etc.",
# Include all Phoenix dependencies
usage_rules: [:phoenix, ~r/^phoenix_/]
]
]
]
]
endThen run:
mix usage_rules.syncThat's it. The config is the source of truth — packages in the file but not in config are automatically removed on each sync.
defp usage_rules do
[
# The file to write usage rules into (required for usage_rules syncing)
file: "AGENTS.md",
# Which packages to include (required for usage_rules syncing)
# :all discovers every dependency with a usage-rules.md and inlines them
usage_rules: :all,
# Or list specific packages and sub-rules:
# usage_rules: [
# :ash, # inlined (default)
# ~r/^ash_/, # regex match (inlined)
# "phoenix:ecto", # specific sub-rule (inlined)
# {:req, link: :at}, # linked with @-style
# {:ecto, link: :markdown}, # linked with markdown-style
# {~r/^phoenix_/, link: :markdown}, # regex match (linked)
# :elixir, # built-in Elixir rules
# :otp, # built-in OTP rules
# ],
# Agent skills configuration
skills: [
location: ".claude/skills", # where to output skills (default)
# Auto-build a "use-<pkg>" skill per dependency
deps: [:ash, :req],
# Supports regex for matching multiple deps:
# deps: [~r/^ash_/],
# Compose custom skills from multiple packages
build: [
"ash-framework": [
description: "Expert on the Ash Framework ecosystem.",
usage_rules: [:ash, ~r/^ash_/]
]
]
]
]
end| Option | Type | Description |
|---|---|---|
file |
string |
Target file for usage rules (e.g. "AGENTS.md", "CLAUDE.md") |
usage_rules |
:all | list |
Which packages to sync. :all auto-discovers, or list specific packages |
skills |
keyword |
Agent skills configuration (see below) |
Each entry in the usage_rules list can be:
| Format | Description |
|---|---|
:package |
Inline the package's usage rules (default) |
"package:sub_rule" |
Inline a specific sub-rule |
"package:all" |
Inline all sub-rules from a package |
~r/pattern/ |
Inline all matching dependencies' usage rules |
{:package, link: :at} |
Link with @deps/package/usage-rules.md style |
{:package, link: :markdown} |
Link with [name](deps/package/usage-rules.md) style |
{~r/pattern/, link: :markdown} |
Link all matching dependencies with markdown-style |
{"package:sub_rule", link: :at} |
Link a specific sub-rule with @-style |
| Option | Type | Description |
|---|---|---|
location |
string |
Output directory for skills (default: ".claude/skills") |
deps |
list |
Auto-build a use-<pkg> skill per listed dependency. Supports atoms and regexes |
build |
keyword |
Define custom composed skills from multiple packages' usage rules |
The simplest setup — discover all deps with usage-rules.md and inline them:
defp usage_rules do
[
file: "AGENTS.md",
usage_rules: :all
]
endPick exactly which packages to include:
defp usage_rules do
[
file: "AGENTS.md",
usage_rules: [:ash, :phoenix, :ecto]
]
endPackages can provide sub-rules in a usage-rules/ directory. Reference them with "package:sub_rule" syntax:
usage_rules: [:phoenix, "phoenix:ecto", "phoenix:html"]Use "package:all" to include all sub-rules from a package:
usage_rules: [:phoenix, "phoenix:all"]UsageRules ships with built-in rules for Elixir and OTP:
usage_rules: [:elixir, :otp, :ash, :phoenix]Use a regex to match multiple dependencies at once:
defp usage_rules do
[
file: "AGENTS.md",
usage_rules: [:ash, ~r/^ash_/]
# If your AGENTS.md is getting too big, link instead of inlining:
# usage_rules: [:ash, {~r/^ash_/, link: :markdown}]
]
endThis matches all dependencies whose name matches the regex and inlines their usage-rules.md. Dependencies without a usage-rules.md are silently skipped.
By default, usage rules are inlined directly into the target file. You can link to specific packages instead using the link option:
defp usage_rules do
[
file: "AGENTS.md",
usage_rules: [
:ash, # inlined
{:phoenix, link: :at}, # @deps/phoenix/usage-rules.md
{:ecto, link: :markdown}, # [ecto usage rules](deps/ecto/usage-rules.md)
{"phoenix:html", link: :at} # @deps/phoenix/usage-rules/html.md
]
]
endSkills are SKILL.md files that agent tools like Claude Code can discover and use. UsageRules can automatically generate skills from your dependencies' usage rules.
Generated skills use markers to delimit managed content. You can add custom content above the markers in any SKILL.md — it will be preserved across syncs.
The deps option auto-builds a use-<package> skill for each listed dependency:
defp usage_rules do
[
file: "AGENTS.md",
usage_rules: :all,
skills: [
deps: [:ash, :req]
]
]
endThis generates .claude/skills/use-ash/SKILL.md and .claude/skills/use-req/SKILL.md, each with reference links to the package's usage rules, available mix tasks, doc search commands, and sub-rule references. Each package's usage-rules.md is written to a references/<package>.md file.
The build option lets you compose a single skill from multiple packages:
skills: [
build: [
"ash-framework": [
description: "Expert on the Ash Framework ecosystem.",
usage_rules: [:ash, :ash_postgres, :ash_phoenix, :ash_json_api]
]
]
]This generates a single .claude/skills/ash-framework/SKILL.md with reference links to usage rules from all listed packages. Each package's rules are written to references/<package>.md. Regex is also supported:
skills: [
build: [
"ash-framework": [
description: "Expert on Ash.",
usage_rules: [:ash, ~r/^ash_/]
]
]
]Skills generated by UsageRules include a managed-by: usage-rules marker in their YAML frontmatter. When a skill is removed from your config and you re-run mix usage_rules.sync, the stale skill files are automatically cleaned up. If you've added custom content to a managed skill, only the managed section is removed — your custom content is preserved.
You can use skills without syncing usage rules into a file — just omit the file and usage_rules keys:
defp usage_rules do
[
skills: [
deps: [:ash, :phoenix]
]
]
endmix usage_rules.search_docs searches hexdocs with human-readable markdown output, designed for both humans and AI agents.
# Search all project dependencies
mix usage_rules.search_docs "search term"
# Search specific packages
mix usage_rules.search_docs "search term" -p ecto -p ash
# Search specific versions
mix usage_rules.search_docs "search term" -p ecto@3.13.2
# Search all packages on hex
mix usage_rules.search_docs "search term" --everywhere
# JSON output
mix usage_rules.search_docs "search term" --output json
# Search only in titles
mix usage_rules.search_docs "search term" --query-by title
# Pagination
mix usage_rules.search_docs "search term" --page 2 --per-page 20Even if you don't use LLMs yourself, your users likely do. Writing a usage-rules.md file helps prevent hallucination-driven support requests.
We don't really know what makes great usage-rules.md files yet. Ash Framework is experimenting with quite fleshed out usage rules which seems to be working quite well. See Ash Framework's usage-rules.md for one such large example. Perhaps for your package only a few lines are necessary.
One quick tip is to have an agent begin the work of writing rules for you, by pointing it at your docs and asking it to write a usage-rules.md file in a condensed format that would be useful for agents to work with your tool. Then, aggressively prune and edit it to your taste.
Make sure that your usage-rules.md file is included in your hex package's files option, so that it is distributed with your package.
A package can provide a main usage-rules.md and/or sub-rule files:
usage-rules.md # general rules
usage-rules/
html.md # html specific rules
database.md # database specific rules
v0.2 replaces CLI arguments with project config. If you were running:
mix usage_rules.sync AGENTS.md --all --link-to-folder depsReplace it with config in mix.exs:
def project do
[
usage_rules: [
file: "AGENTS.md",
usage_rules: :all
]
]
endThen just run mix usage_rules.sync with no arguments.
v1.0 removes link_to_folder, link_style, and inline options. Content is inlined by default. Use per-dep link option for linking:
# Before (v0.2)
usage_rules: :all,
link_to_folder: "deps",
link_style: "at",
inline: ["usage_rules:all"]
# After (v1.0)
usage_rules: [
{:ash, link: :at},
{:phoenix, link: :at},
"usage_rules:all" # inlined by default
]