Your Claude session didn't have to die that fast. You just let it!
For tools you can specify if there is a maximum number of invocations allowed. This sample shows a tool that can only be invoked once. print(f"Number of tool calls ...