Skip to content

trading_agent.doctor.checks.claude_code_backend_check

Checks that Claude Code is installed and can use the Max subscription.

The subscription is used through a token from claude setup-token. An ANTHROPIC_API_KEY in the environment would make Claude Code bill the API instead, so its presence is a failure.

Typical usage example:

result = ClaudeCodeBackendCheck('claude', secrets).run()

ClaudeCodeBackendCheck

ClaudeCodeBackendCheck(backend_name, secrets)

Bases: DoctorCheck

Checks one backend of kind "claude_code".

Creates the check.

Parameters:

Name Type Description Default
backend_name str

The backend's name in trading_agent.toml.

required
secrets Secrets

The secrets read from the environment and .env.

required
Source code in src/trading_agent/doctor/checks/claude_code_backend_check.py
def __init__(self, backend_name: str, secrets: secrets_module.Secrets):
    """Creates the check.

    Args:
        backend_name (str): The backend's name in trading_agent.toml.
        secrets (secrets_module.Secrets): The secrets read from the environment and .env.
    """
    self.name = f'Backend {backend_name} (Claude Code)'
    self._secrets = secrets

run

run()

Checks the CLI, the absence of an API key, and the subscription token.

Returns:

Type Description
CheckResult

OK when everything is ready, a warning when only the token is missing, failed otherwise.

Source code in src/trading_agent/doctor/checks/claude_code_backend_check.py
def run(self) -> doctor_check.CheckResult:
    """Checks the CLI, the absence of an API key, and the subscription token.

    Returns:
        doctor_check.CheckResult: OK when everything is ready, a warning when only the token is missing, failed otherwise.
    """
    if 'ANTHROPIC_API_KEY' in os.environ:
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.FAILED,
            'ANTHROPIC_API_KEY is set, so Claude Code would bill the API instead of your Max subscription; unset it.',
        )
    claude_path = self._claude_path()
    if claude_path is None:
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.FAILED,
            'Neither the Agent SDK bundled claude nor a claude command on PATH was found.',
        )
    completed = subprocess.run(
        [
            claude_path,
            '--version',
        ],
        capture_output=True,
        text=True,
        timeout=_TIMEOUT_SECONDS,
        check=False,
    )
    version = completed.stdout.strip()
    if not self._secrets.claude_code_oauth_token:
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.WARNING,
            f'{version} at {claude_path}, but TRADING_AGENT_CLAUDE_CODE_OAUTH_TOKEN is not set (create it with claude setup-token).',
        )
    return doctor_check.CheckResult(
        doctor_check.CheckStatus.OK,
        f'{version} at {claude_path}; the subscription token is set.',
    )