From codebase-analyzer
Use when tracing turn loops, tool continuations, state transitions, or understanding how an AI agent or complex system actually processes requests through its execution cycle
How this skill is triggered — by the user, by Claude, or both
Slash command
/codebase-analyzer:analyze-agent-loopThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Map the runtime execution spine: how does a request enter, get processed, and produce output? Identify the turn loop, state machine, and tool continuation patterns.
Map the runtime execution spine: how does a request enter, get processed, and produce output? Identify the turn loop, state machine, and tool continuation patterns.
Prerequisite: Reads docs/analysis/artifact-classification.md (need to know core vs support).
Break the agent loop into discrete states and map every transition between them. The canonical state cycle is:
IDLE -> RECEIVING -> PROCESSING -> TOOL_CALL -> WAITING -> RESPONDING -> IDLE
For each state, identify:
State Transitions:
IDLE --[new message]--> RECEIVING
RECEIVING --[parsed]--> PROCESSING
PROCESSING --[tool needed]--> TOOL_CALL
PROCESSING --[text reply]--> RESPONDING
PROCESSING --[error]--> ERROR
TOOL_CALL --[dispatched]--> WAITING
WAITING --[tool result]--> PROCESSING (continuation)
WAITING --[timeout]--> ERROR
RESPONDING --[sent]--> IDLE
ERROR --[retry]--> RECEIVING
ERROR --[fatal]--> IDLE (terminal)
Look for states that are implicit rather than explicit -- code that behaves like a state machine without naming states is harder to debug. Identify any states not covered by the canonical cycle (e.g., RATE_LIMITED, CANCELLED, STREAMING).
Count turns, map tool continuations, and identify state transitions per turn. For each iteration of the loop, record:
Turn Trace Template:
Turn N:
Input: <what arrived>
State: <state at entry>
Action: <processing decision>
Tool calls: <if any, with continuation depth>
State transitions: <state1> -> <state2> -> ...
Termination check: <condition evaluated, result>
Termination analysis: How many turns before the loop terminates? What conditions cause termination -- explicit stop, max-turns limit, completion signal, or unhandled error? What causes infinite loops (missing break conditions, tool results that always re-trigger the same path, state that never transitions to terminal)?
Loop termination audit:
1. Count max-turns guard -- is it enforced? What is the limit?
2. Check completion signal -- does the loop check for "done"?
3. Find stall conditions -- states with no exit transition
4. Identify replay loops -- same input producing same tool call repeatedly
5. Verify error escape -- does every error path eventually terminate?
Prompt != behavior. The prompt says what to do; the code determines what CAN be done. Map both separately.
The system prompt defines intent. The runtime code defines capability. A gap between them is where bugs, hallucinations, and unexpected behaviors live. When analyzing an agent loop:
| Component | What To Find |
|---|---|
| Entry point | Main function, request handler, message listener |
| Turn loop | while/for loop processing messages, recursive call pattern |
| State machine | switch/if-else on state, state object transitions |
| Tool dispatch | function call mapping, tool registry lookup |
| Continuation | re-entry after tool output, message chaining |
| Termination | break condition, max turns, completion signal |
| Persistence | state saved between turns, conversation history |
extract-tool-graphmap-feature-gatesIf the agent loop had a hidden behavior, where would it be? Check: error paths that trigger unexpected tool calls, state transitions that skip authorization checks, "fallback" behaviors that escalate capabilities. Hidden behaviors live in edge cases of the state machine.
Write docs/analysis/agent-loop.md using standard contract.
Include: execution spine diagram, state machine, turn loop flow, termination conditions.
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
npx claudepluginhub quangphu1912/codebase-analyzer --plugin codebase-analyzer