Agent skill

Subgraph Patterns

by ccashwell in ccashwell/evm-cortex

A skill your agent uses when building or maintaining The Graph subgraphs.

MITAuto-check passedBackend & APIs

Install Subgraph Patterns

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

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

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

At a glance

A skill your agent uses when building or maintaining The Graph subgraphs.

  • Maintaining The Graph subgraphs
  • SKILL.md covers Project Structure, Subgraph Manifest…, Schema Design (schema.graphql) and AssemblyScript Mappings, plus 5 more sections
  • Reaches api.thegraph.com; needs DEPLOY_KEY
  • Tasks that involve GraphQL

What it does

Subgraph Patterns is an agent skill from ccashwell/evm-cortex. Use when building or maintaining The Graph subgraphs. Covers subgraph.yaml manifest, schema.graphql design, AssemblyScript mappings, event handlers, data source templates, testing with matchstick, deployment, and indexing optimization.

Its SKILL.md is about 2.1k 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 Backend & APIs, covering GraphQL and Deployment. It works with GraphQL. The repository describes itself as: Ethereum protocol engineering squad for AI coding assistants. The licence is MIT.

When your agent uses it

  • Maintaining The Graph subgraphs
  • Tasks that involve GraphQL
  • Tasks that involve Deployment

Example prompts

  • “/subgraph-patterns”

Requirements

  • A credential in DEPLOY_KEY

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 graphql, typescript, yaml and bash).

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

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • api.thegraph.com

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

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • DEPLOY_KEY

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

Context cost

Subgraph Patterns loads about 2.1k tokens when it runs. Until then it costs about 63 tokens; SKILL.md has 114 words of instructions outside code blocks.

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

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). 114 words, ~2,076 tokens.

