Kloakt
Cloaked headless browser for AI agents.
Lightweight, stealthy, built in Rust. Based on Obscura.
Kloakt is a headless browser built for AI agents. It runs JavaScript via V8, extracts clean markdown from any page (including SPAs), and exposes tools via MCP for Claude Code and other AI systems.
Beyond one-shot extraction it can drive persistent, stateful sessions (click, type, navigate β cookies and page/JS state persist across calls), emit an accessibility/structure snapshot as an agent-vision substitute, and capture real screenshots via system Chrome β 12 MCP tools in all.
Why Kloakt?
| Metric | Kloakt | Headless Chrome |
|---|
| Memory | 30 MB | 200+ MB |
| Binary size | 70 MB | 300+ MB |
| Anti-detect | Built-in | None |
| Page load | 85 ms | ~500 ms |
| Startup | Instant | ~2s |
| SPA extract | Yes | Manual |
Install
Prebuilt binary (recommended)
One-line install (Linux & macOS). Downloads the right binary for your OS/arch from the latest GitHub Release and installs it to ~/.local/bin (or /usr/local/bin when run as root):
curl -fsSL https://raw.githubusercontent.com/KultMember6Banger/kloakt/main/install.sh | sh
You can pin a version or override the install dir:
KLOAKT_VERSION=v0.1.2 INSTALL_DIR=/usr/local/bin \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/KultMember6Banger/kloakt/main/install.sh)"
Windows: download kloakt-x86_64-windows.zip from the Releases page and extract kloakt.exe onto your PATH.
Homebrew (macOS)
brew install KultMember6Banger/kloakt/kloakt
# or, from a local checkout:
brew install --formula ./Formula/kloakt.rb
(Until a dedicated tap exists, brew tap KultMember6Banger/kloakt https://github.com/KultMember6Banger/kloakt then brew install kloakt.)
cargo install
Builds the CLI from crates.io (requires Rust toolchain; first build compiles V8, ~5 min):
cargo install obscura-cli
This installs the kloakt binary. To build with stealth mode, add --features stealth.
Build from source
git clone https://github.com/KultMember6Banger/kloakt.git
cd kloakt
cargo build --release
# With stealth mode (anti-detection + tracker blocking)
cargo build --release --features stealth
Requires Rust 1.75+ (rustup.rs). First build takes ~5 min (V8 compiles from source, cached after).
Quick Start
Extract content (AI agent use)
# Clean markdown from any page
kloakt extract https://example.com --main
# Structured JSON with metadata
kloakt extract https://example.com --main --json
# Cap output for agent context windows
kloakt extract https://en.wikipedia.org/wiki/Rust --main --json --max-chars 3000
# Wait for SPA hydration
kloakt extract https://example.com --delay 2000 --json
Fetch a page
# Get the page title
kloakt fetch https://example.com --eval "document.title"
# Extract all links
kloakt fetch https://example.com --dump links
# Render JavaScript and dump markdown
kloakt fetch https://news.ycombinator.com --dump markdown
# Wait for dynamic content
kloakt fetch https://example.com --wait-until networkidle0
Start the CDP server
kloakt serve --port 9222
# With stealth mode
kloakt serve --port 9222 --stealth
Scrape in parallel
kloakt scrape url1 url2 url3 ... \
--concurrency 25 \
--eval "document.querySelector('h1').textContent" \
--format json
Snapshot page structure (agent vision)
# Indexed accessibility/structure tree β tags, text, roles, what's clickable, visibility
kloakt snapshot https://example.com
# Only the actionable elements (links, buttons, inputs), with id/name/label for targeting
kloakt snapshot https://example.com --interactive
kloakt has no rasterizer, so this is the lightweight "what's on the page and what can I act on" view for agents that work from structure rather than pixels.
Screenshot (via system Chrome)
# Real PNG β delegates to a locally-installed Chrome/Chromium/Edge
kloakt screenshot https://example.com --output shot.png --width 1280 --height 800
Persistent sessions
Drive a named session whose cookies and page/JS state survive across separate
invocations, backed by a running kloakt serve daemon:
kloakt serve --port 9222 & # start the daemon once
kloakt session open shop --url https://example.com
kloakt session snapshot shop --interactive # see the page structure
kloakt session type shop 'input[name=q]' 'hello' # fill a field
kloakt session click shop 'button[type=submit]' # click an element
kloakt session text shop # read the body text
kloakt session eval shop 'document.title' # run JS, get the value back
kloakt session close shop # tear down (drops cookies + page)
Smart Extraction
The extract command uses a multi-phase pipeline optimized for AI agents:
- Noise removal β strips cookie banners, ads, popups, nav, social widgets
- Content scoring β text-density algorithm (Readability-like) finds the main content block
- Markdown conversion β DOM-to-markdown with absolute URL resolution
- SPA fallback β when JS rendering fails, extracts from meta tags, Open Graph, JSON-LD, and noscript content
Works on static HTML, server-rendered pages, and pure client-side SPAs (React, Vue, etc.).
Python API
from kloakt import (
extract, extract_fields, fetch, scrape, search, crawl,
snapshot, screenshot, session_open, session_close,
)
# Extract clean markdown
page = extract("https://example.com")
print(page.title, page.content, page.meta)
# Cap output length
page = extract("https://example.com", max_chars=3000)
# Wait for SPA content
page = extract("https://example.com", delay=2000)
# Structured field extraction via CSS selectors
data = extract_fields("https://news.ycombinator.com", {
"title": "title",
"stories": ".titleline > a[]", # [] => list of all matches
"links": ".titleline > a[]@href" # @href => an attribute
})
print(data["data"]["stories"])
# Raw fetch
html = fetch("https://example.com", dump="html")
title = fetch("https://example.com", eval_js="document.title")
# Parallel scrape
results = scrape(["https://a.com", "https://b.com"], concurrency=5)
# Discover links, or breadth-first crawl a small section of a site
links = search("https://news.ycombinator.com", same_domain=True)
pages = crawl("https://example.com", max_pages=5, max_depth=1)
# Structure snapshot (agent vision) and a real screenshot via system Chrome
snap = snapshot("https://example.com", interactive=True)
screenshot("https://example.com", output="shot.png")
# Persistent session β auto-starts a daemon if one isn't running; cookies + page
# state persist across calls. (session_nav / _click / _type / _eval / _text / _snapshot)
session_open("shop", url="https://example.com")
# ... drive the page across calls ...
session_close("shop")
MCP Server (Claude Code)
Kloakt includes an MCP server for use as a Claude Code tool:
{
"mcpServers": {
"kloakt": {
"command": "python3",
"args": ["/path/to/kloakt/mcp_server.py"]
}
}
}
Exposes 12 native tools:
| Tool | What it does |
|---|
kloakt_extract | Clean markdown, or structured fields via schema |
kloakt_fetch | Low-level fetch (html/text/links/markdown, or JS eval) |
kloakt_scrape | Many URLs in parallel |
kloakt_search | Discover outbound links on a page |
kloakt_crawl | Budget/depth-limited breadth-first crawl |
kloakt_snapshot | Accessibility/structure tree (agent vision) |
kloakt_screenshot | Real PNG via system Chrome |
kloakt_session_open | Open a persistent named session |
kloakt_session_act | navigate / click / type / eval within a session |
kloakt_session_read | Read a session's page as text or snapshot |
kloakt_session_list | List open sessions |
kloakt_session_close | Close a session (drops its cookies + page) |
Puppeteer / Playwright
Puppeteer
The CDP server embeds a per-session token in the WebSocket path (like Chrome). Connect via
browserURL so the client discovers the token from /json/version automatically β don't
hardcode the ws://.../devtools/browser path.
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.connect({
browserURL: 'http://127.0.0.1:9222', // discovers the tokenized ws endpoint
});
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com');
const stories = await page.evaluate(() =>
Array.from(document.querySelectorAll('.titleline > a'))
.map(a => ({ title: a.textContent, url: a.href }))
);
await browser.disconnect();
Playwright
import { chromium } from 'playwright-core';
const browser = await chromium.connectOverCDP({
endpointURL: 'http://127.0.0.1:9222', // discovers the tokenized ws endpoint
});
const page = await browser.newContext().then(ctx => ctx.newPage());
await page.goto('https://en.wikipedia.org/wiki/Web_scraping');
console.log(await page.title());
await browser.close();
Stealth Mode
Enable with --features stealth.