Skip to main content

Module claude

Module claude 

Source
Expand description

Claude-compatible agent runner.

Handles Claude, Kimi, and MiniMax agents. All three use the same claude binary (or a shell wrapper that sets ANTHROPIC_BASE_URL).

§CLI invocation

claude -p --model {model} \
  --permission-mode bypassPermissions \
  --output-format stream-json \
  --disallowedTools '...' \
  --append-system-prompt "{sys_file}" \
  < "{msg_file}"

§Output format (--output-format stream-json)

NDJSON event stream; the final event is always "type": "result":

{"type":"system","subtype":"init",...}
{"type":"assistant","message":{...}}
{"type":"tool_use","tool":{...}}
{"type":"tool_result","result":{...}}
{"type":"result","subtype":"success","is_error":false,"duration_ms":2006,"result":"...","usage":{"input_tokens":10,"output_tokens":78},"modelUsage":{...}}

Backward compatible with --output-format json (single JSON blob) — the parser finds the last "type":"result" line whether it is NDJSON or a pretty-printed single object.

§Kimi/MiniMax wrappers

Both are shell scripts that exec the claude binary with custom env:

exec env ANTHROPIC_BASE_URL=... ANTHROPIC_API_KEY=... claude "$@"

§Known error patterns

  • is_error: true with various message strings
  • “credit balance too low” — billing/auth
  • “overloaded” — capacity / rate limit (HTTP 529)
  • “rate limit” / “429” — standard rate limiting
  • “context_length_exceeded” — context overflow

Structs§

ClaudeRunner
Runner for Claude-compatible agents (Claude, Kimi, MiniMax).

Functions§

collect_assistant_messages_text
Concatenate text content from all type:assistant NDJSON messages in the stream. Used as a fallback when the type:result envelope text does not contain valid AgentResponse JSON but an earlier assistant turn might have emitted it.
find_claude_result
Extract a structured AgentResult from Claude/Kimi/MiniMax NDJSON output.
review_session_exited_mid_thought
True when the stream has no result envelope and ended on a thinking block or a tool call, so the model never produced a finished review decision
strip_tty_control_lines
Drop script tty junk: show-cursor (ESC[?25h) and ^D/backspace redraw lines