Lesson 2: Crafting the System Constitution (CLAUDE.md / AGENT.md)
High-density directives vs. conversational fluff. Defining build scripts, style preferences, and error handling boundaries. Writing a strict constraint file that stops an AI from changing your core packages.
By Bishwambhar Sen • Last updated • 75 min
Every agent needs a set of rules—a constitution—to guide its actions. In this lesson, we will explore how files like CLAUDE.md and AGENT.md shape agent behavior, enforce codebase safety, and lock down core packages.
Theory: Directives vs. Conversational Fluff
AI models process every word in a prompt using self-attention. Writing polite, conversational sentences like:
wastes valuable tokens, is ambiguous, and weakens the model's compliance. In contrast, **high-density directives** use clear, imperative, and structured formatting:
Structured directives eliminate ambiguity, keep context sizes lean, and establish strict error-handling boundaries.
Hands-on: Drafting the System Constitution
A standard system constitution (e.g. CLAUDE.md or AGENT.md) resides at the root of your repository. It communicates three critical categories of instructions:
- Commands & Scripts: Tell the agent exactly how to run, compile, lint, and test the code (e.g.
Build command: npm run build,Test command: npm run test). - Code Style Preferences: State requirements explicitly (e.g. "Use TypeScript, enforce tailwind-merge, prefer clean vanilla CSS, preserve existing comments").
- Boundary Limits: Restrict tool execution permissions (e.g. "Do not install npm dependencies without checking first", "Do not alter base configuration files like tsconfig.json").
Hands-on: Core Package Locking
To prevent an AI agent from breaking core dependencies or modifying stable frameworks, write a strict boundary constraint block in your root constitution file:
# AI Agent Constraints ## CRITICAL CODEBOUNDS - NEVER modify files in `src/core/` unless explicitly requested. - DO NOT run npm installs or add new package dependencies without human approval. - Always check that `npm run test` compiles and passes before marking a task complete.
Constitution Check
Which of the following describes the most effective approach for system constitutions (like CLAUDE.md)?
Coding Challenge: Boundary Constraint Validator
Let's build a small rule validator utility in Python! Write a script that checks a system instruction string and raises an error or prints a warning if it does not contain the mandatory strict constraint block CRITICAL CODEBOUNDS.
- Define a multiline string named
constitution_textcontaining rules. - Write a check that validates if the substring
"CRITICAL CODEBOUNDS"is present. - If missing, print
"Warning: Missing strict codebounds block!". Otherwise, print"Validation Passed.". - Run your script and verify it handles both passing and failing constitutions.
Write this constraint scanner script in the workspace editor on the right!