library-patterns

library-patterns is a skill for Claude Code, Codex from ccashwell/evm-cortex. It costs 43 tokens per session (1,416 once invoked), scanned A, original, MIT.

A guide to designing reusable Solidity libraries, which are shared collections of functions for contracts. It explains when code should be embedded in a contract or deployed separately.

In plain words
What is it for?
Use it when creating shared utilities, safe numeric conversions, math libraries, or type-attached functions in Solidity.
Why use it?
It helps keep repeated utility and math code consistent while making deployment and execution costs clearer.

Skill for Claude CodeCodex

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

Good fit Use it when creating shared utilities, safe numeric conversions, math libraries, or type-attached functions in Solidity.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ccashwell/evm-cortex/library-patterns
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 ccashwell/evm-cortex --skill library-patterns
Clone the repo
git clone --depth 1 https://github.com/ccashwell/evm-cortex

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 library-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/ccashwell/evm-cortex/library-patterns/github.svg)](https://agentmods.dev/skills/ccashwell/evm-cortex/library-patterns)
Your own site
<a href="https://agentmods.dev/skills/ccashwell/evm-cortex/library-patterns"><img src="https://agentmods.dev/badge/skills/ccashwell/evm-cortex/library-patterns/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 library-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/ccashwell/evm-cortex/library-patterns"><img src="https://agentmods.dev/badge/skills/ccashwell/evm-cortex/library-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 43 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,416 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00043 $0.01416
Opus 5.5 $0.00017 $0.00566
Sonnet 5.5 $0.00009 $0.00283
Haiku 4.5 $0.00004 $0.00142

Measured 2mo ago against content hash a44d9fc31c91, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

library-patterns 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 2mo 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/library-patterns/SKILL.md · 207 lines

How it starts

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

Library Patterns

Internal vs External Libraries

Feature Internal (embedded) External (deployed)
Deployment Inlined into calling contract Deployed separately, linked
Call type JUMP (cheap) DELEGATECALL (expensive)
State access Reads caller's storage Reads caller's storage via delegatecall
Gas cost Lower per call Higher per call, lower deploy if shared
Use case Small utilities, math Large shared code across many contracts
// 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.

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+)

// 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.

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);

Read the full file on GitHub · 207 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. 2mo ago First seen · 207 lines · 43 tokens per session scan A a44d9fc31c91

Subscribe to this mod's changes

library-patterns is a skill published in the GitHub repository ccashwell/evm-cortex (131 stars, last pushed 1mo ago), licensed MIT. It adds 43 tokens to every session and 1,416 once invoked, about $0.0002 per session on Opus 5.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.

Related

library-patterns compared with skills from other repositories

library-patterns next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
library-patternsccashwell/evm-cortexSkill1311mo agoMITA43Claude Code, Codex
imagegenopenai/codexSkill137kyesterdayApache-2.0A113Codex
playwright-climicrosoft/playwrightSkill101kyesterdayApache-2.0A19Claude Code
browser-automationopenclaw/openclawSkill395ktodayMITA36Claude Code
systematic-debuggingobra/superpowersSkill331k3d agoMITA21Claude Code
free-llm-apismnfst/awesome-free-llm-apisSkill15kyesterdayCC0-1.0A113Claude Code, Codex
next-cache-components-adoptionvercel/next.jsSkill144ktodayMITA95Claude Code