Files
cline/apps/examples
BeeandSaoud Rizwan 6138bdfe40 feat: Enforce a production singleton Cline Hub (#11372)
* feat: Enforce a production singleton Cline Hub

This PR changes local Hub startup/discovery so production uses one stable daemon per user machine instead of silently creating additional hubs on random ports.

Replace resolveSharedHubOwnerContext with resolveProductionHubOwnerContext
across doctor and hub server lifecycle management to scope hub discovery
to the production owner.

Additionally:
- Preserve and propagate auth tokens when retiring incompatible hubs
- Throw a clear error when a compatible hub is already running but its
  discovery record is missing, guiding users to run 'cline doctor fix'
- Gate port fallback behind an explicit allowPortFallback override
- Update tests to mock the new production hub owner context

* patches

* fix

* hasExplicitPort

* Restored daemon cron startup, made discovery auth tokens required again, and fixed graceful hub stop/restart paths to use the selected production/shared owner context.

* clean up

* patches

* fix Polynomial regular expression

* test

* fix: require explicit hub port fallback in production

* fix(cli): stop pgrep from parsing the hub daemon marker as an option

pgrep treats the "--cline-hub-daemon" pattern as an unknown long option
and exits 2, so doctor never found stale daemons from compiled-binary
installs, which are exactly the processes 'cline doctor fix' is told to
clean up. Pass "--" before the pattern to end option parsing.

* fix(hub): retire legacy shared-owner hubs on production startup

Pre-singleton production builds tracked the local hub under the shared
owner discovery path and spawned daemons on random fallback ports. The
production owner context never reads that path, so upgrades would leave
those daemons running indefinitely with no way to reuse or stop them.
Retire the recorded legacy hub (its record carries the auth token and
pid needed for a graceful stop) and clear the legacy record before
resolving the production hub.

* refactor(hub): simplify stale discovery clearing, share capability list

shouldClearStaleHubDiscovery was only ever called with
discoveredVerified=false (the true assignment sits on a return path),
so the expected-hub probe and compatibility check had no effect and the
condition reduced to "a discovery record exists and was not reused".
Replace it with a plain conditional and drop the tests that exercised
unreachable states.

Also move the hub capability list into a typed HUB_CAPABILITIES
constant in @cline/shared next to HubCapabilityName so the server
cannot drift from the type.

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-06-10 16:59:13 -07:00
..
2026-06-03 01:49:57 +02:00

Cline SDK Examples

Learn how to build with the Cline SDK through working examples, ordered from simple to complex.

SDK Skill

If you use a coding agent (Claude Code, Codex, Cline, etc.), install the Cline SDK skill to give your agent context on the SDK's APIs and best practices to help you build with the Cline SDK.

npx skills add cline/sdk-skill

Prompt it to scaffold agents, create custom tools, wire up plugins, configure providers, and more.

Getting started

All examples live in this directory. Each is a standalone project with its own package.json and README. To run any example:

cd apps/examples/<example-name>
bun install
bun run build:sdk
export CLINE_API_KEY="cline_..."
bun dev

Requires Node.js 22+.

Examples

Beginner

Example Description Concepts
quickstart Send one prompt, stream the response. ~15 lines of code. Agent, subscribe, run()
cli-agent Interactive terminal chat with a shell tool. createTool, multi-turn run()/continue(), streaming
cline-core-cli-agent Interactive terminal chat powered by ClineCore. ClineCore.create(), cline.start(), cline.send(), built-in tools, streaming

Intermediate

Example Description Concepts
code-review-bot AI code reviewer that reads git diffs and produces structured comments. Multiple tools, completesRun lifecycle, systemPrompt, zod schemas
multi-agent Web app that fans out to three specialist agents in parallel, streams results via SSE, then synthesizes a unified answer. Concurrent agents, Promise.all, per-agent subscribe(), SSE streaming, agent composition

Advanced

Example Description Concepts
desktop-app Full Tauri + Next.js desktop app for running and inspecting chat sessions. Sidecar runtime, websocket transport, session persistence
menubar macOS menu bar app with Tauri. Native app integration, compact UI
vscode VS Code extension with chat panel. Extension API, webview, workspace context

SDK packages

When building your own app, install the public SDK package:

npm add @cline/sdk

@cline/sdk re-exports everything from @cline/core. You only need @cline/agents or @cline/llms if you want lower-level control over the agent runtime or model gateway directly.

Learn more