Skip to content

Fix Anthropic client instantiation on every API call #8

@chenhaot

Description

@chenhaot

In agent.py:36-38, a new anthropic.Anthropic client is created on every call to _call(). This means every analyze_issues, suggest_next, etc. creates a fresh HTTP client with a new connection pool. For users with anthropic_api_key configured, this adds unnecessary latency and resource overhead, especially during cmd_suggest which calls both analyze_issues and suggest_next sequentially.

Fix: Create the Anthropic client once and reuse it. Either initialize it in a module-level variable when api_key is first provided, or use a simple cache pattern:

_anthropic_client = None
def _get_client(api_key):
    global _anthropic_client
    if _anthropic_client is None:
        _anthropic_client = anthropic.Anthropic(api_key=api_key)
    return _anthropic_client

Identified by minbot code review

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions