Skip to content

refactor: Split agent_server/services/claude_code.py (1003 lines) #122

Closed

Description

@vybe

Problem

docker/base-image/agent_server/services/claude_code.py (1003 lines) is the agent-side runtime service handling interactive sessions, headless execution, subprocess management, and output parsing. It contains:

Function Lines
execute_headless_task 303
execute_claude_code 182
read_subprocess_output_with_timeout 170

Proposed Solution

Split into focused modules:

  1. services/claude_code.py — Core session management, execute_claude_code (~300 lines)
  2. services/headless_executor.py — Headless task execution, execute_headless_task (~350 lines)
  3. services/subprocess_manager.py — Process lifecycle, output reading, timeout handling (~250 lines)
  4. services/output_parser.py — Metric extraction (tokens, cost, context) from Claude output (~100 lines)

Acceptance Criteria

  • Each file < 350 lines
  • Terminal sessions work (interactive mode)
  • Headless task execution works
  • All output metrics captured correctly

Source

Refactor audit 2026-03-13

Activity

  1. added
    priority-p1
    type-refactor
    on Mar 14, 2026
  2. AndriiPasternak31 commented on May 8, 2026

    @AndriiPasternak31
    Contributor

    Heads-up for whoever picks this up: the file has more than doubled since this issue was filed (1003 → 2137 lines as of 2026-05-09). The 4-module proposal in the issue body is stale and doesn't account for responsibilities the file gained since March (JSONL recovery, signal-exit classification, empty-result diagnostics, drain-budget handling, GUARD-003 timeout layering).

    ADR 0001 (PR #743, evaluation for #409) proposes a rescoped 6-module split in §10 that maps cleanly to today's file. Use it as a starting point — disagreement welcome.

    Also from #409's evaluation: SDK migration is DEFERRED, so this split has standalone value and won't be invalidated by a near-term rewrite.

  3. added
    status-in-dev
    on May 10, 2026
  4. vybe commented on May 10, 2026

    @vybe
    ContributorAuthor

    Fixed in PR #750 (ec0e4ef on dev). claude_code.py split into focused modules: executor.py, session_manager.py, output_handler.py, command_builder.py.

  5. reopened this on May 10, 2026
  6. added
    complexity-low
    theme-devex
    on Jun 3, 2026
  7. added a commit that references this issue on Jun 12, 2026
  8. removed
    status-in-dev
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p1theme-devextype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions