Course contents

Scoping AI rules with globs, and managing your context budget

intermediate4 min readUpdated
  • Cursor
  • GitHub Copilot
  • Claude Code
  • Windsurf / Devin
  • Cline
  • Codex
  • Antigravity CLI
On this page

Why scope at all

An always-on rule is paid for on every request. A React rule loading while the agent edits Terraform wastes tokens and adds noise that can pull the agent in the wrong direction. Scoping fixes both: the rule appears when the agent touches matching files and stays out of the way otherwise.

The same scope in six syntaxes

Here's one scope, "TypeScript React files under src/", written for each tool that supports file-pattern rules:

.cursor/rules/react.mdc
---
description: "React component conventions"
globs: "src/**/*.tsx, src/**/*.ts"
alwaysApply: false
---

globs is one comma-separated string.

Glob gotchas

  • Patterns are relative to the project root (for Claude Code, the folder containing .claude). components/** doesn't match src/components/Button.tsx; use **/components/** or src/components/**.
  • One star vs. two. In Copilot's docs, *.py matches only the current directory and **/*.py matches all directories. Use **/ when you mean "anywhere".
  • Root config files. A Next.js rule should also match next.config.ts and proxy.ts, which aren't in app/. List them explicitly.
  • Overly broad scopes. **/*.ts on a TypeScript monorepo is effectively always-on. Narrow to the package or the layer.
  • Brackets. In Claude Code, a [ starts a bracket expression; a malformed one makes that pattern match nothing.

Scoped vs. description-based

Some tools can also load a rule when the agent judges it relevant from its description: Cursor ("Apply Intelligently"), Devin and Antigravity (model_decision). Use it when the topic isn't tied to file paths, like "database migrations" or "payments". Use globs when it is. Globs are more predictable; descriptions are more flexible.

Your context budget, tool by tool

These are the numbers that matter, from each tool's docs (November 2026):

ToolLimit or guidance
CodexAll AGENTS.md files combined stop at 32 KiB (project_doc_max_bytes). Skills list capped at 2% of the context window.
Antigravity24,000 bytes per rule file; 20,000 tokens across all always-on and global rules.
Claude CodeTarget under 200 lines per CLAUDE.md. Skill descriptions cut at 1,536 characters in the listing.
CursorKeep rules under 500 lines.
Agent Skills specKeep SKILL.md under 500 lines and under about 5,000 tokens; name and description about 100 tokens.

Measure, don't guess

wc -c AGENTS.md GEMINI.md CLAUDE.md 2>/dev/null
find .cursor/rules .claude/rules .clinerules .devin/rules -name '*.md*' -exec wc -c {} + 2>/dev/null

A rough conversion is about 4 characters per token for English prose, so a 9 KB rule is around 2,000 to 2,500 tokens. Code-heavy text is often denser.

In Claude Code and Antigravity CLI, /context shows the real breakdown. In Codex, /status shows context usage.

A worked example

You install five presets.dev stacks for Codex: nextjs, react, typescript, tailwind and supabase. That appends five sections to AGENTS.md, 25.3 KB in our test. Your own root guidance is another 4 KB, so you're at about 29 KB of a 32 KiB budget. One more large stack, and Codex starts dropping the end of the file, which is usually the most recently added and most specific content.

Options:

  1. Move stack sections into nested AGENTS.md files in the packages that use them.
  2. Install only the stacks a folder needs, using --cwd to target that folder.
  3. Raise project_doc_max_bytes in ~/.codex/config.toml (each teammate has to do this).

For tools with glob scoping, like Cursor or Claude Code, the same five stacks cost nothing until matching files are touched.

Common mistakes

  • Scoping a universal fact. "Use pnpm" scoped to *.ts won't load when the agent edits package.json. Universal facts belong in the always-on file.
  • Stacking always-on rules. Five alwaysApply: true rules is one giant rule. Merge or scope them.
  • Forgetting that skills cost something too. Each installed skill adds its description to every session. Remove skills nobody uses.

Recap

  • Scope conventions to the files they cover; keep universal facts always on.
  • Learn your tool's syntax: globs, applyTo, paths, or trigger: glob. Codex scopes by folder.
  • Know the limits: 32 KiB for Codex AGENTS.md, 24 KB per Antigravity rule, about 200 lines per CLAUDE.md.
  • Measure with wc -c and the tool's context view.

Next step

Write the always-on file well: AGENTS.md that works across tools.