There are two parts to this README. The first part is the README made by CodeCrafters when I started the project. The second part is my README made using this project! (only difference in first part is markdown header level) I completed this challenge when it was in the early access stage.
This is a starting point for Python solutions to the "Build Your own Claude Code" Challenge.
Claude Code is an AI coding assistant that uses Large Language Models (LLMs) to understand code and perform actions through tool calls. In this challenge, you'll build your own Claude Code from scratch by implementing an LLM-powered coding assistant.
Along the way you'll learn about HTTP RESTful APIs, OpenAI-compatible tool calling, agent loop, and how to integrate multiple tools into an AI assistant.
Note: If you're viewing this repo on GitHub, head over to codecrafters.io to try the challenge.
The entry point for your claude-code implementation is in app/main.py. Study
and uncomment the relevant code, and submit to pass the first stage:
codecrafters submitNote: This section is for stages 2 and beyond.
- Ensure you have
uvinstalled locally. - Run
./your_program.shto run your program, which is implemented inapp/main.py. - Run
codecrafters submitto submit your solution to CodeCrafters. Test output will be streamed to your terminal.
This script is a CLI-based AI agent that provides an interactive chat interface with file system and shell capabilities. It uses an OpenAI-compatible API to create a conversation loop where the AI can call tools to read files, write files, and execute shell commands.
-
Command-line Interface: Uses
argparseto accept a required-pargument for the initial user prompt. -
OpenAI Integration: Configures an OpenAI client using settings from
app.config(specificallyACTIVE_PROVIDER, api_key, base_url, and model). -
Tool Integration: The AI has access to three tools:
- Read: Reads and returns the contents of a specified file
- Write: Writes content to a specified file
- Bash: Executes a shell command and returns the output (stdout or stderr)
-
Conversation Loop:
- Starts with the user's initial prompt
- Sends the conversation to the AI
- If the AI calls a tool, the script executes it and adds the result back to the conversation
- Continues looping until the AI provides a final response without tool calls
- Prints the final AI response
-
Provider Support: Includes special logging for Ollama and OpenRouter providers.
- The script parses the command-line argument to get the user's initial prompt.
- It creates an OpenAI client with the configured provider.
- It enters a loop where it:
- Calls the AI with the current conversation history and available tools
- Checks if the AI response includes tool calls
- Executes each tool call (Read/Write/Bash) and appends the result as a "tool" message
- Continues the loop until no more tool calls are made
- Finally, it prints the AI's content-only response to the console.
This allows users to interact with an AI assistant that can directly manipulate files and execute commands, making it useful for tasks like code review, file editing, system administration, and automated workflows - all through natural language prompts.