context

context is a cursor rule for Cursor from rubyroidlabs/rails_api_keys. It costs 727 tokens per session, scanned A, original, MIT.

A reference document describing the architecture and public interface of a Rails engine named rails_api_keys. Rails is a Ruby web framework, and an engine is a reusable component that plugs into a Rails application.

In plain words
What is it for?
Use it when building or changing personal API-key creation and authentication for Rails applications, including which models may own keys and how keys are configured.
Why use it?
It keeps the engine's naming, data model, configuration, and supported behavior in one agreed source of truth.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/. Also seen: mentions AGENTS.md.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is gem "rails_api_keys", path: "../rails_api_keys" # or git:.

Good fit Use it when building or changing personal API-key creation and authentication for Rails applications, including which models may own keys and how keys are configured.

Compare 6 cursor rules from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/rubyroidlabs/rails_api_keys
agentmods
npx agentmods add rules/rubyroidlabs/rails_api_keys/context

Made for: Cursor.

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 context

README.md
[![agentmods](https://agentmods.dev/badge/rules/rubyroidlabs/rails_api_keys/context/github.svg)](https://agentmods.dev/rules/rubyroidlabs/rails_api_keys/context)
Your own site
<a href="https://agentmods.dev/rules/rubyroidlabs/rails_api_keys/context"><img src="https://agentmods.dev/badge/rules/rubyroidlabs/rails_api_keys/context/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 context

Your own site · 80×15
<a href="https://agentmods.dev/rules/rubyroidlabs/rails_api_keys/context"><img src="https://agentmods.dev/badge/rules/rubyroidlabs/rails_api_keys/context.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 727 This file is loaded in full into every session.
When invoked 727 The same file — it is already loaded in full.
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.00727 $0.00727
Opus 5.5 $0.00291 $0.00291
Sonnet 5.5 $0.00145 $0.00145
Haiku 4.5 $0.00073 $0.00073

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

Security

Grade A, and why

context 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 1mo 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.

.cursor/rules/context.mdc · 97 lines

How it starts

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

rails_api_keys Context

Single source of truth for engine state and architecture

Overview

Reusable Rails engine that issues and authenticates personal API keys. Intentionally thin: keys + auth helpers only. Public MIT-licensed gem.

Naming

  • Gem / require / repo: rails_api_keys
  • Module: RailsApiKeys
  • Table: rails_api_keys_api_keys
  • Generator: rails_api_keys:install

Technology

  • Rails engine (>= 7.0), isolated namespace RailsApiKeys
  • Active Record for rails_api_keys_api_keys
  • No frontend, mailers, jobs, or mounted business routes

Public surface

has_api_keys (on owner models)

  • Declares polymorphic has_many :api_keys and registers the model as an allowed owner
  • Adds create_api_key!(name:, permission:) → [record, raw_token] (wraps ApiKey.generate_for!)
  • Multiple models may opt in (e.g. User, Company)
  • Models without the macro cannot own keys

Configuration (RailsApiKeys.configure) — all optional

Option Default Purpose
token_prefix nil → "#{AppName.downcase}_ak_" Prefix for generated raw tokens
owner_active uses active_for_authentication? when present Gate authenticate on owner liveness

Host initializers should only set overrides; do not restate defaults.

RailsApiKeys::ApiKey

  • Polymorphic belongs_to :owner
  • Permissions: read, read_write (immutable after create)
  • generate_for!(owner:, name:, permission:) → [record, raw_token]
  • authenticate(raw_token) → active key if digest matches and owner active; touches last_used_at
  • revoke! sets revoked_at
  • Stores token_digest (SHA-256), token_display_prefix; never plaintext

RailsApiKeys::Authentication

  • authenticate_api_key! — Bearer token → current_api_key / current_api_owner; 401 on auth failure; GET/HEAD require read, other methods require write (403 if lacking)

Install

bin/rails generate rails_api_keys:install
bin/rails db:migrate

Read the full file on GitHub · 97 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. 1mo ago First seen · 97 lines · 727 tokens per session scan A 68efa394df7c

Subscribe to this mod's changes

context is a cursor rule published in the GitHub repository rubyroidlabs/rails_api_keys (10 stars, last pushed 18d ago), licensed MIT. It adds 727 tokens to every session, about $0.0029 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-08-31.