Menu

A Claude Client in One Go File
📰

A Claude Client in One Go File

DEV Community: go·stepinto.dev·18 days ago
#Tj8x8wez
#devtogo#devto#dev#json#type
Reading 0:00
15s threshold

Last week I wrote a Claude client in bash , parsed the stream with regular expressions, and pinned it as the thing to beat. This week it's Go, which has it rather easy by comparison.

Go is the first language in the series where the standard library covers everything the spec asks for: an HTTP client with TLS, a JSON codec, a buffered line reader, and a timezone database baked into the binary. The whole client is 175 lines in one file, and it runs from a scratch image.

The code is at github.com/AndyCross/claude-hot-path and the leaderboard is at /claude-hot-path/ . The spec, which every client has to pass, is on that page.

Reading the stream

An SSE stream is lines. event: lines, data: lines, blank separators, and the occasional ping . The client only acts on data: lines, so a bufio.Scanner over the response body with a prefix check is the entire transport layer:

sc := bufio . NewScanner ( resp . Body ) sc . Buffer ( make ([] byte , 64 * 1024 ), 1 << 20 ) for sc . Scan () { data , ok := strings .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.