Build your own agentic layer, part 2: rules, skills, and the context window

Part 2 of a series on building your own agentic layer. Part 1 covers what an agentic layer is.
The first thing you'll want to do is write rules. The second thing you'll find out is that every rule costs something, every session, forever.
Rules: what the agent always knows
A rules file is plain markdown that the harness adds to the model's instructions at the start of every session. For Claude Code that's CLAUDE.md. Trillian writes its rules once in .ruler/AGENTS.md, and ruler generates the CLAUDE.md from it.
Mine has things like:
- Stage changes, never commit or push. I run the commit.
- Commit messages are a subject and one or two sentences of why.
- Diagrams in Mermaid, never ASCII art.
- Never log secrets.
- When you're about to do something I asked for that's less safe or more work than another option, say so once before you start.
The good rules are specific and say why. "Write good commit messages" does nothing. "Subject under 72 characters, body says why and not what, because the diff already shows what" actually changes the output.
The catch: the context window
Everything in the rules file lands in the context window, the model's working memory, before you've typed a word. That has two costs. You pay for those tokens on every turn, and the model has to split its attention between your rules and your actual task. Anthropic calls managing this context engineering, and it's most of the craft here.
In September I had Claude audit Trillian. It measured about 34,000 tokens of instructions loaded into every single session. About 15,500 of those were rules for my day job, and they were loading in my personal projects too, because Claude Code reads every file in ~/.claude/rules/ no matter what you're working on. That's a lot of attention spent on rules that didn't apply.
Skills: what the agent loads when it needs it
The fix is progressive disclosure: show the agent a one-line summary of what's available, and let it load the full details only when the task calls for it.
In Claude Code that's a skill. A skill is a folder with a SKILL.md in it. Only the name and description sit in context all the time. Here's the top of my SQL one:
---
name: sql
description: >-
SQL standards for application code and schema changes — parameterization,
explicit columns, and migrations. Use whenever writing or reviewing SQL or
data-access code: queries, stored procedures, schema/DDL, or migrations
against MSSQL, Supabase, or Postgres. Trigger on ".sql" files,
"SELECT/INSERT/UPDATE", "CREATE TABLE", "migration", or any database query work.
---
When I ask for a migration, the model sees "migration" in that description, loads the full file, and follows it. When I'm writing CSS, the SQL rules cost me one paragraph instead of a page.

Trillian has 35 skills now. Most are per-language standards (TypeScript, C#, Rust, SQL, Swift), some are architecture styles, and some are workflows like writing a design doc. The day-job rules from that audit moved into a skill too, with a short pointer left in the always-loaded rules.
The description is the part to sweat. It's the only thing the model sees when it decides whether to load the skill, so I write it like a list of search terms: file extensions, keywords, the phrases I actually type.
What goes where
My rule of thumb now:
- Rules for anything that applies to every task in every repo. How I want commits, how to talk to me, what's off limits.
- Skills for anything that only applies to some tasks. A language, a framework, a procedure.
- A one-line pointer in the rules when a skill has to fire. My rules say "before writing any service-layer code, load the idesign skill." It's the most-loaded skill I have.
When the model forgets anyway
Even with a good description, the model sometimes doesn't load a skill, or forgets a rule halfway through a long session. Rules near the top of a long conversation lose out to whatever came in most recently.
So for a few things that matter every turn, Trillian has a hook (more on hooks in part 4) that adds a short reminder to every prompt I send. It's a couple of lines, like which modes are on and the commit message limits. It's cheaper than a bigger rules file and it shows up right where the model is looking.
Watch for junk
One more thing from that audit. My ~/.claude/skills/ folder had 241 directories for 34 real skills. Each skill had been copied six times under random names, and every copy put its description into every session. The cause was my own install script on Windows, where a symlink command quietly made copies instead of links.
I wouldn't have found that without measuring. Every so often, look at what's actually loading.
Links
- Claude Code skills
- How Claude Code loads CLAUDE.md and rules
- Equipping agents for the real world with Agent Skills, Anthropic's post on why skills work this way
- Effective context engineering for AI agents
- AGENTS.md and ruler
Drafted with an assistant, edited by @wintaru
0 comments