Skip to main content

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

PropertyValue
FileCLAUDE.md (project root)
LoadingAlways (injected at session start)
Token cost~500 tokens
ProtectionLocked 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

PrincipleHow applied
LeanPointers to specs, not full content
StableRarely changes — locked by hook
Identity-focusedAnswers "who am I, what do I do?"
Boot-focusedAnswers "what do I do first?"

Rules

Location and loading

PropertyValue
Directory.claude/rules/
LoadingAlways (all .md files auto-loaded)
Total token cost~2,000 tokens
Count8 rule files

Rule files

FilePurposeToken cost
company-constitution.md14 sections of core behavior~400
agent-intelligence-protocol.md8 mandatory protocols~350
cost-awareness.mdEngine and token discipline~200
tech-freshness.mdPerishable knowledge defense~200
ub-governance.mdKnowledge management standards~250
gsta-alignment.mdStrategic alignment format~150
compaction-recovery-protocol.mdMemory cliff defense~150
glossary.mdTerm definitions and pointers~300

Rule design guidelines

GuidelineWhy
Keep rules behavioral, not proceduralProcedures go in skills (L3)
Each rule under 500 tokensAll rules loaded every session
Use pointers to UB for detailsRules stay lean
No hardcoded dates or versionsUse "current" or "latest"
No duplication across rulesSingle source per concept

Rule vs skill decision

QuestionAnswer
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

HookTriggerCommon uses
SessionStartNew session beginsInject timestamp, strategic anchor, agent intelligence
PreToolUseBefore any tool callGate operations, protect files, validate inputs
PostToolUseAfter any tool callLog 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 caseImplementation
Protect CLAUDE.md from editsCheck if target file is CLAUDE.md, block if not authorized
Validate dangerous commandsCheck for destructive shell commands
Log tool usageRecord which tools are called

PostToolUse hook

Reacts to completed operations:

Use caseImplementation
Log ingestion resultsRecord entry IDs after ingest_fragment
Track WO transitionsLog state changes
Notify on errorsSend alerts on failures

How they work together

Loading order

  1. System prompt (Claude's base behavior)
  2. CLAUDE.md (L1 — identity and boot)
  3. Rules (L2 — behavioral standards)
  4. SessionStart hook output (event-driven context)
  5. 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

PageRelationship
Prompt Engineering OverviewHigh-level concepts
Skills OverviewL3 skill reference
Skills in CLAUDE.mdHow skills integrate
Context WindowsToken budget