Agent skill

Library Patterns

by ccashwell in ccashwell/evm-cortex

Library design patterns for reusable Solidity code. An agent skill from ccashwell/evm-cortex.

MITAuto-check passedDevelopment

Install Library Patterns

skills CLI
$ npx skills add ccashwell/evm-cortex --skill library-patterns -a claude-code

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

GitHub CLI
$ gh skill install ccashwell/evm-cortex library-patterns --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/library-patterns .claude/skills/library-patterns && 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
library-patterns
GitHub stars
131
Token cost
~1.6k tokens
SKILL.md length
284 words
Files
1
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

Library design patterns for reusable Solidity code. An agent skill from ccashwell/evm-cortex.

  • Works in 6 steps: Pure/view functions only — libraries… → Single responsibility — one library per… → Internal functions preferred — avoids… → …
  • Creating shared utilities
  • SKILL.md covers Internal vs External Libraries, Using-For Directives, Math Libraries and Struct Libraries, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Library Patterns is an agent skill from ccashwell/evm-cortex. Library design patterns for reusable Solidity code. Use when creating shared utilities, math libraries, or type-safe operations. Covers internal vs external libraries, using-for, deployment patterns, and common math libraries.

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

It sits in Development, covering Smart contracts, Design patterns and Type safety. It works with Solidity. The repository describes itself as: Ethereum protocol engineering squad for AI coding assistants. The licence is MIT.

When your agent uses it

  • Creating shared utilities
  • Type-safe operations

Example prompts

  • “/library-patterns”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Pure/view functions only — libraries should not have side effects beyond the storage pointer passed to them
  2. Single responsibility — one library per type or domain
  3. Internal functions preferred — avoids DELEGATECALL overhead
  4. Revert on invalid input — don't return sentinel values
  5. Custom errors over require strings — consistent with protocol patterns
  6. Gas-test critical paths — math libraries are hot paths, benchmark them

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

Library Patterns loads about 1.6k tokens when it runs. Until then it costs about 61 tokens; SKILL.md has 284 words of instructions outside code blocks.

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

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). 284 words, ~1,583 tokens.

Download SKILL.mdSave it as .claude/skills/library-patterns/SKILL.md (or your agent's skills folder).
name
library-patterns
description
Library design patterns for reusable Solidity code. Use when creating shared utilities, math libraries, or type-safe operations. Covers internal vs external libraries, using-for, deployment patterns, and common math libraries.

Library Patterns

Internal vs External Libraries

FeatureInternal (embedded)External (deployed)
DeploymentInlined into calling contractDeployed separately, linked
Call typeJUMP (cheap)DELEGATECALL (expensive)
State accessReads caller's storageReads caller's storage via delegatecall
Gas costLower per callHigher per call, lower deploy if shared
Use caseSmall utilities, mathLarge shared code across many contracts
solidity
// Internal library — inlined at compile time
library SafeCast {
    error SafeCast_Overflow();

    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) revert SafeCast_Overflow();
        return uint128(value);
    }

    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) revert SafeCast_Overflow();
        return uint96(value);
    }

    function toInt256(uint256 value) internal pure returns (int256) {
        if (value > uint256(type(int256).max)) revert SafeCast_Overflow();
        return int256(value);
    }
}

Using-For Directives

Attach library functions to types for cleaner syntax.

solidity
using SafeCast for uint256;
using FixedPointMathLib for uint256;

function calculateShares(uint256 assets, uint256 totalAssets, uint256 totalShares)
    internal
    pure
    returns (uint256)
{
    return assets.mulDivDown(totalShares, totalAssets);
}

function packTimestamp(uint256 timestamp) internal pure returns (uint48) {
    return timestamp.toUint48();
}
Global Using-For (Solidity 0.8.13+)
solidity
// In a shared file, apply globally to all files that import it
using SafeCast for uint256 global;
using FixedPointMathLib for uint256 global;

Math Libraries

Solmate FixedPointMathLib

The gold standard for fixed-point math. Gas-optimized with assembly.

solidity
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";

using FixedPointMathLib for uint256;

// Multiply then divide, rounding down — prevents phantom overflow
uint256 shares = assets.mulDivDown(totalShares, totalAssets);

// Multiply then divide, rounding up — useful for debt calculations
uint256 debt = borrowed.mulDivUp(interestRate, PRECISION);

// WAD math (18 decimal fixed point)
uint256 result = a.mulWadDown(b);  // (a * b) / 1e18, round down
uint256 result = a.divWadUp(b);    // (a * 1e18) / b, round up

// Square root
uint256 sqrtPrice = FixedPointMathLib.sqrt(price);
When to Round Up vs Down
ContextDirectionReason
Minting shares from assetsRound downFewer shares protects vault
Burning shares for assetsRound downFewer assets protects vault
Calculating debt owedRound upMore debt protects lender
Calculating collateral requiredRound upMore collateral protects protocol
Fee calculationRound upEnsures protocol collects at least the fee

Struct Libraries

Encapsulate operations on custom types in libraries.

solidity
struct Position {
    uint128 collateral;
    uint128 debt;
    uint48 lastUpdate;
    uint16 healthFactor;
}

