Building a Claude-like agentic system.
SaferSkills independently audited building-claude-from-scratch (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
A complete reproducible implementation of the 62 components that define Claude's thinking and agentic behavior, built on open source models and tested end to end on a real research paper reproduction task.
In practice, when building agentic systems, AI models are rarely the bottleneck anymore. The harness around them is. Anthropic spent two years building that harness for Claude, the orchestration code that picks the right tools and grades its work before declaring success.
This repository reproduces that harness from scratch on an open source model. Every one of the 62 components that define Claude's thinking approach is implemented in a single executable Jupyter notebook, applied to a real research paper reproduction task, and graded mechanically at the end.
The model came from training. The reproducibility came from architecture. This repository is that architecture, fully runnable.

The 62 components are distributed across 4 main principles:
| Principle | What It Does | Key Components |
|---|---|---|
| Cognition | Turns a chat completion into a reasoner | Thinking channels, compute adaptive allocation, self consistency, best of N verification |
| Orchestration | Decomposes hard tasks into solvable subgoals | Tree of thoughts, OODA subagents, plan and execute, master loop |
| Reliability | Turns a working agent into a deployable one | Architect editor splits, linter in the loop, self refine, cache aware prompts |
| Grounding and Trust | Earns the right to claim success | Sandboxed REPLs, real pytest verification, four tier memory, definition of done contracts |
The 62 components compose into 8 phases. Each phase has its own component diagram, its own section in the notebook, and its own dedicated discussion in the blog post.
Teaches the model to deliberate before it acts. Thinking channels, compute adaptive effort allocation, self consistency, best of N with verifier scoring, and budget forcing.

How thoughts compose into trajectories. Step back decomposition, tree of thoughts branching, OODA subagent dispatch, master loop, and sub agent output discipline that keeps parent context clean.

From plan to verifiable action. Plan and execute, ReAct, evaluator optimizer loops with feedback, Reflexion memory of past failures, and external feedback verification through real Python execution.

The hardening stack. Architect editor split for cost optimization, self refine convergence, linter in the loop with auto revert, adversarial self probing, and cache aware prompt ordering for 89 percent token cost reduction.

What makes Claude feel different. Thought signatures for reasoning continuity, coverage curves for compute optimal sampling, deliberative alignment where verifiers never see the chain of thought, soul document with values not rules, and bi temporal memory that lets the agent change its mind without contradicting itself.

The layer that knows what kind of problem it is solving. Problem type classification, definition of done contract, persistent task DAG with SQLite backed state, execution trace as first class artifact, and selective rollback as graph mutation when failures happen.

Where the agent earns the right to claim success. Persistent sandboxed REPL with Docker, filesystem as state with git checkpoints, executable spec layer that compiles contracts to pytest, four tier memory with bge-m3 embeddings, and the MCP compatible tool registry.

All eight phases compose into one runnable agent. Five specialised subagents (Paper Analyzer, Code Implementer, Experimenter, Verifier, Report Writer), the boring master loop that orchestrates them, the budget guard that meters every step, and the final verdict produced by mechanical pytest evaluation.

Toy benchmarks do not stress an agentic harness. Reproducing a peer reviewed research paper does. Every component in this repository has to contribute to producing a number that matches a published result, and the spec layer grades us mechanically at the end.
We picked Freitas et al. 2025, "A statistical model for forecasting probabilistic epidemic bands for dengue cases in Brazil" (Infectious Disease Modelling, doi:10.1016/j.idm.2025.07.014). The paper fits a Bayesian hierarchical model on 14 years of DATASUS dengue data and forecasts the 2022 to 2023 epidemic season. Their reported national 75th percentile estimate is 1,405,191 cases. Our agent's job is to reproduce this number within 5 percent on its own.
Why this paper. It has clean math, a public dataset, a single hard numerical target, and a real Bayesian inference step. It is exactly the kind of task a researcher would normally hand to Claude. Read the paper. Write the code. Fit the model. Validate the result. Write the report.
| Resource | Link |
|---|---|
| Paper | doi.org/10.1016/j.idm.2025.07.014 |
| Dataset | DATASUS public dengue surveillance, 487,239 weekly observations across 5,570 municipalities (2010 to 2024) |
Every component is implemented in claude_from_scratch.ipynb and grouped by phase. Below is the full mapping.
Extended thinking · Interleaved thinking · Static thinking budgets · Adaptive thinking budgets · Test time compute scaling · Self consistency · Best of N with verifier · Budget forcing
Step back prompting · Least to most decomposition · Tree of thoughts · OODA loop subagent · Master agent loop · Single threaded loop · Orchestrator worker pattern · Sub agent output discipline
Plan and execute · LLM compiler · Evaluator optimizer · ReAct · Reflexion · CRITIC · Mixture of agents · Verifier asymmetry
Self refine · Verifier guided search · External feedback verification · Tool description self improvement · Adversarial self probing · Architect editor split · Linter in the loop · Tool result compaction · Cache aware prompt ordering · Sample diversity without temperature · Don't make the model count · Empty tool result trap · Pause turn pattern
Thought signatures · Goldilocks altitude · Token variance · Compute optimal allocation · Coverage curves · Soul document · Deliberative alignment · Don't hold back effect · Effort knob · Delegation cost · Tool choice strictness · Process isolation · Bi temporal memory
Problem type classification · Cost bounded branching · Execution trace as artifact · Definition of done contract · Task DAG with persistent state · Node level retry policies · Selective rollback · Replan as graph mutation
Persistent sandboxed REPL · Real environment in verifier · Filesystem as state with git · Executable spec layer · plus four tier memory and MCP compatible tool registry
git clone https://github.com/FareedKhan-dev/building-claude-from-scratch.git
cd building-claude-from-scratch
pip install -r requirements.txtSet your API key as an environment variable. The notebook works with any OpenAI compatible endpoint.
export DEEPSEEK_API_KEY="sk-..."For local models served through vLLM or Ollama, point the client base URL accordingly inside the notebook setup cell.
jupyter notebook claude_from_scratch.ipynbThe notebook is self contained. Run cells in order from top to bottom. Each phase builds on the previous one, and the final phase (Phase 8) executes the full end to end reproduction run.
The notebook follows the same 8 phase structure as the blog post. Each phase has theory cells that explain the pattern and connect it to how Claude actually implements it, followed by code cells that build the component piece by piece, followed by execution cells that show the real output.
| Section | What You Will Learn |
|---|---|
| Phase 1 | How a bare LLM differs from a deliberating reasoner, and how to add the cognitive substrate |
| Phase 2 | How to decompose hard problems and delegate to isolated sub agents without context pollution |
| Phase 3 | How to ground model output in real tool execution with self correction loops |
| Phase 4 | How to harden raw output through editorial discipline, static checks, and adversarial probing |
| Phase 5 | The frontier patterns that make Claude feel different, applied to an open source backend |
| Phase 6 | How to make execution durable across crashes through SQLite backed task DAGs |
| Phase 7 | How to build the trust gate that grades work mechanically through pytest |
| Phase 8 | How everything composes into one end to end agent that reproduces a real research paper |
Every numerical claim in the notebook is real arithmetic from the actual run. Nothing is faked. Nothing is hardcoded. The verdict at the end is whatever pytest produces against the contract.
| Audience | What You Get |
|---|---|
| Developers building agentic systems | A complete working blueprint for production grade agent harnesses you can adapt to any domain |
| Junior engineers | Step by step exposure to every pattern Anthropic uses, with theory paragraphs that explain the why behind each one |
| Senior engineers and architects | A reference implementation showing how 62 individual patterns compose into one coherent system |
| Researchers | A reproducible case study of how open source models can close most of the architectural gap with frontier systems on real research tasks |
| Anyone curious about how Claude works | The full architecture made transparent, runnable, and grounded in real published patterns from Anthropic, OpenAI, and DeepMind |
| Metric | Value |
|---|---|
| Paper's reported national p75 | 1,405,191 cases |
| Agent's reproduced p75 | 1,302,540 cases |
| Relative deviation | 7.30 percent |
| Verdict from spec layer | partial |
| Total cost | $0.0036 |
| Total wall clock time | 198.6 seconds |
| Cost vs bare model baseline | 88x more expensive, infinitely more verifiable |
| Architectural gap closed vs Claude | approximately 70 percent |
The 7.30 percent deviation lands honestly in the partial band. The agent did the science correctly. The Laplace approximation tax (R-INLA was unavailable in the sandbox) accounts for the deviation, exactly as the agent predicted in Phase 2's tree of thoughts branching. To push the run from partial to reproduces, switch to PyMC NUTS for inference or install R-INLA in the sandbox.
building-claude-from-scratch/
│
├── claude_from_scratch.ipynb # The complete implementation, all 62 components
├── requirements.txt # All Python dependencies
├── README.md # This file
│
└── workspace/ # Created at runtime
├── agent_code/ # Files the agent writes during the run
├── data/ # The dengue dataset
├── reports/ # Final REPORT.md and visualizations
├── memory/ # ChromaDB vector store
└── dag.db # SQLite backed persistent stateEverything lives in one notebook by design. The notebook is the documentation. The notebook is the test suite. The notebook is the proof.
The complete walkthrough with theory, code, and discussion of every output is published on Medium.
The blog covers each of the 8 phases in detail, explains the reasoning behind every architectural decision, and connects every pattern to how Claude actually implements it internally. It is roughly 78 minutes of reading and pairs directly with running the notebook side by side.
If you use this repository in your work, please cite the companion blog post and the original Freitas et al. paper.
@article{freitas2025dengue,
title = {A statistical model for forecasting probabilistic epidemic bands for dengue cases in Brazil},
author = {Freitas et al.},
journal = {Infectious Disease Modelling},
year = {2025},
doi = {10.1016/j.idm.2025.07.014}
}The 62 patterns implemented here are drawn from published research by Anthropic (extended thinking, Constitutional AI, MCP, Claude Code architecture), OpenAI (deliberative alignment, scaling test time compute), DeepMind (large language monkeys), and the broader agent research community (Tree of Thoughts, ReAct, Reflexion, Self Refine, Plan and Execute, Architect Editor, Mixture of Agents, Best of N, Self Consistency).
MIT License. See LICENSE for details.
<div align="center">
Built by [Fareed Khan](https://github.com/FareedKhan-dev)
If this repository was useful to you, please consider giving it a star ⭐
</div>
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.