Give your coding agent the GuardedStruct rules
v0.1.4
The GuardedStruct package ships a rules file and seven skills for coding agents such as Claude Code, Cursor and Copilot. With them in your project, an agent knows the DSL, the derive syntax and the shape of the errors. This guide shows how to sync the rules into your agent file, pull in the skills, or copy the skills by hand.
Before you begin
GuardedStruct must be a dependency of your project, so that its files are in deps/guarded_struct. For the sync, you also need the usage_rules package.
See what the package contains
The Hex package includes these files.
usage-rules.mdis the entry point. It summarizes the universal contracts and links the sub-rules.usage-rules/holds nine sub-rules:dsl,derive,conditional,validators,core-keys,extensions,ash,apianderrors..claude/skills/holds seven skills, one folder each with aSKILL.md:guarded-struct,guarded-struct-dsl,guarded-struct-derive,guarded-struct-conditional,guarded-struct-ash,guarded-struct-extensionsandguarded-struct-api.
Sync the rules into your agent file
Add usage_rules as a dev dependency and describe what to sync in the usage_rules key of your project config.
# mix.exs
def project do
[
# ...
usage_rules: [
file: "AGENTS.md",
usage_rules: [:guarded_struct],
skills: [
location: ".claude/skills",
package_skills: [:guarded_struct]
]
]
]
end
defp deps do
[
{:guarded_struct, "~> 0.1.4"},
{:usage_rules, "~> 1.1", only: [:dev]}
]
endRun the sync. It writes the rules into the file named by file, and it writes the skills that package_skills lists into location.
mix deps.get
mix usage_rules.syncRun mix usage_rules.sync again after you update the dependency, because the files come from the version you have installed.
Take only some of the rules
Name a sub-rule as "guarded_struct:name" in the usage_rules list to include that part and nothing else.
usage_rules: [
"guarded_struct:dsl",
"guarded_struct:derive",
"guarded_struct:errors"
]Copy the skills by hand
Without usage_rules, copy the skill folders into the directory your agent reads. Each skill is a plain folder with one SKILL.md file.
mkdir -p .claude/skills
cp -R deps/guarded_struct/.claude/skills/* .claude/skills/Next steps
- Get started: the tutorial for a new project.
- DSL reference: the current list of options.
- Configuration: the other settings of GuardedStruct.