library PositionLib {
    using SafeCast for uint256;
    using FixedPointMathLib for uint256;

    error Position_Undercollateralized();

    function addCollateral(Position storage self, uint256 amount) internal {
        self.collateral += amount.toUint128();
        self.lastUpdate = uint48(block.timestamp);
    }

    function addDebt(Position storage self, uint256 amount) internal {
        self.debt += amount.toUint128();
        self.lastUpdate = uint48(block.timestamp);
    }

    function healthFactor(Position storage self, uint256 price)
        internal
        view
        returns (uint256)
    {
        if (self.debt == 0) return type(uint256).max;
        return uint256(self.collateral).mulDivDown(price, uint256(self.debt));
    }

    function isHealthy(Position storage self, uint256 price, uint256 minHealth)
        internal
        view
        returns (bool)
    {
        return healthFactor(self, price) >= minHealth;
    }
}

Usage:

solidity
using PositionLib for Position;

mapping(address => Position) public positions;

function addCollateral(uint256 amount) external {
    positions[msg.sender].addCollateral(amount);
    // ...
}

Enumerable Set / Map Libraries

For onchain iteration requirements, use OpenZeppelin's EnumerableSet.

solidity
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

using EnumerableSet for EnumerableSet.AddressSet;

EnumerableSet.AddressSet private _whitelistedTokens;

function addToken(address token) external onlyOwner {
    if (!_whitelistedTokens.add(token)) revert AlreadyWhitelisted();
}

function isWhitelisted(address token) external view returns (bool) {
    return _whitelistedTokens.contains(token);
}

function getWhitelistedTokens() external view returns (address[] memory) {
    return _whitelistedTokens.values();
}

Library Design Guidelines

  1. Pure/view functions only — libraries should not have side effects beyond the storage pointer passed to them
  2. Single responsibility — one library per type or domain
  3. Internal functions preferred — avoids DELEGATECALL overhead
  4. Revert on invalid input — don't return sentinel values
  5. Custom errors over require strings — consistent with protocol patterns
  6. Gas-test critical paths — math libraries are hot paths, benchmark them

Library Design Checklist

  • Library has a single, focused responsibility
  • All functions are internal unless deployment sharing is needed
  • using-for applied to relevant types
  • Math operations use audited libraries (Solmate, OpenZeppelin)
  • Rounding direction explicitly chosen and documented
  • Safe casting used for all type narrowing
  • Custom errors defined within the library
  • NatSpec on all public-facing functions

© 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/library-patterns of ccashwell/evm-cortex.

Open the folder on GitHubat commit f8f3301

Compare with similar skills

Library Patterns 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.

Library Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Library Patterns this skillccashwell/evm-cortex131—~1.6kAutomated safety check: PassMIT
Foundry Deploy Fixturesaviggiano/security144—~634Automated safety check: PassMIT
New Configlidofinance/diffyscan142—~1kAutomated safety check: PassMIT
Validate Configlidofinance/diffyscan142—~1.1kAutomated safety check: PassMIT
Foundry Differential Testsaviggiano/security144—~613Automated safety check: PassMIT
Smart Contract InteractionNethereum/Nethereum2.3k—~1.9kAutomated safety check: PassMIT

Similar skills

  • Foundry Deploy Fixtures

    aviggiano/security

    Create or refactor Foundry deployment fixtures for Solidity tests.

    144 GitHub stars~634 tokensUpdated 22 days ago
    Backend & APIsAuto-check passed
  • New Config

    lidofinance/diffyscan

    Creates or extends a Diffyscan verification config for a deployed contract or deployment.

    142 GitHub stars~1k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Validate Config

    lidofinance/diffyscan

    Reviews an existing Diffyscan YAML or JSON config for load errors, runtime prerequisites, pinned sources, address mappings and broad exceptions.

    142 GitHub stars~1.1k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Foundry Differential Tests

    aviggiano/security

    Create Foundry differential tests comparing production Solidity contracts against an independent reference model.

    144 GitHub stars~613 tokensUpdated 22 days ago
    Backend & APIsAuto-check passed
  • Smart Contract Interaction

    Nethereum/Nethereum

    Interact with Ethereum smart contracts using Nethereum typed DTOs.

    2.3k GitHub stars~1.9k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed
  • Gh Update PR Description

    lidofinance/staking-modules

    Update the current-branch GitHub PR title, description, and labels with gh CLI using this repository's PR template.

    119 GitHub stars~568 tokensUpdated yesterday
    DevelopmentAuto-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

Works with

Questions about Library Patterns

What does Library Patterns do?

Library design patterns for reusable Solidity code. An agent skill from ccashwell/evm-cortex. Library Patterns is an agent skill from ccashwell/evm-cortex. Library design patterns for reusable Solidity code.

When should I use Library Patterns?

Library Patterns fits situations like: creating shared utilities; type-safe operations.

How do I install Library Patterns in Claude Code?

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

How do I install Library Patterns in Codex?

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

Can I use Library Patterns 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 library-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/library-patterns, .gemini/skills/library-patterns, .github/skills/library-patterns and .opencode/skills/library-patterns in your project.

What does Library Patterns need to run?

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

Does Library Patterns 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 Library Patterns 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 Library Patterns use?

Library Patterns 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 Library Patterns use?

About 1.6k tokens (SKILL.md is roughly 6.3k 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 Library Patterns?

Skills that share tags, products or a category with Library Patterns: Foundry Deploy Fixtures (aviggiano/security, 144 stars), New Config (lidofinance/diffyscan, 142 stars), Validate Config (lidofinance/diffyscan, 142 stars) and Foundry Differential Tests (aviggiano/security, 144 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Library Patterns?

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.