Concepts
Use the “Sign” metaphor to explain instruction tuning, and split the work between permanent context (PROMPT.md / AGENTS.md) and one-off prompts.
Concepts
Use the “Sign” metaphor to explain instruction tuning, and split the work between permanent context (PROMPT.md / AGENTS.md) and one-off prompts.
Design
Design instruction layers across mission / norms / pitfalls / examples, and decide which failure pattern each layer absorbs.
Implementation
Harden the project’s PROMPT.md by encoding one or two recurring mistakes as explicit anti-patterns, and automate the failure → instruction-update cycle.
Operations
Monitor instruction drift and propose a quarterly housekeeping routine that re-reviews, rewrites, and prunes instructions.
In Week 5 we learned how to keep context clean — auto-compaction, fresh context, state files. But even with clean context, if the agent keeps making the same mistakes, it’s all for nothing.
The core question this week: Can we correct agent behavior without changing model weights?
The answer is “instruction tuning” — correcting behavior by changing the environment (the instruction file) rather than the model. If Week 4’s Ralph loop AGENTS.md (cumulative learning) was passive record-keeping, this week’s PROMPT.md/CLAUDE.md tuning is active constraint design.
When we move to Week 7 (multi-agent), each agent will need its own PROMPT.md and permissions. Before that, we master the techniques for precisely controlling a single agent’s behavior.
When an agent makes recurring mistakes in the Ralph Loop, we correct its behavior by adding specific, deterministic instructions to PROMPT.md — without retraining model weights.
# [Permanent Constraints — Never Ignore]
## ⚠️ Known Pitfalls (Instructional Tuning)
### 1. Do not call non-existent functions- `utils.parse_json()` does not exist in this project- Always use `json.loads()` directly- Added: 2026-04-02 (recurring error at loop #47)
### 2. Do not commit without tests- `pytest tests/ -q` must pass before any `git commit`- CI will auto-rollback on failure
### 3. Type hints are mandatory- All functions must include Python type hints- `def add(a, b):` → `def add(a: int, b: int) -> int:`
---
# [Current Task]...GitHub Blog’s analysis of 2,500 open-source repositories (2026) and ETH Zurich’s AGENTbench research empirically identified the success factors and anti-patterns of instruction files.
pnpm test --coverage) at the top of the filedef add(a: int, b: int) -> int: is more effective than “write in a type-safe manner”| Tier | Meaning | Examples |
|---|---|---|
| Always Do | Execute every time without fail | ”Run pytest before committing”, “Type hints mandatory” |
| Ask First | Request confirmation before executing | ”Confirm with a human before DB schema changes”, “Confirm before modifying external API keys” |
| Never Do | Absolutely prohibited | ”Never commit .env files”, “Never push directly to main” |
CLAUDE.md is injected into the system prompt every session and every turn. Therefore there is a token budget:
Pruning test: For each line, ask “Would Claude make a mistake without this?” If not, delete it.
Include: Build/test commands, non-standard coding conventions, architecture decisions, prohibited lists Exclude: Standard language rules (handled by linters), frequently changing information, long tutorials
Skills are the solution for staying under 200 lines while still leveraging domain knowledge:
| Storage | Load Time | Purpose |
|---|---|---|
CLAUDE.md | Automatic every session | Project-wide rules (under 200 lines) |
.claude/skills/*.md | On-demand for relevant tasks | Domain-specific knowledge |
Example: API conventions, deployment procedures, DB migration rules don’t need to be loaded every time. Placing them in .claude/skills/ means they load only when needed — saving tokens while making specialized knowledge available.
SkillReducer research (arXiv:2603.29919) found a “less-is-more” effect: compressing tool descriptions by 48% actually improved quality by 2.8%. Reducing information helps the agent focus on what matters.
| Metric | Measurement Method |
|---|---|
| Recurring error rate | Number of identical error occurrences / total loop count |
| Average loop count | Number of loops required to complete a task |
| Context efficiency | Ratio of tokens wasted on unnecessary exploration |
Adding constraints to PROMPT.md is like installing custom-made signs. In contrast, Claude Code’s Output Styles are pre-installed mode switches built into the agent. They change behavior patterns at zero configuration cost.
The key insight: output styles change the cognitive mode, not just the tone. Given the same task, the agent’s approach to the problem itself changes depending on the style.
claude --output-style explanatory "Improve error handling in this function"The agent modifies code while explaining why it makes each change. Reasoning is already embedded in the PR, so reviewers only need to verify the decisions.
Best for: Team onboarding, junior engineers working in unfamiliar codebases, reducing code review turnaround
claude --output-style learning "Improve error handling in this function"Instead of making changes directly, the agent guides step by step, encouraging the learner to make the changes themselves. Coaching mode.
Best for: Educational purposes, lab exercises where students need to understand the principles
claude --output-style concise "Improve error handling in this function"Outputs code changes with minimal explanation. For experienced developers who just need results fast.
Best for: Repetitive tasks, lint fixes, applying well-known patterns
Boris Cherny’s team sets Explanatory as the default when junior engineers work in unfamiliar services. The result: PR review time dropped — reasoning arrives attached to the code, so reviewers no longer need to reconstruct the decision chain.
If output styles change the direction, effort levels adjust the depth.
| Level | Use Case | Cost | Example |
|---|---|---|---|
low | Simple lookups, type checks | Minimal | claude --effort low "Return type of this function?" |
medium | General code changes | Moderate | claude --effort medium "Add tests" |
high | Architecture design, complex debugging | High | claude --effort high "Design async refactoring" |
max | Maximum reasoning depth (supported models only) | Maximum (10x+) | claude --effort max "Security vulnerability analysis" |
Practical effort level use in Ralph loops: start with low in early iterations (exploration phase), then switch to high for core implementation — this optimizes token cost across the loop.
When the built-in styles (Explanatory/Learning/Concise) are insufficient, you can create a custom style:
# Create a new custom styleclaude /output-style:newIn the generated Markdown file’s frontmatter, keep-coding-instructions: true/false controls whether existing coding instructions are preserved or fully replaced. This is a deeper level of instruction tuning than PROMPT.md — it replaces the coding-related portion of the system prompt itself.
| Aspect | PROMPT.md Instruction Tuning | Output Style + Effort Level |
|---|---|---|
| Setup cost | High — error analysis → writing → verification | Zero — a single CLI flag |
| Customization | Unlimited — free-text project constraints | Limited — choose from preset list |
| Persistence | Permanent — written to file, git-tracked | Per-session — must specify each time |
| Sign metaphor | Custom-made signs installed on site | Factory-installed mode switches |
| Best for | Project-specific recurring error correction | General behavior pattern changes |
CLAUDE.md is advisory — it is followed roughly 80% of the time. For 100% enforcement, use Hooks.
Hooks are an automation mechanism that triggers shell commands / HTTP / LLM judgment on tool calls and session events. They are defined in ~/.claude/settings.json or the project’s .claude/settings.json.
| Type | Behavior | Use Case |
|---|---|---|
| command | Execute a shell command | Auto-format, lint check, log recording |
| http | HTTP endpoint POST | External service notification, CI trigger |
| prompt | Delegate judgment to LLM (Haiku) | Automatically judge “task completion” |
| agent | Subagent reads files/runs commands | Complex verification like “did tests pass” |
{ "hooks": { "PostToolUse": [{ "matcher": "Write", "command": "npx prettier --write $CLAUDE_FILE_PATH" }] }}This Hook runs Prettier automatically every time Claude writes a file. It is 100% reliable compared to writing “follow Prettier format” in CLAUDE.md.
{ "hooks": { "Stop": [{ "type": "prompt", "prompt": "Are all tasks complete? Check fix_plan.md for any incomplete items.", "model": "haiku" }] }}The prompt type Hook delegates judgment to the Haiku model. If it returns "ok": false, the agent continues working. This is the key pattern for automating the manual verification step in the Ralph loop.
Instruction files are a common pattern across all AI coding tools, but the implementation differs per tool:
| Tool | File | Hierarchy | Notable Features |
|---|---|---|---|
| Claude Code | CLAUDE.md | 5-level + Skills | @import, advisory (~80%), supplemented by Hooks |
| Cursor | .cursor/rules/ | Directory-based | Migrated from .cursorrules, glob pattern matching |
| Windsurf | .windsurf/rules/ | Directory-based | Cascade engine auto-detects context |
| Codex CLI | AGENTS.md | Tool-neutral | 60,000+ repo adoption, 25+ agent compatible |
| GitHub Copilot | .github/copilot-instructions.md | Single file | Combined with VS Code 3-tier memory |
pytest execution via PreToolUse: Bash(git commit*)? Which is more effective, and why?Error Pattern Analysis
Analyze execution logs from the previous lab using log_analyzer.py (see Lab 06) to extract the top 5 recurring errors.
3-Tier Boundary Design
Classify the extracted errors into Always Do / Ask First / Never Do, and add a structured instruction section to PROMPT.md.
Hook Configuration
Implement one of the Never Do items as a PreToolUse Hook to guarantee 100% enforcement. Add it to settings.json.
A/B Testing
Run the same task before and after adding instructions, comparing loop counts, token usage, and recurring error rate. Use ab_test.py from Lab 06.
Connect to Lab 06
Use the experimental results above to complete the 4 requirements in Lab 06 (analysis report, PROMPT.md, comparison experiment, graph).
Submission deadline: 2026-04-14 23:59
Requirements:
PROMPT.md (instruction section + Always Do / Never Do structure).claude/skills/ for on-demand loading. The less-is-more effect from SkillReducer