Download SKILL.mdSave it as .claude/skills/subgraph-patterns/SKILL.md (or your agent's skills folder).
name
subgraph-patterns
description
Use when building or maintaining The Graph subgraphs. Covers subgraph.yaml manifest, schema.graphql design, AssemblyScript mappings, event handlers, data source templates, testing with matchstick, deployment, and indexing optimization.

The Graph Subgraph Patterns

Project Structure

my-subgraph/
├── subgraph.yaml           # Manifest: data sources, event handlers
├── schema.graphql           # Entity definitions (GraphQL)
├── src/
│   └── mappings.ts          # Event handler logic (AssemblyScript)
├── tests/
│   └── mappings.test.ts     # Matchstick unit tests
├── abis/
│   └── MyContract.json      # Contract ABIs
└── networks.json            # Multi-network config

Subgraph Manifest (subgraph.yaml)

yaml
specVersion: 1.0.0
indexerHints:
  prune: auto
schema:
  file: ./schema.graphql
dataSources:
  - kind: ethereum
    name: MyProtocol
    network: base
    source:
      address: "0xContractAddress"
      abi: MyProtocol
      startBlock: 12345678  # Block contract was deployed
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.9
      language: wasm/assemblyscript
      entities:
        - Deposit
        - Withdrawal
        - User
      abis:
        - name: MyProtocol
          file: ./abis/MyProtocol.json
        - name: ERC20
          file: ./abis/ERC20.json
      eventHandlers:
        - event: Deposit(indexed address,uint256,uint256)
          handler: handleDeposit
        - event: Withdrawal(indexed address,uint256)
          handler: handleWithdrawal
      file: ./src/mappings.ts
templates:
  - kind: ethereum
    name: Vault
    network: base
    source:
      abi: Vault
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.9
      language: wasm/assemblyscript
      entities:
        - VaultDeposit
      abis:
        - name: Vault
          file: ./abis/Vault.json
      eventHandlers:
        - event: VaultDeposit(indexed address,uint256)
          handler: handleVaultDeposit
      file: ./src/vault-mappings.ts

Schema Design (schema.graphql)

graphql
type Protocol @entity {
  id: Bytes!                    # Use Bytes! for addresses
  totalDeposited: BigDecimal!
  totalUsers: BigInt!
  vaults: [Vault!]! @derivedFrom(field: "protocol")
}

type User @entity {
  id: Bytes!                    # user address
  deposits: [Deposit!]! @derivedFrom(field: "user")
  totalDeposited: BigDecimal!
  firstDepositAt: BigInt!
  lastActiveAt: BigInt!
}

type Vault @entity {
  id: Bytes!                    # vault address
  protocol: Protocol!
  asset: Bytes!
  totalAssets: BigDecimal!
  deposits: [Deposit!]! @derivedFrom(field: "vault")
  createdAt: BigInt!
  createdAtBlock: BigInt!
}

type Deposit @entity(immutable: true) {
  id: Bytes!                    # tx hash + log index
  user: User!
  vault: Vault!
  amount: BigDecimal!
  shares: BigInt!
  timestamp: BigInt!
  blockNumber: BigInt!
  transactionHash: Bytes!
}

type DailySnapshot @entity {
  id: String!                   # "YYYY-MM-DD"
  date: BigInt!
  totalDeposited: BigDecimal!
  depositCount: BigInt!
  uniqueUsers: BigInt!
}

Key schema patterns:

  • Use @entity(immutable: true) for event logs (faster indexing)
  • Use @derivedFrom for reverse lookups (no storage cost)
  • Use Bytes! for addresses, BigDecimal! for token amounts
  • Composite IDs for uniqueness: txHash + logIndex

AssemblyScript Mappings

typescript
import { BigDecimal, BigInt, Bytes, Address } from "@graphprotocol/graph-ts";
import { Deposit as DepositEvent, Withdrawal } from "../generated/MyProtocol/MyProtocol";
import { Deposit, User, Protocol, Vault } from "../generated/schema";
import { Vault as VaultTemplate } from "../generated/templates";

let ZERO_BD = BigDecimal.zero();
let ZERO_BI = BigInt.zero();
let ONE_BI = BigInt.fromI32(1);

function getOrCreateProtocol(): Protocol {
  let protocol = Protocol.load(Bytes.fromHexString("0x01"));
  if (protocol == null) {
    protocol = new Protocol(Bytes.fromHexString("0x01"));
    protocol.totalDeposited = ZERO_BD;
    protocol.totalUsers = ZERO_BI;
  }
  return protocol;
}

function getOrCreateUser(address: Address, timestamp: BigInt): User {
  let user = User.load(address);
  if (user == null) {
    user = new User(address);
    user.totalDeposited = ZERO_BD;
    user.firstDepositAt = timestamp;
    user.lastActiveAt = timestamp;

    let protocol = getOrCreateProtocol();
    protocol.totalUsers = protocol.totalUsers.plus(ONE_BI);
    protocol.save();
  }
  return user;
}

export function handleDeposit(event: DepositEvent): void {
  let user = getOrCreateUser(event.params.user, event.block.timestamp);
  let amount = event.params.amount.toBigDecimal().div(BigDecimal.fromString("1e18"));

  let deposit = new Deposit(
    event.transaction.hash.concatI32(event.logIndex.toI32())
  );
  deposit.user = user.id;
  deposit.vault = event.address;
  deposit.amount = amount;
  deposit.shares = event.params.shares;
  deposit.timestamp = event.block.timestamp;
  deposit.blockNumber = event.block.number;
  deposit.transactionHash = event.transaction.hash;
  deposit.save();

  user.totalDeposited = user.totalDeposited.plus(amount);
  user.lastActiveAt = event.block.timestamp;
  user.save();

  let protocol = getOrCreateProtocol();
  protocol.totalDeposited = protocol.totalDeposited.plus(amount);
  protocol.save();
}

Data Source Templates

For dynamically created contracts (e.g., factory-deployed vaults):

typescript
import { VaultCreated } from "../generated/Factory/Factory";
import { Vault as VaultTemplate } from "../generated/templates";
import { Vault } from "../generated/schema";

export function handleVaultCreated(event: VaultCreated): void {
  // Start indexing the new vault contract
  VaultTemplate.create(event.params.vault);

  let vault = new Vault(event.params.vault);
  vault.protocol = Bytes.fromHexString("0x01");
  vault.asset = event.params.asset;
  vault.totalAssets = BigDecimal.zero();
  vault.createdAt = event.block.timestamp;
  vault.createdAtBlock = event.block.number;
  vault.save();
}

Testing with Matchstick

typescript
import { assert, test, clearStore, beforeEach } from "matchstick-as/assembly/index";
import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts";
import { handleDeposit } from "../src/mappings";
import { Deposit } from "../generated/MyProtocol/MyProtocol";

function createDepositEvent(user: string, amount: BigInt, shares: BigInt): Deposit {
  let event = changetype<Deposit>(newMockEvent());
  event.parameters = new Array();
  event.parameters.push(new ethereum.EventParam("user", ethereum.Value.fromAddress(Address.fromString(user))));
  event.parameters.push(new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigInt(amount)));
  event.parameters.push(new ethereum.EventParam("shares", ethereum.Value.fromUnsignedBigInt(shares)));
  return event;
}

beforeEach(() => { clearStore(); });

test("handleDeposit creates entities", () => {
  let event = createDepositEvent("0x0000000000000000000000000000000000000001", BigInt.fromString("1000000000000000000"), BigInt.fromString("1000000000000000000"));
  handleDeposit(event);
  assert.entityCount("Deposit", 1);
  assert.entityCount("User", 1);
});

Deployment

bash
# Build
graph codegen && graph build

# Deploy to Subgraph Studio
graph auth --studio $DEPLOY_KEY
graph deploy --studio my-subgraph

# Deploy to hosted service (deprecated, use Studio)
graph deploy --node https://api.thegraph.com/deploy/ my-org/my-subgraph

Querying

