Here is how to build your first agentic loop with Claude Code:
1. Open your terminal. 2. Create an empty folder and move into it. 3. Run the following command:
************************* claude -p "Write fibonnacy(n) in a Python file. Write tests for it, including edge cases. Run pytest after every change. Don't stop until every test passes." \ --allowedTools "Read,Write,Edit,Bash(python3 -m pytest:*),Bash(pytest:*)"\ --max-turns 15 *************************
That's it. If you have Python and pytest installed on your system, Claude will implement the Fibonacci function and test it.
There are 3 things you need to know about this command:
First, it uses the -p flag to run Claude Code non-interactively. It takes a prompt, runs the full agent loop, prints the result, and exits.
Second, the --allowedTools flag pre-approves exactly what the agent can touch, so Claude doesn't need to ask you every time.
Third, the --max-turns flag caps the number of agentic turns the loop can run. When it hits the cap, the run exits with an error instead of grinding forever.
This is just a simple "Hello World"-type example to get you started.
The key on every loop is the verification step: how does the agent know it is done?
Coming up with the evaluation criteria is probably the most important step in building a loop. In this example, I'm asking Claude to write unit tests and use them to evaluate the code. This works for something simple, but you'll need a much more robust evaluation for anything more complex.
Something worth mentioning: building the verification step is where a ton of my time is going right now. The agent is writing the code, and the agent is verifying that the code (and the product) work as intended. My job has become defining what "works" looks like.


















