law-of-demeter

law-of-demeter is a skill for Claude Code from JordanCoin/codingskills. It costs 59 tokens per session (1,152 once invoked), scanned A, original, MIT.

A code-review guide based on the Law of Demeter, which says that a component should work mainly with its immediate collaborators rather than reaching through several layers of objects. It focuses on deep chains such as `order.customer.address.city`.

In plain words
What is it for?
Use it to review or redesign code with long chained calls, excessive coupling, fragile object relationships, or tests that require many mocks.
Why use it?
It helps find code that is tightly connected to internal object details. Reducing these connections can make changes safer and testing less difficult.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the coding-skills plugin — 9 skills shipped together

Good fit Use it to review or redesign code with long chained calls, excessive coupling, fragile object relationships, or tests that require many mocks.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jordancoin/codingskills/law-of-demeter
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add JordanCoin/codingskills --skill law-of-demeter
Clone the repo
git clone --depth 1 https://github.com/JordanCoin/codingskills

Made for: Claude Code.

Or install coding-skills, the plugin that ships this one along with the rest of its 9 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for law-of-demeter

README.md
[![agentmods](https://agentmods.dev/badge/skills/jordancoin/codingskills/law-of-demeter/github.svg)](https://agentmods.dev/skills/jordancoin/codingskills/law-of-demeter)
Your own site
<a href="https://agentmods.dev/skills/jordancoin/codingskills/law-of-demeter"><img src="https://agentmods.dev/badge/skills/jordancoin/codingskills/law-of-demeter/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for law-of-demeter

Your own site · 80×15
<a href="https://agentmods.dev/skills/jordancoin/codingskills/law-of-demeter"><img src="https://agentmods.dev/badge/skills/jordancoin/codingskills/law-of-demeter.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 59 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,152 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00059 $0.01152
Opus 5 $0.00030 $0.00576
Sonnet 5 $0.00012 $0.00230
Haiku 4.5 $0.00006 $0.00115

Measured 12d ago against content hash eb19648bca6b, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

law-of-demeter scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/law-of-demeter/SKILL.md · 88 lines

How it starts

The opening of the file, as written. The whole thing — 88 lines — stays where its author put it; the contents beside it link to each section on GitHub.

LoD — Law of Demeter (Principle of Least Knowledge)

Before Applying

If .agents/stack-context.md exists, read it first. Apply this principle using idiomatic patterns for the detected stack. For framework-specific details, use context7 MCP or web search — don't guess.

Principle

A component should only talk to its immediate collaborators. Don't reach through an object to access its internals, its children's internals, or anything deeper.

More precisely: a method should only call methods on (1) itself, (2) its own fields, (3) its parameters, (4) objects it creates, and (5) global/singleton services.

Why This Matters in Production

Every chain of access (order.customer.address.city) is a chain of coupling. If any link in that chain changes — the customer model gets restructured, address becomes optional, city moves to a sub-object — every caller breaks.

LoD violations create fragile systems where a seemingly small refactor triggers cascading failures across unrelated code. They also make testing painful: to test a function that reaches through 4 layers, you must mock all 4 layers.

In production, LoD violations are a leading cause of NullPointerException and undefined is not an object errors. Each . in a chain is a potential null/undefined dereference point.

Rules

  1. Don't chain through objects. If you need data from deep inside a structure, ask the immediate owner to provide it. order.shipping_city() not order.customer.address.city.
  2. Tell, don't ask. Instead of reaching into an object to get data and make a decision, tell the object what you need done. Let it use its own internals.
  3. Wrap external APIs at the boundary. Third-party SDKs and API responses often expose deep structures. Create a thin wrapper that exposes only what your code needs, in the shape your code needs.
  4. Flatten data for consumers. When passing data across boundaries (to templates, to frontends, to other services), flatten the nested structure into a purpose-built shape rather than exposing your internal model.
  5. Limit parameter knowledge. A function that receives an object should only use the fields it directly needs. If it only needs the user's email, accept the email — not the entire user object.

Read the full file on GitHub · 88 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 88 lines · 59 tokens per session scan A eb19648bca6b

Subscribe to this mod's changes

law-of-demeter is a skill published in the GitHub repository JordanCoin/codingskills (7 stars, last pushed 6mo ago), licensed MIT. It adds 59 tokens to every session and 1,152 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

karpathy-coding-principles

Use when andrej Karpathy's 4 coding principles — think before coding, simplicity first, surgical changes, goal-driven execution. Use when coding, reviewing code quality, reducing overengineering,.

oyi77/1ai-skills · 46 tokens

refactor

Automated iterative code refactoring with swarm-orchestrated specialist agents including deep codebase discovery, confidence-scored code review, and security analysis. Use this skill when the user wants to improve existing code quality, clean up messy code, restructure, simplify, reduce tech debt, or perform…

zircote-plugins/refactor · 112 tokens

uncle-bob-craft

Use when performing code review, writing or refactoring code, or discussing architecture; complements clean-code and does not replace project linter/formatter.

ratnesh-maurya/cursor-claude-personas · 36 tokens

delphi-clean-code-solid

Diretrizes de SOLID, Clean Code e padrões de nomenclatura para classes, interfaces, métodos e variáveis em projetos Delphi.

regyssilveira/AgentKit4D · 33 tokens

recipe-front-review

Reviews completed frontend implementation for governing-source compliance, scope economy, repository quality, and security, then applies user-approved React corrections.

shinpr/claude-code-workflows · 29 tokens

new-skill

Scaffold a new brooks-lint analysis skill so it passes npm run validate and npm run evals on the first try — generates skills/{name}/SKILL.md (with the mandatory "Do NOT trigger for:" clause and a Process section citing guide step ranges) plus skills/{name}/{name}-guide.md (sequentially numbered steps), then appends…

hyhmrright/brooks-lint · 145 tokens