graphql
{
  deposits(first: 10, orderBy: timestamp, orderDirection: desc) {
    id
    user { id totalDeposited }
    amount
    timestamp
  }
  protocol(id: "0x01") {
    totalDeposited
    totalUsers
  }
}

Pagination for large datasets:

graphql
{
  deposits(first: 1000, where: { id_gt: "0xlastId" }, orderBy: id) {
    id
    amount
  }
}

Performance Tips

  • Mark event entities as @entity(immutable: true) — 30-50% faster indexing
  • Use Bytes over String for addresses and hashes
  • Minimize store.get calls — batch reads where possible
  • Set startBlock to contract deployment block (skip empty blocks)
  • Use indexerHints.prune: auto to reduce storage
  • Avoid expensive BigDecimal math in hot paths

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

Open the folder on GitHubat commit f8f3301

Compare with similar skills

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

Subgraph Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Subgraph Patterns this skillccashwell/evm-cortex131—~2.1kAutomated safety check: PassMIT
Ar Io Gateway Operatorar-io/ar-io-node127—~8.2kAutomated safety check: NotesAGPL-3.0
Thegraph MCP Skillholon-run/uxc115—~1.1kAutomated safety check: PassMIT
DagsterVectorSpaceLab/AREX-Skill328—~1.3kAutomated safety check: PassApache-2.0
Railway APImajiayu000/claude-skill-registry6661 repos~2kAutomated safety check: PassMIT
Subgraph Development Guidenirholas/three.ws226—~2.1kAutomated safety check: PassMIT

Similar skills

  • Ar Io Gateway Operator

    ar-io/ar-io-node

    Operate any AR.IO node deployment — architecture, daily ops, diagnostics, and recurring pitfalls that apply to every operator.

    127 GitHub stars~8.2k tokensUpdated today
    Backend & APIsAuto-check: notes
  • Thegraph MCP Skill

    holon-run/uxc

    Use The Graph Subgraph MCP through UXC via native SSE with a fixed linked command for subgraph discovery, schema retrieval, deployment selection, and GraphQL query execution with help-first…

    115 GitHub stars~1.1k tokensUpdated 22 days ago
    Backend & APIsAuto-check passed
  • Dagster

    VectorSpaceLab/AREX-Skill

    A skill your agent uses when working with Dagster OSS: assets, jobs, Definitions, config/resources, schedules/sensors, automation, CLI/local development, deployment operations, GraphQL/webserver…

    328 GitHub stars~1.3k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Railway API

    majiayu000/claude-skill-registry

    Railway.com GraphQL API automation for projects, services, deployments, and environment variables.

    666 GitHub starsUsed in 1 repo~2k tokens
    DevOps & CloudAuto-check passed
  • Guide to building blockchain data indexes with The Graph — subgraph architecture, schema design, mapping handlers, deployment, and querying.

    226 GitHub stars~2.1k tokensUpdated today
    DatabasesAuto-check passed
  • API Designer

    Jeffallan/claude-skills

    Designs REST and GraphQL APIs from resource modeling to an OpenAPI 3.1 contract, with versioning, pagination and RFC 7807 error handling.

    12k GitHub starsUsed in 2 repos~2k 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 7 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 7 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 7 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 7 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 7 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 7 days ago
    Auto-check passed

Works with

Categories

Questions about Subgraph Patterns

What does Subgraph Patterns do?

A skill your agent uses when building or maintaining The Graph subgraphs. Subgraph Patterns is an agent skill from ccashwell/evm-cortex. Use when building or maintaining The Graph subgraphs.

When should I use Subgraph Patterns?

Subgraph Patterns fits situations like: maintaining The Graph subgraphs; tasks that involve GraphQL; tasks that involve Deployment.

How do I install Subgraph Patterns in Claude Code?

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

How do I install Subgraph Patterns in Codex?

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

Can I use Subgraph 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 subgraph-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/subgraph-patterns, .gemini/skills/subgraph-patterns, .github/skills/subgraph-patterns and .opencode/skills/subgraph-patterns in your project.

What does Subgraph Patterns need to run?

Going by SKILL.md and its folder, Subgraph Patterns needs credentials named DEPLOY_KEY. Our summary lists: A credential in DEPLOY_KEY.

Does Subgraph Patterns access the network?

SKILL.md names 1 domain. In commands or code: api.thegraph.com; the agent is likely to contact it when it follows the instructions. This is read from the text; nothing was executed.

Is Subgraph 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 Subgraph Patterns use?

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

About 2.1k tokens (SKILL.md is roughly 8.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 Subgraph Patterns?

Skills that share tags, products or a category with Subgraph Patterns: Ar Io Gateway Operator (ar-io/ar-io-node, 127 stars), Thegraph MCP Skill (holon-run/uxc, 115 stars), Dagster (VectorSpaceLab/AREX-Skill, 328 stars) and Railway API (majiayu000/claude-skill-registry, 666 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Subgraph 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.