law-of-demeter

law-of-demeter is a skill for Claude Code, Codex from j5ik2o/okite-ai. It costs 223 tokens per session (2,507 once invoked), scanned A, original, MIT.

A code-design guide based on the Law of Demeter, which says that code should mainly talk to its immediate collaborators rather than objects several steps away.

In plain words
What is it for?
Use it in code reviews, refactoring, or design work to find chained calls and replace them with simpler delegation.
Why use it?
It helps reduce fragile chains such as getting an object, then its child, then another child, which can break when internal structures change.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it in code reviews, refactoring, or design work to find chained calls and replace them with simpler delegation.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/j5ik2o/okite-ai/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 j5ik2o/okite-ai --skill law-of-demeter
Clone the repo
git clone --depth 1 https://github.com/j5ik2o/okite-ai

Made for: Claude Code, Codex.

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/j5ik2o/okite-ai/law-of-demeter/github.svg)](https://agentmods.dev/skills/j5ik2o/okite-ai/law-of-demeter)
Your own site
<a href="https://agentmods.dev/skills/j5ik2o/okite-ai/law-of-demeter"><img src="https://agentmods.dev/badge/skills/j5ik2o/okite-ai/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/j5ik2o/okite-ai/law-of-demeter"><img src="https://agentmods.dev/badge/skills/j5ik2o/okite-ai/law-of-demeter.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 223 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,507 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.00223 $0.02507
Opus 5 $0.00112 $0.01254
Sonnet 5 $0.00045 $0.00501
Haiku 4.5 $0.00022 $0.00251

Measured 9d ago against content hash ddd905e98459, 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 9d 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

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

How it starts

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

Law of Demeter

直接の友人とだけ話せ。見知らぬ者に話しかけるな。

核心原則

メソッドは「直接の友人」のメソッドだけを呼び出し、「友人の友人」には手を出さない。

Karl Liebherr(1987年、ノースイースタン大学)が提唱。正式名称は「最小知識の原則(Principle of Least Knowledge)」。

アプローチ 特徴 問題
連鎖呼び出し a.getB().getC().doX() 内部構造に依存、変更に脆い
委譲 a.doX() 結合度が低い、変更に強い

4つのルール

メソッド M が呼び出してよいのは、以下の4種類のメソッドのみ:

# 許可される呼び出し先 説明
1 自身(this / self)のメソッド 自分のクラスに定義されたメソッド
2 M の引数として渡されたオブジェクトのメソッド パラメータ経由の直接の友人
3 M 内で生成したオブジェクトのメソッド 自分が作ったオブジェクトは友人
4 自身のインスタンス変数(フィールド)のメソッド 保持しているオブジェクトは友人

禁止: 上記メソッド呼び出しの戻り値のメソッドを呼び出すこと(=友人の友人)

判断フロー

メソッド内で obj.method() を呼んでいる
    ↓
obj はどこから来たか?
    ├─ this/self のフィールド → ✅ 許可(ルール4)
    ├─ メソッドの引数 → ✅ 許可(ルール2)
    ├─ メソッド内で new/生成した → ✅ 許可(ルール3)
    ├─ this/self 自身 → ✅ 許可(ルール1)
    └─ 別のメソッド呼び出しの戻り値 → ❌ 違反(友人の友人)

アンチパターン検出

Train Wreck(列車事故)

連鎖的なドット呼び出しでオブジェクトの内部構造をたどるパターン:

❌ order.getCustomer().getAddress().getCity()
❌ user.getProfile().getSettings().getTheme().getName()
❌ app.getConfig().getDatabase().getConnection().execute(query)
❌ invoice.getLineItems().get(0).getProduct().getCategory()

検出基準

パターン 問題
ドットが2つ以上の連鎖 構造依存(ただし流暢APIは例外)
getter連鎖 + 末尾の操作 取得したオブジェクトの操作 = 友人の友人
getter連鎖 + if文 遠いオブジェクトの状態で分岐

変換パターン

1. 委譲メソッドの導入

// ❌ 違反: 友人(order)の友人(customer)の友人(address)に話しかけている
City city = order.getCustomer().getAddress().getCity();

// ✅ 修正: 各レベルに委譲メソッドを追加
City city = order.getShippingCity();

// Order
public City getShippingCity() {
    return customer.getShippingCity();
}

// Customer
public City getShippingCity() {
    return address.getCity();
}

2. 目的に応じたメソッド名

// ❌ 違反: 内部構造を露出した名前
Email email = order.getCustomer().getEmail();

// ✅ 修正: 目的を表すメソッドを提供
Email email = order.getNotificationEmail();

3. パラメータとして渡す

// ❌ 違反: 遠いオブジェクトを取得して使用
void processOrder(Order order) {
    PaymentGateway gateway = order.getCustomer().getPaymentGateway();
    gateway.charge(order.getTotal());
}

// ✅ 修正: 必要なオブジェクトを引数で受け取る
void processOrder(Order order, PaymentGateway gateway) {
    gateway.charge(order.getTotal());
}

Read the full file on GitHub · 238 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 9d ago First seen · 238 lines · 223 tokens per session scan A ddd905e98459

Subscribe to this mod's changes

law-of-demeter is a skill published in the GitHub repository j5ik2o/okite-ai (81 stars, last pushed 4mo ago), licensed MIT. It adds 223 tokens to every session and 2,507 once invoked, about $0.0011 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-09-03.