mark3labs/kit/kit-sdk
Claude Code and agent skill by mark3labs/kit
- community
Checking that the SKILL.md file is still in the repository.
Guide for building Go applications with the Kit SDK. Use when the user asks to create a program, service, script, or application that uses Kit programmatically as a Go library — e.g. embedding LLM interactions, building agents, creating CLI tools powered by Kit, or integrating Kit into backend services. Do NOT use for Kit extensions (use kit-extensions skill instead).
Install
npx vskill@latest install mark3labs/kit/kit-sdkSKILL.md
Kit SDK Development Guide
The Kit SDK (pkg/kit) lets you embed Kit's full agent capabilities — LLM interactions, tool execution, session management, streaming, hooks — into any Go application. Unlike extensions (which are interpreted scripts running inside Kit's TUI), SDK programs are standalone compiled Go binaries.
This file is the entry point. It gives the installation, a quick start, the core lifecycle, and the rules you must never miss. Detailed material lives in the references/ directory (see Reference files below). Read only the reference files that apply to your task.
Installation
Import path (alias recommended):
Quick Start
Core Lifecycle
- Create:
kit.New(ctx, opts)— loads config, initializes MCP servers, creates LLM provider, sets up agent - Interact:
host.Prompt(ctx, msg)— send messages, agent uses tools as needed - Close:
host.Close()— cleans up MCP connections, model resources, session file handle
Always defer Close():
API Map
| Area | Entry points | Reference | |
|---|---|---|---|
| Configure the instance | kit.Options{Model, SystemPrompt, MaxSteps, Tools, ExtraTools, NoSession, ...}, kit.NewIsolatedAgent / kit.Isolated() for hermetic embeds | references/options.md | |
| Talk to the agent | Prompt, PromptResult, PromptResultWithFiles, PromptWithOptions, Steer, FollowUp, PromptResultWithMessages | references/prompt-methods.md | |
| Observe (read-only) | host.OnToolCall(...), host.OnMessageUpdate(...), host.Subscribe(...) | references/events.md | |
| Intercept (read-write) | host.OnBeforeToolCall(priority, fn), OnAfterToolResult, OnBeforeTurn, OnPrepareStep, OnContextPrepare, OnBeforeCompact | references/hooks.md | |
| Add capabilities | kit.NewTool(name, desc, fn), kit.TextResult, built-in tool constructors and bundles | references/tools.md | |
| Persist conversations | SessionPath, Continue, NoSession, instance and package-level session methods | references/sessions.md | |
| Decision API | kit.Decide, host.Decide, GetDecisionModels, typed question builders, custom decision providers (kit.RegisterDecisionProvider, Options.DecisionProviders) | references/decisions.md | |
| Models and MCP | host.SetModel, model registry, custom provider backends (kit.RegisterProvider, Options.Providers), AddMCPServer, in-process servers, MCP OAuth | references/models-and-mcp.md | |
| Manage the context window | EstimateContextTokens, Compact, AutoCompact, host.Subagent | references/context-compaction-subagents.md |
A minimal custom tool, which is the most common extension point:
Critical Rules (never skip)
- `Tools` replaces, `ExtraTools` adds.
Options.Toolsreplaces default core tools, not MCP or extension tools.Options.ExtraToolsadds tools alongside the defaults. UseToolsto replace core tools; useExtraToolsto extend them. - Register events and hooks before calling `Prompt`. Subscribers and hooks return an unsubscribe function —
defer unsub()if the handler must not outlive a scope. - Events are read-only; hooks are read-write. Use
host.On<Event>to observe. Usehost.On<Hook>(priority, fn)to block, modify, or inject. In hooks, returnnilto allow/pass through; the first non-nil result wins. Lower priority values run first (kit.HookPriorityHigh = 0,Normal = 50,Low = 100). - Pointer fields mean "unset". Generation parameters like
Temperature,TopP,TopKare pointers so an explicit0.0differs from "leave the provider default". Zero-valueMaxTokensauto-resolves; a non-zero value suppresses right-sizing. - Sessions persist automatically as JSONL tree files. No explicit save call exists or is needed. Use
NoSession: truefor ephemeral, in-memory agents (scripts, subagents, tests). - Context-window fill is not `InputTokens` alone. With prompt caching, sum
InputTokens + CacheReadTokens + CacheCreationTokens + OutputTokensfromresult.FinalUsage. - Reactive compaction is always on. A context-overflow error triggers one compact-and-replay.
AutoCompact: trueadds proactive compaction before turns that near the limit. If the replay still overflows, the turn fails withkit.ErrContextOverflow. - MCP OAuth is opt-in. If
MCPAuthHandleris nil, remote MCP servers that require OAuth fail with an authorization-required error. They do not open a browser silently. - No dependency-name leakage. Use the
kit.LLM*type aliases (LLMMessage,LLMUsage, ...) andkit.ConvertToLLM*helpers. Do not import the underlying LLM library into SDK-facing code. - Configuration file selection is not field precedence. An explicit
ConfigFileselects only that file; otherwise project config is preferred to home config. Effective generation/provider fields use explicit SDK values → environment → configuration → per-model/fallback values. Stored credentials beat provider environment variables unless explicitly overridden. Seereferences/configuration.md.kit.Newhandles setup; usekit.InitConfigonly for special cases.
Reference files
Read the file that matches the task. Paths are relative to this skill's root directory.
| File | Read it when you need... | |
|---|---|---|
references/options.md | Every kit.Options field with comments (model, behavior, generation parameters, provider overrides, session, tools, skills, feature toggles, compaction, MCP OAuth, in-process MCP), the generation/provider cheat-sheet table, and isolated agents (NewIsolatedAgent, Isolated, opt-in options). | |
references/prompt-methods.md | All prompt variants: simple string, full result with usage stats, multimodal file attachments, per-call system message injection, system-level steering, continue without new input, multiple user messages in one turn. | |
references/events.md | Typed convenience subscribers, the generic subscriber, the full list of event types with their fields, and tool-kind constants. | |
references/hooks.md | Each hook (BeforeToolCall, AfterToolResult, BeforeTurn, AfterTurn, PrepareStep, ContextPrepare, BeforeCompact) with result types, plus hook priorities. | |
references/tools.md | Creating custom tools with kit.NewTool (schema auto-generation, struct tags, output helpers), built-in tool constructors, tool bundles, tool options, using tools in Options, querying tools at runtime. | |
references/sessions.md | Session modes, instance methods, package-level session operations, and implementing a custom SessionManager. | |
references/models-and-mcp.md | Model management at creation and runtime, the model registry, model string format, per-model system prompts and generation parameters, custom provider backends (ProviderFactory); dynamic MCP server management, in-process MCP servers, MCP prompts, MCP resources, MCP OAuth authorization and token storage. | |
references/context-compaction-subagents.md | Context token estimation, GetContextStats, manual and automatic compaction, reactive compaction; in-process subagents, subscribing to subagent events, named agents. | |
references/extension-api-auth-skills.md | The ExtensionAPI (kit.Extensions()), credential management (auth), and skill loading/prompt building. | |
references/types.md | The full list of re-exported types (LLMMessage, LLMUsage, tool types, event types, errors, ...). | |
references/common-patterns.md | Recipes: scripting/CLI pipe, long-running autonomous agent, streaming output to terminal, multi-turn conversation with memory, tool execution monitoring, guard rails with hooks, parallel subagents, read-only analysis agent. | |
references/configuration.md | Config file discovery order, ${ENV_VAR} expansion, kit.InitConfig and kit.InitConfigWithOptions. |
Key Files for Reference
- `pkg/kit/kit.go` — Kit struct, New(), Prompt methods, Subagent, Close
- `pkg/kit/extension_api.go` — ExtensionAPI interface, kit.Extensions() accessor
- `pkg/kit/types.go` — Re-exported types from internal packages
- `pkg/kit/tools.go` — Tool constructors and bundles
- `pkg/kit/events.go` — Event types, EventBus, typed subscribers
- `pkg/kit/hooks.go` — Hook system (BeforeToolCall, AfterToolResult, etc.)
- `pkg/kit/sessions.go` — Session management
- `pkg/kit/compaction.go` — Context compaction
- `pkg/kit/models.go` — Model registry lookups
- `pkg/kit/config.go` — Config initialization and defaults
- `pkg/kit/skills.go` — Skills loading and prompt building
- `pkg/kit/auth.go` — Credential management
- `examples/sdk/` — Working example programs
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/kit-sdk/SKILL.md
Popularity
- Repository stars
- 143
- Repository forks
- 30
- 7-day trend score
- 24
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mark3labs/kit/kit-sdk)