Skip to content

Refactor: Remove SDK duplication in src/claude/ (~68% line reduction) #51

@RichardAtCT

Description

@RichardAtCT

Summary

A deep review of src/claude/ (2,774 lines across 8 files) against claude-agent-sdk v0.1.31 reveals that ~68% (~1,880 lines) duplicates or over-complicates native SDK functionality.

Full analysis: docs/SDK_DUPLICATION_REVIEW.md

Key Findings

# Finding Impact Lines Affected
1 Using query() instead of ClaudeSDKClient — we built a 340-line SessionManager with temp IDs and swap logic for what the SDK handles natively HIGH ~330
2 ToolMonitor validates tools reactively during streaming; SDK's can_use_tool blocks before execution HIGH ~425
3 Maintaining two complete backends (SDK 513 lines + CLI subprocess 594 lines + parser 338 lines) with identical dataclasses and extraction logic HIGH ~1,012
4 Not using max_budget_usd — cost tracked in 4 places but never enforced MEDIUM ~10
5 Manual disallowed_tools checking — SDK has native option MEDIUM ~15
6 Bash substring blocklist (>, ` , &, ;) blocks legitimate shell usage; should use can_use_tool` + sandbox MEDIUM

Proposed Phases

Phase What Risk
1 Low-risk cleanup: dead state, ResultMessage.result, pass disallowed_tools to SDK options None
2 Remove CLI subprocess backend (integration.py, parser.py, fallback logic) Medium — upgrade SDK first
3 Replace ToolMonitor with can_use_tool callback Medium — write tests first
4 Switch query() to ClaudeSDKClient for multi-turn conversations High — prototype first
5 Final cleanup: CLI discovery, consolidate dataclasses Low

Prerequisites

  • Upgrade claude-agent-sdk to latest (currently on 0.1.31)
  • Ensure test coverage on existing security validation rules
  • Prototype ClaudeSDKClient lifecycle management (one client per user? per directory?)

Target State

File Before After
integration.py 594 deleted
parser.py 338 deleted
session.py 340 ~90
monitor.py 333 ~50
facade.py 568 ~270
sdk_integration.py 513 ~410
Total 2,774 ~900

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions