llmkit

package module
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 0 Imported by: 0

README

llmkit

Go Reference Go Report Card

Go library for LLM utilities. Standalone toolkit for token counting, prompt templates, response parsing, model selection, and multi-provider CLI integrations (Claude, Codex, Gemini, and more).

Installation

go get github.com/randalmurphal/llmkit

Packages

Package Description
claude Claude CLI wrapper with OAuth credential management
codex OpenAI Codex CLI wrapper with headless exec --json support
template Prompt template rendering with {{variable}} syntax
tokens Token counting and budget management
parser Extract JSON, YAML, and code blocks from LLM responses
truncate Token-aware text truncation strategies
model Model selection, cost tracking, and escalation chains

Quick Start

Token Counting
import "github.com/randalmurphal/llmkit/tokens"

counter := tokens.NewEstimatingCounter()
count := counter.Count("Hello, World!")  // ~4 tokens
Template Rendering
import "github.com/randalmurphal/llmkit/template"

engine := template.NewEngine()
result, err := engine.Render("Hello {{name}}!", map[string]any{"name": "World"})
// result: "Hello World!"
Claude CLI
import "github.com/randalmurphal/llmkit/claude"

client := claude.NewCLI()
resp, err := client.Complete(ctx, claude.CompletionRequest{
    Messages: []claude.Message{
        {Role: claude.RoleUser, Content: "What is 2+2?"},
    },
})
fmt.Println(resp.Content)
Response Parsing
import "github.com/randalmurphal/llmkit/parser"

response := `Here's the JSON: ` + "```json\n{\"key\": \"value\"}\n```"
data, err := parser.ExtractJSON(response)
// data: map[string]any{"key": "value"}
Model Selection
import "github.com/randalmurphal/llmkit/model"

selector := model.NewSelector(
    model.WithThinkingModel(model.ModelOpus),
    model.WithDefaultModel(model.ModelSonnet),
    model.WithFastModel(model.ModelHaiku),
)
m := selector.SelectForTier(model.TierThinking)  // ModelOpus

Design Principles

  • Zero external dependencies - Only Go stdlib
  • À la carte imports - Use only what you need
  • Stable API - Semver-friendly, rarely changes
  • No forced patterns - Interfaces for flexibility

Development

# Run tests
make test

# Run tests with coverage
make coverage

# Lint
make lint

# All checks
make verify

License

MIT License - see LICENSE for details.

Documentation

Overview

Package llmkit provides utilities for working with Large Language Models.

llmkit is a standalone toolkit extracted from flowgraph, designed to be imported à la carte. Each subpackage can be used independently:

  • claude: Claude CLI wrapper with OAuth credential management
  • template: Prompt template rendering with {{variable}} syntax
  • tokens: Token counting and budget management
  • parser: Extract JSON, YAML, and code blocks from LLM responses
  • truncate: Token-aware text truncation strategies
  • model: Model selection, cost tracking, and escalation chains

Quick Start

Token counting:

import "github.com/randalmurphal/llmkit/tokens"
counter := tokens.NewEstimatingCounter()
count := counter.Count("Hello, World!")

Template rendering:

import "github.com/randalmurphal/llmkit/template"
engine := template.NewEngine()
result, _ := engine.Render("Hello {{name}}", map[string]any{"name": "World"})

Claude CLI:

import "github.com/randalmurphal/llmkit/claude"
client := claude.NewCLI()
resp, _ := client.Complete(ctx, claude.CompletionRequest{...})

Design Philosophy

llmkit follows these principles:

  • Zero external dependencies (stdlib only)
  • Each package usable independently
  • Stable, semver-friendly API
  • Sensible defaults with full configurability
  • Interfaces for extensibility, concrete types for simplicity

Directories

Path Synopsis
Package aider provides a client for the Aider CLI.
Package aider provides a client for the Aider CLI.
Package claude provides interfaces and implementations for the Claude Code CLI.
Package claude provides interfaces and implementations for the Claude Code CLI.
jsonl
Package jsonl provides reading and tailing of Claude Code session JSONL files.
Package jsonl provides reading and tailing of Claude Code session JSONL files.
session
Package session provides long-running Claude CLI session management with bidirectional stream-json I/O.
Package session provides long-running Claude CLI session management with bidirectional stream-json I/O.
Package claudeconfig provides utilities for parsing Claude Code's native configuration formats.
Package claudeconfig provides utilities for parsing Claude Code's native configuration formats.
Package claudecontract provides a single source of truth for all Claude CLI interface details including flag names, event types, file paths, permission modes, tool names, and other volatile strings that may change between CLI versions.
Package claudecontract provides a single source of truth for all Claude CLI interface details including flag names, event types, file paths, permission modes, tool names, and other volatile strings that may change between CLI versions.
Package codex provides a Go wrapper for the OpenAI Codex CLI.
Package codex provides a Go wrapper for the OpenAI Codex CLI.
Package codexcontract centralizes Codex CLI protocol constants.
Package codexcontract centralizes Codex CLI protocol constants.
Package continue provides a client for Continue.dev CLI (cn).
Package continue provides a client for Continue.dev CLI (cn).
Package gemini provides a Go wrapper for the Gemini CLI binary.
Package gemini provides a Go wrapper for the Gemini CLI binary.
Package local provides a client for local LLM models via a Python sidecar process.
Package local provides a client for local LLM models via a Python sidecar process.
Package model provides model selection, cost tracking, and escalation chains.
Package model provides model selection, cost tracking, and escalation chains.
Package opencode provides a client for the OpenCode CLI.
Package opencode provides a client for the OpenCode CLI.
Package parser extracts structured content from LLM responses.
Package parser extracts structured content from LLM responses.
Package provider defines the unified interface for LLM CLI providers.
Package provider defines the unified interface for LLM CLI providers.
Package template provides prompt template rendering with variable substitution.
Package template provides prompt template rendering with variable substitution.
Package tokens provides token counting and budget management for LLM prompts.
Package tokens provides token counting and budget management for LLM prompts.
Package truncate provides text truncation utilities for managing LLM context.
Package truncate provides text truncation utilities for managing LLM context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL