Agent skill

Diamond Pattern

by ccashwell in ccashwell/evm-cortex

A skill your agent uses when building large modular contracts with EIP-2535 Diamond pattern.

MITAuto-check passed

Install Diamond Pattern

skills CLI
$ npx skills add ccashwell/evm-cortex --skill diamond-pattern -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ccashwell/evm-cortex diamond-pattern --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ccashwell/evm-cortex.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/diamond-pattern .claude/skills/diamond-pattern && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
diamond-pattern
GitHub stars
131
Token cost
~1.9k tokens
SKILL.md length
216 words
Files
1
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when building large modular contracts with EIP-2535 Diamond pattern.

  • Building large modular contracts with EIP-2535 Diamond pattern
  • SKILL.md covers Overview, Architecture, Diamond Contract and DiamondCut Interface, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Diamond Pattern is an agent skill from ccashwell/evm-cortex. Use when building large modular contracts with EIP-2535 Diamond pattern. Covers facets, diamondCut, diamond loupe, AppStorage and DiamondStorage patterns, selector mapping, and facet upgrade process.

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The repository describes itself as: Ethereum protocol engineering squad for AI coding assistants. The licence is MIT.

When your agent uses it

  • Building large modular contracts with EIP-2535 Diamond pattern

Example prompts

  • “/diamond-pattern”

What it can do on your machine

Read from SKILL.md and the folder at commit f8f3301. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are solidity).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Diamond Pattern loads about 1.9k tokens when it runs. Until then it costs about 54 tokens; SKILL.md has 216 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~54
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ccashwell/evm-cortex at commit f8f3301, republished under its MIT licence (© ccashwell). 216 words, ~1,877 tokens.

