Course contents
Scoping AI rules with globs, and managing your context budget
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:
---
description: "React component conventions"
globs: "src/**/*.tsx, src/**/*.ts"
alwaysApply: false
---
globs is one comma-separated string.
---
applyTo: "src/**/*.tsx,src/**/*.ts"
---
applyTo is one comma-separated string.
---
paths:
- "src/**/*.{ts,tsx}"
---
paths takes a YAML list or a comma-separated string. Brace expansion works.
---
paths:
- "src/**/*.tsx"
- "src/**/*.ts"
---
paths is a YAML list of globs.
---
trigger: glob
globs: "src/**/*.tsx, src/**/*.ts"
---
Set trigger: glob, then globs.
---
trigger: glob
globs: "src/**/*.tsx, src/**/*.ts"
description: "React component conventions"
---
Quote patterns that start with * so YAML doesn't read them as aliases.
Codex has no glob frontmatter. Scope by folder instead: put an AGENTS.md in src/ (or the package folder). Codex reads it when you start in that folder or below.
Glob gotchas
- Patterns are relative to the project root (for Claude Code, the folder containing
.claude).components/**doesn't matchsrc/components/Button.tsx; use**/components/**orsrc/components/**. - One star vs. two. In Copilot's docs,
*.pymatches only the current directory and**/*.pymatches all directories. Use**/when you mean "anywhere". - Root config files. A Next.js rule should also match
next.config.tsandproxy.ts, which aren't inapp/. List them explicitly. - Overly broad scopes.
**/*.tson 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):
| Tool | Limit or guidance |
|---|---|
| Codex | All AGENTS.md files combined stop at 32 KiB (project_doc_max_bytes). Skills list capped at 2% of the context window. |
| Antigravity | 24,000 bytes per rule file; 20,000 tokens across all always-on and global rules. |
| Claude Code | Target under 200 lines per CLAUDE.md. Skill descriptions cut at 1,536 characters in the listing. |
| Cursor | Keep rules under 500 lines. |
| Agent Skills spec | Keep 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:
- Move stack sections into nested
AGENTS.mdfiles in the packages that use them. - Install only the stacks a folder needs, using
--cwdto target that folder. - Raise
project_doc_max_bytesin~/.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
*.tswon't load when the agent editspackage.json. Universal facts belong in the always-on file. - Stacking always-on rules. Five
alwaysApply: truerules 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, ortrigger: glob. Codex scopes by folder. - Know the limits: 32 KiB for Codex
AGENTS.md, 24 KB per Antigravity rule, about 200 lines perCLAUDE.md. - Measure with
wc -cand the tool's context view.
Next step
Write the always-on file well: AGENTS.md that works across tools.