Available now — 1st Edition 2026

Claw Code
Architecture of an
AI Agent Harness

How does an AI agent harness really work? 14 chapters deep-dive into the architecture of Claude Code — from the bootstrap phase to token routing.

Free EPUB Download FREE How-To Guide Table of Contents
14Chapters
6.4k+Lines
207Commands
184Tools
$0Cost

The architecture you will understand

Claw Code follows a clear three-layer model. This book explains each layer line by line — with code examples, ASCII diagrams, and data flow analysis.

Mirror Layer

207 commands and 184 tools as JSON snapshots. LRU-cached, immutable, typed.

Orchestration Layer

Token-based prompt routing, session bootstrapping, multi-turn loops with budget control.

Infrastructure Layer

7-phase bootstrap, trust gating, prefetch operations, JSON session persistence.

Permission System

Deny-list-based access control with name and prefix matching.

29 Subsystems

From utils (564 modules) to voice (1 module) — each documented with JSON metadata.

Ethics & Law

Clean-room reimplementation, copyleft debate, the questions that matter.

src/runtime.py
class PortRuntime:
    def route_prompt(self, prompt: str, limit: int = 5):
        # Tokenization
        tokens = {t.lower() for t in
            prompt.replace('/', ' ')
                  .replace('-', ' ').split() if t}

        # Scoring: 207 commands + 184 tools
        by_kind = {
            'command': self._collect_matches(
                tokens, PORTED_COMMANDS, 'command'),
            'tool': self._collect_matches(
                tokens, PORTED_TOOLS, 'tool'),
        }
        return self._select(by_kind, limit)

14 Chapters. No filler.

Each chapter goes deep into a module — with source code, sequence diagrams, and architectural analysis.

01
Introduction & Background
The night of March 31, 2026, OmX orchestration, 25B tokens
Context
02
Ethics & Law of AI Reimplementation
Hong Minhee's essay, chardet case, copyleft debate
Ethics
03
High-Level Architecture
Three-layer model, dependency graph, data flow diagrams
Architecture
04
The CLI Entry Point
main.py in detail, all 24 commands, argparse, dispatch
Code
05
Data Models & Type System
Frozen dataclasses, PortingModule, value objects
Code
06
Command & Tool Catalog
JSON snapshots, LRU caching, filtering, permissions
Code
07
The Runtime Environment
Token scoring, routing algorithm, bootstrap_session
Core
08
The Query Engine
QueryEnginePort, streaming, token budgeting
Core
09
Session Management
StoredSession, TranscriptStore, persistence
Code
10
Setup & Bootstrap
7 phases, prefetch, trust gating
Code
11
Execution Layer
ExecutionRegistry, shim execution, remote modes
Code
12
Subsystem Architecture
29 packages, JSON metadata, 1,372 original modules
Architecture
13
Quality Assurance
Parity audit, 49 tests without mocking
Testing
14
Summary & Outlook
Rust port, design patterns, future directions
Outlook

How-To Guide — 10 Steps to Understanding

Step by step through the architecture. From setup to building your own AI system.

Written by a practitioner

BA

Belkis Aslani

Technical author and software architect with a deep interest in AI agent systems, harness engineering, and the question of how intelligent systems wire their tools.

Freiberg am Neckar, Germany Belkis.aslani@gmail.com 1st Edition, April 2026

Ready to understand the architecture?

14 chapters. 6,400+ lines. Every module explained. Completely free.

$0
No catch. No newsletter. Just download.
14 deep chapters EPUB-3 format Code examples ASCII diagrams Instant download No registration

EPUB 3 — Kindle · Apple Books · Google Play · Tolino · Kobo