# windy3f3f3f3f/claude-code-from-scratch architecture

> Architecture diagram of the GitHub repository windy3f3f3f3f/claude-code-from-scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/windy3f3f3f3f/claude-code-from-scratch
- Repository: https://github.com/windy3f3f3f3f/claude-code-from-scratch

## Overview

Mini Claude Code is a learning-oriented coding agent, implemented in TypeScript and Python. Its main workflow is: a user submits a coding task through the CLI; the agent builds prompts and calls a model, checks permissions, executes requested tools, and returns results through the terminal. Sessions, context management, memory, skills, sub-agents, and MCP extend that loop. The graph emphasizes the TypeScript runtime and README-documented capabilities; several feature links are documented but their implementations were not sampled.

Main entry points: [`src/agent.ts`](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/agent.ts) (Agent loop), [`src/cli.ts`](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/cli.ts) (CLI and REPL), [`src/tools.ts`](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/tools.ts) (Permissions and tools), [`src/mcp.ts`](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/mcp.ts) (MCP integration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and interaction"]
  node_cli["CLI and REPL<br/>[cli.ts]"]
  node_terminal["Terminal UI<br/>[ui.ts]"]
  node_sessions[("Session persistence<br/>[session.ts]")]
end

subgraph group_agent["Agent orchestration"]
  node_agentloop["Agent loop<br/>[agent.ts]"]
  node_prompt["Prompt construction<br/>[prompt.ts]"]
  node_permissions["Permissions and tools<br/>[tools.ts]"]
  node_context["Context management<br/>[agent.ts]"]
  node_autonomy["Autonomy modes<br/>[autonomy.ts]"]
end

subgraph group_capabilities["Agent capabilities"]
  node_memory["Memory system<br/>[memory.ts]"]
  node_skills["Skills<br/>[skills.ts]"]
  node_subagents["Sub-agents<br/>[subagent.ts]"]
  node_mcp["MCP integration<br/>[mcp.ts]"]
end

subgraph group_integrations["External systems"]
  node_project[("Project files")]
  node_model(("Model API"))
  node_mcpservers(("MCP servers"))
end

node_user(("User"))

node_user -->|"submits task"| node_cli
node_cli -->|"starts agent"| node_agentloop
node_cli -->|"loads and saves"| node_sessions
node_cli -->|"displays interaction"| node_terminal
node_agentloop -->|"builds prompts"| node_prompt
node_agentloop -->|"sends requests"| node_model
node_model -->|"returns responses"| node_agentloop
node_agentloop -->|"checks and executes"| node_permissions
node_permissions -->|"reads and writes"| node_project
node_agentloop -->|"manages history"| node_context
node_agentloop -->|"evaluates goals"| node_autonomy
node_agentloop -->|"recalls and saves"| node_memory
node_agentloop -->|"discovers and invokes"| node_skills
node_agentloop -->|"delegates tasks"| node_subagents
node_agentloop -.->|"discovers and routes tools"| node_mcp
node_mcp -.->|"connects over stdio"| node_mcpservers
node_agentloop -->|"prints responses"| node_terminal

click node_cli "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/cli.ts"
click node_terminal "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/ui.ts"
click node_agentloop "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/agent.ts"
click node_prompt "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/prompt.ts"
click node_permissions "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/tools.ts"
click node_context "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/agent.ts"
click node_autonomy "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/autonomy.ts"
click node_sessions "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/session.ts"
click node_memory "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/memory.ts"
click node_skills "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/skills.ts"
click node_subagents "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/subagent.ts"
click node_mcp "https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/mcp.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_terminal,node_sessions,node_user toneBlue
class node_agentloop,node_prompt,node_permissions,node_context,node_autonomy toneAmber
class node_memory,node_skills,node_subagents,node_mcp toneMint
class node_project,node_model,node_mcpservers toneRose
```

## Components

### CLI and interaction

- [CLI and REPL](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/cli.ts): `src/cli.ts`
- [Terminal UI](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/ui.ts): `src/ui.ts`
- [Session persistence](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/session.ts): `src/session.ts`

### Agent orchestration

- [Agent loop](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/agent.ts): `src/agent.ts`
- [Prompt construction](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/prompt.ts): `src/prompt.ts`
- [Permissions and tools](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/tools.ts): `src/tools.ts`
- [Context management](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/agent.ts): `src/agent.ts`
- [Autonomy modes](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/autonomy.ts): `src/autonomy.ts`

### Agent capabilities

- [Memory system](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/memory.ts): `src/memory.ts`
- [Skills](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/skills.ts): `src/skills.ts`
- [Sub-agents](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/subagent.ts): `src/subagent.ts`
- [MCP integration](https://github.com/windy3f3f3f3f/claude-code-from-scratch/blob/main/src/mcp.ts): `src/mcp.ts`

### External systems

- **Project files**
- **Model API**
- **MCP servers**

### Other components

- **User**

## Connections

- User → CLI and REPL: submits task
- CLI and REPL → Agent loop: starts agent
- CLI and REPL → Session persistence: loads and saves
- CLI and REPL → Terminal UI: displays interaction
- Agent loop → Prompt construction: builds prompts
- Agent loop → Model API: sends requests
- Model API → Agent loop: returns responses
- Agent loop → Permissions and tools: checks and executes
- Permissions and tools → Project files: reads and writes
- Agent loop → Context management: manages history
- Agent loop → Autonomy modes: evaluates goals
- Agent loop → Memory system: recalls and saves
- Agent loop → Skills: discovers and invokes
- Agent loop → Sub-agents: delegates tasks
- Agent loop → MCP integration: discovers and routes tools
- MCP integration → MCP servers: connects over stdio
- Agent loop → Terminal UI: prints responses
