
learn-claude-code: 12 Sessions From a While Loop to Multi-Agent Teams, Zero Frameworks
An agent is a while loop. That single sentence is the core thesis of learn-claude-code , a 23k-star project by shareAI-lab that reconstructs the internals of an AI coding agent like Claude Code from absolute zero. The starting point is literally one while loop and one bash tool. Source: learn-claude-code — shareAI-lab The Loop That Never Changes Session 01 defines an agent_loop function. Call the LLM, check if stop_reason is tool_use , execute the tools, append results to messages, call again. This loop survives all 12 sessions without a single modification. def agent_loop ( messages ): while True : response = client . messages . create ( model = MODEL , system = SYSTEM , messages = messages , tools = TOOLS , ) messages . append ({ " role " : " assistant " , " content " : response . content }) if response . stop_reason != " tool_use " : return results = [] for block in response . content : if block . type == " tool_use " : output = TOOL_HANDLERS [ block . name ]( ** block . input ) res
Continue reading on Dev.to Python
Opens in a new tab


