CLAUDE.md + Rules + Hooks
Benchmarked against: Anthropic — Console Prompting Tools Architecture: Three-layer agent configuration Location:
CLAUDE.md(root),.claude/rules/(rules),.claude/settings.json(hooks)
This page details each component of SuperPortia's prompt engineering stack — how they work individually and together.
CLAUDE.md
Location and loading
| Property | Value |
|---|---|
| File | CLAUDE.md (project root) |
| Loading | Always (injected at session start) |
| Token cost | ~500 tokens |
| Protection | Locked by PreToolUse hook (Captain authorization required to edit) |
Structure
# SuperPortia — Agent Boot Config
## Identity
Who you are, who the Captain is.
## Watch Rule
Timestamp every reply with Taipei time.
## Boot Sequence
1. Read hook output
2. Ask Captain what to work on
## Pre-Flight Check
3D scoring reference (pointer to UB entry).
## Engineering Governance
Pointer to EGS spec.
## Information Retrieval
Mandatory search flow: UB first, delegate, ingest.
## Version Control
Commit conventions.
## Terminology
Pointer to glossary.
## Communication
Behavioral guidance.
Design principles
| Principle | How applied |
|---|---|
| Lean | Pointers to specs, not full content |
| Stable | Rarely changes — locked by hook |
| Identity-focused | Answers "who am I, what do I do?" |
| Boot-focused | Answers "what do I do first?" |
Rules
Location and loading
| Property | Value |
|---|---|
| Directory | .claude/rules/ |
| Loading | Always (all .md files auto-loaded) |
| Total token cost | ~2,000 tokens |
| Count | 8 rule files |
Rule files
| File | Purpose | Token cost |
|---|---|---|
company-constitution.md | 14 sections of core behavior | ~400 |
agent-intelligence-protocol.md | 8 mandatory protocols | ~350 |
cost-awareness.md | Engine and token discipline | ~200 |
tech-freshness.md | Perishable knowledge defense | ~200 |
ub-governance.md | Knowledge management standards | ~250 |
gsta-alignment.md | Strategic alignment format | ~150 |
compaction-recovery-protocol.md | Memory cliff defense | ~150 |
glossary.md | Term definitions and pointers | ~300 |
Rule design guidelines
| Guideline | Why |
|---|---|
| Keep rules behavioral, not procedural | Procedures go in skills (L3) |
| Each rule under 500 tokens | All rules loaded every session |
| Use pointers to UB for details | Rules stay lean |
| No hardcoded dates or versions | Use "current" or "latest" |
| No duplication across rules | Single source per concept |
Rule vs skill decision
| Question | Answer |
|---|---|
| Must every agent always know this? | Rule |
| Is it a specific step-by-step procedure? | Skill |
| Does it shape all behavior? | Rule |
| Is it invoked by command? | Skill |
| Would it waste tokens if unused? | Skill |
Hooks
Location and configuration
Hooks are configured in .claude/settings.json:
{
"hooks": {
"SessionStart": [...],
"PreToolUse": [...],
"PostToolUse": [...]
}
}
Hook types
| Hook | Trigger | Common uses |
|---|---|---|
| SessionStart | New session begins | Inject timestamp, strategic anchor, agent intelligence |
| PreToolUse | Before any tool call | Gate operations, protect files, validate inputs |
| PostToolUse | After any tool call | Log results, trigger follow-up actions |
SessionStart hook
The most important hook — sets the agent's initial context:
#!/bin/bash
# .claude/hooks/session-start.sh
# Inject current Taipei time
echo "$(TZ='Asia/Taipei' date '+%Y-%m-%d %H:%M') (Taipei)"
# Strategic anchor (survives compaction)
echo "STRATEGIC ANCHOR"
echo " Project: SS1 | Role: Chief Engineer"
# Pre-Flight Check reminder
echo "Pre-Flight Check active — 30s self-check before non-trivial tasks"
PreToolUse hook
Gates specific operations:
| Use case | Implementation |
|---|---|
| Protect CLAUDE.md from edits | Check if target file is CLAUDE.md, block if not authorized |
| Validate dangerous commands | Check for destructive shell commands |
| Log tool usage | Record which tools are called |
PostToolUse hook
Reacts to completed operations:
| Use case | Implementation |
|---|---|
| Log ingestion results | Record entry IDs after ingest_fragment |
| Track WO transitions | Log state changes |
| Notify on errors | Send alerts on failures |
How they work together
Loading order
- System prompt (Claude's base behavior)
- CLAUDE.md (L1 — identity and boot)
- Rules (L2 — behavioral standards)
- SessionStart hook output (event-driven context)
- Skills (L3 — on demand, when user invokes
/command)
Authoring guidelines
For CLAUDE.md
- Keep under 500 tokens
- Only pointers, never full procedures
- Lock with PreToolUse hook to prevent accidental edits
- Update rarely — version changes go in changelog
For Rules
- One concept per file
- Under 500 tokens per file
- Use tables for structured information
- Include "Go Deeper" pointers to UB entries
- No procedure steps (those go in skills)
For Hooks
- Keep scripts fast (under 1 second)
- Output text is injected into agent context (costs tokens)
- Test hook output for token efficiency
- Use environment variables for ship-specific values
Related pages
| Page | Relationship |
|---|---|
| Prompt Engineering Overview | High-level concepts |
| Skills Overview | L3 skill reference |
| Skills in CLAUDE.md | How skills integrate |
| Context Windows | Token budget |