NEW: Claude Code Security — research preview

Agent Development Kit

5-layer model - understand the complete architecture

POPULARRead time: 15 min

Agent Development Kit: The 5-Layer Model

"Claude Code isn't a coding assistant. It's an agent platform."

Most people are using 10% of it.

The key is understanding the 5-layer composition model that powers everything.

Layer 1: CLAUDE.md — Memory Layer

Your agent's constitution.

Think of it as an employee onboarding document, not a novel. Keep it under 200 lines.

## Tech Stack
- Node.js 20
- TypeScript
- React 19
 
## Conventions
- Kebab-case filenames
- camelCase variables
- ESLint strict mode
 
## Architecture
- /src/app (Next.js App Router)
- /src/components (React)
- /src/lib (utilities)
 
## Security
- No .env in git
- API keys environment-only
- Rate limiting on all endpoints

What goes in CLAUDE.md:

  • Tech stack (not installation instructions)
  • Coding conventions (not tutorials)
  • Architecture overview (not detailed design)
  • Hard constraints (banned patterns, security rules)
  • Key file locations (not every file)

What belongs in Skills instead:

  • Multi-step workflows
  • Complex procedures
  • Decision trees
  • Testing strategies
  • Deployment procedures

CLAUDE.md is for facts you want in every session. Skills load on demand — only when you invoke them or Claude decides they're relevant. Auto memory (Layer 6) is what Claude writes for itself.


Layer 2: Skills — Knowledge Layer

Extend your agent with reusable knowledge modules.

Skills use the Agent Skills open standard (agentskills.io).

Skill Anatomy

---
name: "Database Migration"
description: "Safe schema migrations with rollback"
user-invocable: true
disable-model-invocation: false
allowed-tools: ["bash", "file"]
model: "sonnet"
effort: "high"
context: "fork"
hooks:
  - event: "post-tool-execution"
    pattern: "ALTER TABLE"
    action: "validate"
paths:
  - "db/migrations/**"
  - "prisma/schema.prisma"
---
 
# Database Migration Skill
 
Use this skill to create safe migrations...
 
## Usage
- /db-migrate "add users table"
- /db-migrate --rollback
 
## Behind the Scenes
\`\`\`bash
# Dynamic context injection
echo "Schema: $(cat prisma/schema.prisma | head -20)"
\`\`\`

Skill Frontmatter Fields

FieldTypePurpose
namestringSkill identifier
descriptionstringWhat it does
user-invocableboolCan user run it?
disable-model-invocationboolModel can't call it
allowed-toolsstring[]Tool whitelist
modelstringForce model (haiku/sonnet/opus)
effortstringTask difficulty (low/medium/high/max)
contextstringfork = subagent isolation
hooksobject[]Trigger on events
pathsstring[]File globs (scope)
shellobjectShell environment vars

Dynamic Context: Code Injection

$ARGUMENTS[0]          # First parameter
${CLAUDE_SESSION_ID}   # Current session UUID
${CLAUDE_SKILL_DIR}    # Skill directory path
 
!`git log -1 --oneline`  # Shell output injection

Skill Scope Priority

  1. Enterprise (global across org, managed policy)
  2. Personal (~/.claude/skills/)
  3. Project (.claude/skills/)
  4. Plugin (npm packages, plugin-name:skill-name namespace)

Skill directories are watched live — adding or editing a SKILL.md takes effect in the current session without restarting.

In monorepos, skills in nested .claude/skills/ directories are discovered automatically when Claude works with files in that subdirectory.


Layer 3: Hooks — Guardrail Layer

Hooks intercept Claude Code at specific points:

{
  "hooks": [
    {
      "event": "PreToolUse",
      "pattern": "bash.*rm.*-rf",
      "action": "ask"
    },
    {
      "event": "PostToolExecution",
      "pattern": "git.*commit",
      "action": "notify"
    }
  ]
}

Hook Events:

  • PreToolUse — Before shell command
  • PostToolExecution — After command runs
  • PreCommit — Git commit safety
  • PreFileDeletion — File deletion warning
  • MissingFile — File not found
  • Notification — Slack/webhook alerts

Layer 4: Subagents — Delegation Layer

Isolate context. Run agents in parallel.

---
context: fork    # Runs in isolated subagent
---
 
This skill always runs in a fresh context
with its own memory and filesystem scope.

Built-in Agent Types:

  • Explore agent (search codebases, summarize)
  • Plan agent (break tasks into steps)
  • General-purpose agent (default)

Parallel Execution:

/batch \
  "Implement auth module" \
  "Set up database migrations" \
  "Build API endpoints"

Running 3 agents simultaneously = 3x token cost but saves wall-clock time.


Layer 5: Plugins — Distribution Layer

Bundle and share skills as npm packages.

{
  "name": "@acme/claude-skills",
  "version": "1.0.0",
  "skills": {
    "db-migrate": "./skills/db-migrate.md",
    "deploy": "./skills/deploy.md"
  }
}

Install:

claude plugin add @acme/claude-skills

Bundled Skills (Pre-Loaded)

SkillCommandPurpose
Batch/batchParallel agents
Simplify/simplify3-agent code review
Debug/debugInteractive debugger
Loop/loopAgentic loop for complex tasks
Claude API/claude-apiAPI reference loader

Layer 6: Auto Memory — Learning Layer

Claude writes notes for itself across sessions — without you doing anything.

What Claude remembers:

  • Build commands it discovered
  • Debugging insights from your sessions
  • Architecture patterns specific to your project
  • Code style preferences it inferred

Storage: ~/.claude/projects/<project>/memory/MEMORY.md plus topic files (debugging.md, api-conventions.md, etc.).

The first 200 lines / 25KB of MEMORY.md load at every session start. Topic files load on demand.

# Browse and edit memory in a session
/memory
MechanismWritten byLoadedBest for
CLAUDE.mdYouEvery session (full)Team standards, constraints
Auto memoryClaudeEvery session (200 lines)Learned insights, project patterns
SkillsYouOn demandWorkflows, procedures

Putting It Together: A Real Example

Project Structure:
├── CLAUDE.md                    # Layer 1: Memory
├── .claude/
│   ├── skills/
│   │   ├── db-migrate.md       # Layer 2: Skills
│   │   └── deploy.md
│   ├── settings.json           # Layer 3: Hooks
│   └── .mcp.json              # MCP config
├── .git/
└── src/

User runs: claude "Add user authentication"

Agent process:

  1. Reads CLAUDE.md (constraints, tech stack)
  2. Checks hooks (pre-tool safety rules)
  3. Searches for relevant Skills
  4. Creates plan (ask for approval)
  5. Forks subagent if using isolation
  6. Executes with fallback to Layer 2, 3 constraints
  7. Logs via Hooks (Layer 3)

Composition Benefits

✅ Reusable knowledge (Skills)
✅ Safety guardrails (Hooks)
✅ Scalability (Plugins)
✅ Isolation (Subagents)
✅ Governance (CLAUDE.md)
✅ Persistent learning (Auto Memory)

Next: Explore Architecture for runtime details, or dive into Skills and Auto Memory for deep-dives.