Learn · Claude Code fundamentals · CCAR-F task 1.1

The agentic loop

Gather, act, observe, repeat: the loop behind every Claude Code session, and why you branch on stop_reason.

Watch the narrated lesson

Key ideas

Worked example: A correct loop in the Messages API

This is what Claude Code and the Agent SDK do for you. Note the single branch on stop_reason, the one message of tool results, and that any stop reason other than tool_use ends the loop instead of repeating it.

Exam traps

Official docs

Practise CCAR-F questions · Next lesson: Built-in tools