elixir-cyclic-deps
Skill59 starsChanged 9 months agoMITView on GitHub
Detects and removes cyclic compile-time dependencies in Elixir codebases using mix xref, with minimal code changes. Use when the user explicitly asks to check for cycles, remove cyclic dependencies, or fix xref cycle failures. Requires Elixir 1.19 or higher for accurate results.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ci-preflightSkill
- citationsSkill
- codegen-syncSkill
- debuggingSkill
- docsSkill
- gitSkill
- lint-and-formatSkill
- live-testsSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Verify version: elixir -v or inside the project run mix run -e 'IO.inspect(System.version())'.
- Distinctive: line 17
If the version is below 1.19, stop and inform the user that upgrading to Elixir 1.19+ is required for reliable cycle detection.
- Distinctive: line 21
Run both commands from the project root.
- Very specific: line 44
Establish baseline: run both xref commands with --fail-above 3 (or current project setting).
- Very specific: line 45
Inspect cycles: run without --fail-above to see full cycle output.
- Distinctive: line 47
Prefer breaking a single dependency (e.g.
- Distinctive: line 49
Avoid duplication; follow existing repository guidelines (e.g.
- Very specific: line 66
If the project has a cyclecheck (or similar) task in mix.exs, use it after changes:
- Very specific: line 72
Ensure it runs both xref commands with the target --fail-above 0 once cycles are cleared.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Elixir Cyclic Dependencies
When to Use
Apply this skill only when the user explicitly asks to check or remove cyclic dependencies (e.g. "check for cycles", "remove cyclic dependencies", "fix xref cycles").
Prerequisite: Elixir Version
Cycle detection is correct only on Elixir 1.19 or higher. Before running any cycle checks:
- Verify version:
elixir -vor inside the project runmix run -e 'IO.inspect(System.version())'. - If the version is below 1.19, stop and inform the user that upgrading to Elixir 1.19+ is required for reliable cycle detection.
Detecting Cycles
Run both commands from the project root. Start with a relaxed threshold, then tighten:
mix xref graph --format cycles --label compile-connected --fail-above 3
mix xref graph --format cycles --label compile --fail-above 3- compile-connected: cycles in the compile-time dependency graph (modules that compile in a cycle).
- compile: same graph, different label; both should be run.
- --fail-above N: exit code fails when cycle count is above N. Use
3initially, goal is 0.
To list cycles without failing (for inspection), omit --fail-above or set it high:
mix xref graph --format cycles --label compile-connected
mix xref graph --format cycles --label compileGoal: reach --fail-above 0 for both commands (no cycles).
Workflow
- Check Elixir version (must be ≥ 1.19).
- Establish baseline: run both xref commands with
--fail-above 3(or current project setting). Note cycle count and which modules appear in cycles. - Inspect cycles: run without
--fail-aboveto see full cycle output; identify the smallest set of edges (module A → module B) that, if removed, break cycles. - Plan minimal changeset:
- Prefer breaking a single dependency (e.g. move shared code to a new module both can depend on) over large refactors.
- Helper modules are allowed if they yield the smallest change: extract shared logic into a new module that the cycle participants depend on, so the cycle is broken.
- Avoid duplication; follow existing repository guidelines (e.g. AGENTS.md, .cursor rules) and prior patterns in the codebase.
- Implement: make the chosen change, then re-run both xref commands with
--fail-above 0(or gradually lower from 3 → 0). - Verify:
mix compile --warnings-as-errors, tests, and any project lint (e.g.mix lintormix cyclecheckif defined).
Minimal-Change Strategies
| Strategy | When to use |
| Extract helper module | Two or more modules in a cycle need the same logic; extract it to a new module that has no dependency back on the cycle. |
| Move code down | Move a function from module A to module B so that A no longer depends on B (or vice versa), breaking the cycle. |
| Invert dependency | If A uses B and B uses A, see if one usage can be replaced by a callback, option, or data structure so only one direction remains. |
| Split module | One module has two distinct responsibilities and participates in two cycles; split into two modules to break cycles. |
Choose the option that removes cycles with the least code churn and no new duplication.
Project Integration
If the project has a cyclecheck (or similar) task in mix.exs, use it after changes:
mix cyclecheckEnsure it runs both xref commands with the target --fail-above 0 once cycles are cleared.
Summary Checklist
- Elixir version ≥ 1.19 confirmed
- Both
compile-connectedandcompilexref cycle commands run - Goal:
--fail-above 0for both - Minimal changeset (helper modules OK)
- No code duplication; follows repo guidelines
mix compile, tests, and lint pass after changes
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

