# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                claude-code
version             2.1.229
revision            0

categories          llm
maintainers         {breun @breun} openmaintainer
license             Restrictive NoMirror
supported_archs     x86_64 arm64

description         Claude Code -- Anthropic's agentic coding tool that lives in your terminal
long_description    Claude Code is an agentic coding tool that lives in your \
                    terminal, understands your codebase, and helps you code \
                    faster by executing routine tasks, explaining complex \
                    code, and handling git workflows - all through natural \
                    language commands.

homepage            https://claude.com/product/claude-code

# https://code.claude.com/docs/en/setup
# Operating Systems: macOS 13.0+
platforms           {darwin >= 22}

if {${configure.build_arch} eq "x86_64"} {
    set arch_classifier x64
    checksums    rmd160  c9e2d55937ea02df5cf504056836032d8256e91a \
                 sha256  1cb62183e9f89ea21eb4950b84896fa7101182c7dfcbbe92e7a293f0b20ba541 \
                 size    303439136
} elseif {${configure.build_arch} eq "arm64"} {
    set arch_classifier arm64
    checksums    rmd160  3fa442954dc00237f98e81e61e4584fbc68c22e7 \
                 sha256  d732f0ba0a539c58c2ffcaef06ed03b4e523726f0cb6cc27b3a5b7e7ae0a7a21 \
                 size    294720528
} else {
    set arch_classifier unsupported_arch
    distfiles
}

# GCS bucket URL from https://claude.ai/install.sh
set claude_code_releases https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases

master_sites        ${claude_code_releases}/${version}/darwin-${arch_classifier}/

distname            claude
dist_subdir         ${name}/${version}-${os.platform}-${arch_classifier}

extract.suffix
extract {
    # There is nothing to extract, just copy the downloaded distfiles to worksrcpath
    xinstall -d ${worksrcpath}
    xinstall -m 755 ${distpath}/${distfiles} ${worksrcpath}
}

use_configure       no
build {}

test.run    yes
test.cmd    ./claude
test.target
test.args   --version

variant telemetry description {Allow Claude Code to send anonymous usage telemetry to Anthropic} {}

destroot {
    set binary_dir ${prefix}/share/${name}
    set binary ${binary_dir}/claude

    # Install binary
    xinstall -d ${destroot}${binary_dir}
    xinstall -m 755 ${worksrcpath}/claude ${destroot}${binary}

    # Create launch script
    set launch_script [open ${destroot}${prefix}/bin/claude w 0755]
    puts $launch_script "#!/bin/sh"
    set launch_command "DISABLE_UPDATES=1 DISABLE_INSTALLATION_CHECKS=1"
    if {![variant_isset telemetry]} {
        append launch_command " DISABLE_TELEMETRY=1"
    }
    append launch_command " ${binary} \"$@\""
    puts $launch_script $launch_command
    close $launch_script
}

livecheck.type      regex
livecheck.url       ${claude_code_releases}/latest
livecheck.regex     ^(\[\\d.\]+)$
