Skip to content

fix(detection): support list-format JSON output from Claude Code CLI … - #134

Merged
barisozbas merged 1 commit into
uber:mainfrom
yazeedallabadi24:fix/claude-cli-2.1-json-array-compat
Sep 22, 2026
Merged

barisozbas merged 1 commit into
uber:mainfrom
yazeedallabadi24:fix/claude-cli-2.1-json-array-compat

Conversation

@yazeedallabadi24

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related issue:
N/A

What changed?
Updated _invoke_claude_reasoning and _extract_mcp_tool_usage in Detection/guardrail/adr_agent/adr_baseline.py to handle list/array formatted JSON outputs from Claude Code CLI. When --output-format json yields an event array, the parser extracts the entry with type: result (falling back to the last element if absent).

Why?
Modern Claude Code CLI versions (2.1+, e.g. v2.1.274) output a stream of JSON events formatted as an array [{"type": "system", ...}, ..., {"type": "result", ...}] rather than a single top-level dictionary. Previously, json.loads(stdout) produced a list, triggering an unhandled 'list' object has no attribute 'get' exception.

How did you test it?

  1. Live CLI Verification: Tested against Claude Code CLI v2.1.274, confirming both _invoke_claude_reasoning and _extract_mcp_tool_usage successfully parse the event list to extract reasoning verdicts and session IDs.
  2. Backward Compatibility: Verified that standard dictionary outputs (from earlier CLI versions) remain unaffected.
  3. Detection Test Suite: Ran uv run pytest tests/ in Detection/ — all 165 tests passed (including all 63 in test_adr_baseline.py).
  4. Sensor Test Suite: Ran uv run pytest tests/ in Sensor/ — all 287 tests passed.

Potential risks
None. Single-dict responses bypass the list handler and execute existing behavior unchanged.

@CLAassistant

CLAassistant commented Sep 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@barisozbas barisozbas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@barisozbas
barisozbas merged commit 1c8ecd6 into uber:main Sep 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants