System Design Concepts

12 architectural patterns from Claude Code CLI — each explained with diagrams, source code, and AI-powered chat.

Architecture

Plugin Architecture

Plugin / Extension Pattern

How Claude Code supports 45+ built-in tools plus unlimited external tools (via MCP) using a single extensible interface.

2 source files
Concurrency

Streaming & Concurrent Execution

Concurrent Pool + State Machine

Managing parallel tool execution with result ordering guarantees while streaming progress to the UI in real time.

1 source file
Security

Permission Systems

Strategy Pattern + Rule Engine

Five-tier permission model combining glob rule matching, ML classification, and interactive prompting.

1 source file
Auth

OAuth Token Lifecycle

Proactive Refresh + Secure Storage

PKCE OAuth flow with proactive token refresh, OS keychain storage, and startup prefetch.

1 source file
Resilience

Rate Limiting & Exponential Backoff

Exponential Backoff + Source-Aware Retry

Smart retry logic that distinguishes foreground user queries from background tasks to avoid amplifying capacity issues.

1 source file
State

Immutable State Management

Single Source of Truth + Immutable Updates

Preventing UI flicker and bugs in a terminal app through deep immutability and append-only message logs.

1 source file
Patterns

Observer Pattern

Observer / Event Bus

Lifecycle hooks as a subprocess-based observer pattern — extensible without modifying core code.

1 source file
Patterns

Strategy Pattern

Strategy / Adapter Pattern

Swappable implementations for transports (MCP), sandboxes, and auth providers behind unified interfaces.

1 source file
Patterns

Factory Pattern

Factory / Registry Pattern

A central tool registry that produces Tool instances on demand — enabling dynamic loading and MCP tool injection.

1 source file
Security

Security Defense-in-Depth

Defense-in-Depth / Layered Security

Multiple independent security layers — AST analysis, SSRF guard, secret scanning, permissions, and sandboxing.

1 source file
Performance

Context Window Management

LLM-as-Compressor

Using Claude itself to summarize conversation history and extend sessions beyond the token limit.

1 source file
Performance

LRU Caching & Performance

LRU Cache / Memoization

File state caching, memoized selectors, and prompt caching to minimize redundant I/O and API costs.

1 source file