Download SKILL.mdSave it as .claude/skills/diamond-pattern/SKILL.md (or your agent's skills folder).
name
diamond-pattern
description
Use when building large modular contracts with EIP-2535 Diamond pattern. Covers facets, diamondCut, diamond loupe, AppStorage and DiamondStorage patterns, selector mapping, and facet upgrade process.

EIP-2535 Diamond Pattern

Overview

The Diamond pattern splits a contract into multiple "facets" (logic modules) that share a single storage and address. Bypasses the 24KB contract size limit and enables surgical upgrades of individual functions.

Architecture

User → Diamond Proxy
         ├── FacetA (functions a1, a2)
         ├── FacetB (functions b1, b2, b3)
         ├── DiamondCutFacet (add/replace/remove functions)
         └── DiamondLoupeFacet (introspection)

All facets share the Diamond's storage context via delegatecall.

Diamond Contract

solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {LibDiamond} from "./libraries/LibDiamond.sol";

contract Diamond {
    constructor(address contractOwner, address diamondCutFacet) payable {
        LibDiamond.setContractOwner(contractOwner);
        LibDiamond.FacetCut[] memory cut = new LibDiamond.FacetCut[](1);
        bytes4[] memory selectors = new bytes4[](1);
        selectors[0] = IDiamondCut.diamondCut.selector;
        cut[0] = LibDiamond.FacetCut({
            facetAddress: diamondCutFacet,
            action: LibDiamond.FacetCutAction.Add,
            functionSelectors: selectors
        });
        LibDiamond.diamondCut(cut, address(0), "");
    }

    fallback() external payable {
        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
        address facet = ds.selectorToFacetAndPosition[msg.sig].facetAddress;
        require(facet != address(0), "Diamond: Function does not exist");
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    receive() external payable {}
}

DiamondCut Interface

solidity
interface IDiamondCut {
    enum FacetCutAction { Add, Replace, Remove }

    struct FacetCut {
        address facetAddress;
        FacetCutAction action;
        bytes4[] functionSelectors;
    }

    event DiamondCut(FacetCut[] diamondCut, address init, bytes calldata);

    function diamondCut(
        FacetCut[] calldata diamondCut_,
        address init_,
        bytes calldata calldata_
    ) external;
}

Storage Patterns

All state in one struct at a fixed position:

solidity
struct AppStorage {
    // Token state
    mapping(address => uint256) balances;
    mapping(address => mapping(address => uint256)) allowances;
    uint256 totalSupply;
    string name;
    string symbol;

    // Protocol state
    address treasury;
    uint256 feeRate;
    mapping(address => bool) operators;
}

library LibAppStorage {
    bytes32 constant APP_STORAGE_POSITION = keccak256("myprotocol.app.storage");

    function appStorage() internal pure returns (AppStorage storage s) {
        bytes32 position = APP_STORAGE_POSITION;
        assembly { s.slot := position }
    }
}

// Usage in any facet:
contract TokenFacet {
    function balanceOf(address account) external view returns (uint256) {
        return LibAppStorage.appStorage().balances[account];
    }
}
DiamondStorage (Per-Facet Namespaced Storage)

Each facet gets its own storage namespace. Better for composable/reusable facets:

solidity
library LibTokenStorage {
    bytes32 constant STORAGE_POSITION = keccak256("myprotocol.token.storage");

    struct TokenStorage {
        mapping(address => uint256) balances;
        uint256 totalSupply;
    }

    function tokenStorage() internal pure returns (TokenStorage storage s) {
        bytes32 position = STORAGE_POSITION;
        assembly { s.slot := position }
    }
}

library LibGovernanceStorage {
    bytes32 constant STORAGE_POSITION = keccak256("myprotocol.governance.storage");

    struct GovernanceStorage {
        mapping(uint256 => Proposal) proposals;
        uint256 proposalCount;
    }

    function governanceStorage() internal pure returns (GovernanceStorage storage s) {
        bytes32 position = STORAGE_POSITION;
        assembly { s.slot := position }
    }
}

Example Facet

solidity
contract ERC20Facet {
    using LibAppStorage for *;

    event Transfer(address indexed from, address indexed to, uint256 value);

    function transfer(address to, uint256 amount) external returns (bool) {
        AppStorage storage s = LibAppStorage.appStorage();
        require(s.balances[msg.sender] >= amount, "Insufficient balance");

        s.balances[msg.sender] -= amount;
        s.balances[to] += amount;
        emit Transfer(msg.sender, to, amount);
        return true;
    }

    function balanceOf(address account) external view returns (uint256) {
        return LibAppStorage.appStorage().balances[account];
    }
}

Diamond Loupe (Introspection)

solidity
interface IDiamondLoupe {
    struct Facet {
        address facetAddress;
        bytes4[] functionSelectors;
    }

    function facets() external view returns (Facet[] memory);
    function facetFunctionSelectors(address facet) external view returns (bytes4[] memory);
    function facetAddresses() external view returns (address[] memory);
    function facetAddress(bytes4 selector) external view returns (address);
}

Upgrade Process

solidity
// Add new functions
IDiamondCut.FacetCut[] memory cuts = new IDiamondCut.FacetCut[](1);
bytes4[] memory selectors = new bytes4[](2);
selectors[0] = NewFacet.newFunction1.selector;
selectors[1] = NewFacet.newFunction2.selector;
cuts[0] = IDiamondCut.FacetCut({
    facetAddress: address(newFacet),
    action: IDiamondCut.FacetCutAction.Add,
    functionSelectors: selectors
});

// With initialization callback
diamond.diamondCut(cuts, address(initContract), abi.encodeCall(DiamondInit.init, ()));

// Replace existing functions
cuts[0].action = IDiamondCut.FacetCutAction.Replace;

// Remove functions (set facetAddress to address(0))
cuts[0].facetAddress = address(0);
cuts[0].action = IDiamondCut.FacetCutAction.Remove;

Diamond vs Other Patterns

AspectUUPSDiamond
Max contract size24KBUnlimited (split across facets)
Upgrade granularityWhole implementationPer-function
Shared storageN/AAll facets share
ComplexityLowHigh
Audit costLowerHigher
IntrospectionNoDiamondLoupe

When to Use Diamond

  • Contract exceeds 24KB limit
  • Protocol needs modular upgrades (change one function without redeploying all)
  • Multiple teams work on different facets independently
  • Need EIP-165 introspection of all supported interfaces

Security Checklist

  • Only owner/governance can call diamondCut
  • Storage layout is consistent across all facets (use AppStorage or DiamondStorage)
  • No storage collisions between facets (test with forge inspect)
  • Selector clashes are detected before diamondCut (no two facets share a selector)
  • DiamondLoupe is implemented for transparency
  • Initialization contract runs exactly once during upgrades
  • Test full upgrade cycle: add facet → verify → replace → verify → remove

© ccashwell, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/diamond-pattern of ccashwell/evm-cortex.

Open the folder on GitHubat commit f8f3301

Compare with similar skills

Diamond Pattern next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Diamond Pattern compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Diamond Pattern this skillccashwell/evm-cortex131—~1.9kAutomated safety check: PassMIT
Golang Patternsaffaan-m/ECC275k—~1.1kAutomated safety check: PassMIT
Kotlin Exposed Patternsaffaan-m/ECC275k4 repos~5.5kAutomated safety check: PassMIT
Dotnet Patternsaffaan-m/ECC275k1 repos~2.3kAutomated safety check: PassMIT
Fastapi Patternsaffaan-m/ECC275k—~2.3kAutomated safety check: PassMIT
Python Patternsaffaan-m/ECC275k—~2.3kAutomated safety check: PassMIT

Similar skills

  • Golang Patterns

    affaan-m/ECC

    Go-specific design patterns and best practices including functional options, small interfaces, dependency injection, concurrency patterns, error handling, and package organization.

    275k GitHub stars~1.1k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • JetBrains Exposed ORM patterns including DSL queries, DAO pattern, transactions, HikariCP connection pooling, Flyway migrations, and repository pattern.

    275k GitHub starsUsed in 4 repos~5.5k tokens
    DatabasesAuto-check passed
  • Dotnet Patterns

    affaan-m/ECC

    Idiomatic C and .NET patterns, conventions, dependency injection, async/await, and best practices for building robust, maintainable .NET applications.

    275k GitHub starsUsed in 1 repo~2.3k tokens
    DevelopmentAuto-check passed
  • Fastapi Patterns

    affaan-m/ECC

    FastAPI patterns for async APIs, dependency injection, Pydantic request and response models, OpenAPI docs, tests, security, and production readiness.

    275k GitHub stars~2.3k tokensUpdated 3 days ago
    Backend & APIsAuto-check passed
  • Python Patterns

    affaan-m/ECC

    Python-specific design patterns and best practices including protocols, dataclasses, context managers, decorators, async/await, type hints, and package organization.

    275k GitHub stars~2.3k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • Patterns

    sickn33/agentic-awesome-skills

    Reference document for monopoly patterns. An agent skill from sickn33/agentic-awesome-skills.

    47k GitHub starsUsed in 1 repo~2.6k tokens
    Backend & APIsAuto-check passed

More from ccashwell/evm-cortex

All 89 skills in this repo
  • Xray Pre Audit

    ccashwell/evm-cortex

    A skill your agent uses when preparing for a security audit, performing reconnaissance on a new codebase, or creating a protocol overview.

    131 GitHub stars~25k tokensUpdated 8 days ago
    Auto-check passed
  • Aave Integration

    ccashwell/evm-cortex

    A skill your agent uses when integrating with Aave V3 for lending, borrowing, flash loans, or building on top of Aave markets.

    131 GitHub stars~1.3k tokensUpdated 8 days ago
    Auto-check passed
  • Access Control Patterns

    ccashwell/evm-cortex

    Access control design patterns for Solidity protocols. An agent skill from ccashwell/evm-cortex.

    131 GitHub stars~1.8k tokensUpdated 8 days ago
    Auto-check passed
  • Anvil Patterns

    ccashwell/evm-cortex

    A skill your agent uses when running a local Ethereum node with Anvil.

    131 GitHub stars~1.3k tokensUpdated 8 days ago
    Auto-check passed
  • Audit Breadth Scan

    ccashwell/evm-cortex

    A skill your agent uses when performing systematic breadth-first review of all contracts during a security audit.

    131 GitHub stars~1.4k tokensUpdated 8 days ago
    Auto-check passed
  • Audit Depth Analysis

    ccashwell/evm-cortex

    A skill your agent uses when performing deep analysis of specific findings or high-risk areas during a security audit.

    131 GitHub stars~1.6k tokensUpdated 8 days ago
    Auto-check passed

Questions about Diamond Pattern

What does Diamond Pattern do?

A skill your agent uses when building large modular contracts with EIP-2535 Diamond pattern. Diamond Pattern is an agent skill from ccashwell/evm-cortex. Use when building large modular contracts with EIP-2535 Diamond pattern.

When should I use Diamond Pattern?

Diamond Pattern fits situations like: building large modular contracts with EIP-2535 Diamond pattern.

How do I install Diamond Pattern in Claude Code?

Run `npx skills add ccashwell/evm-cortex --skill diamond-pattern -a claude-code`. Or copy the skill folder (skills/diamond-pattern in ccashwell/evm-cortex) into .claude/skills/diamond-pattern in your project. Claude Code loads it when a task matches its description.

How do I install Diamond Pattern in Codex?

Run `npx skills add ccashwell/evm-cortex --skill diamond-pattern -a codex`. Or copy the skill folder (skills/diamond-pattern in ccashwell/evm-cortex) into .agents/skills/diamond-pattern in your project. Codex loads it when a task matches its description.

Can I use Diamond Pattern in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ccashwell/evm-cortex --skill diamond-pattern -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/diamond-pattern, .gemini/skills/diamond-pattern, .github/skills/diamond-pattern and .opencode/skills/diamond-pattern in your project.

What does Diamond Pattern need to run?

SKILL.md names no scripts, command-line tools or credentials: Diamond Pattern is instructions for the agent only.

Does Diamond Pattern access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Diamond Pattern safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Diamond Pattern use?

Diamond Pattern is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Diamond Pattern use?

About 1.9k tokens (SKILL.md is roughly 7.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Diamond Pattern?

Skills that share tags, products or a category with Diamond Pattern: Golang Patterns (affaan-m/ECC, 275k stars), Kotlin Exposed Patterns (affaan-m/ECC, 275k stars), Dotnet Patterns (affaan-m/ECC, 275k stars) and Fastapi Patterns (affaan-m/ECC, 275k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Diamond Pattern?

ccashwell (a GitHub user) maintains it in ccashwell/evm-cortex, which has 131 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on September 30, 2026.

Source: ccashwell/evm-cortex on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.