Back to projects
Jul 18, 2026
3 min read

stackpilot

A lean coding agent rebuilt from recorded Claude Code traces. Client-side cache prediction, 14 tools, auto-compaction, Bedrock support.
stackpilot — Anthropic Messages API$stackpilot “refactor the config layer”searchfind config references → 12 matcheseditconfig.ts → toml, env, typesbashnpm run typecheck && npm test ✓agentdelegate test updates to subagent3 files changed, 12 tests pass, 0 regressions.

stackpilot is a lean, open-source CLI coding agent. It replicates Claude Code’s behavioral core — the tool-calling loop, prompt structure, cache model, and compaction protocol — rebuilt from recorded session traces rather than documentation.

How it was built

Every feature was verified against actual Claude Code traffic captured through ai-agent-profiler. System prompt structure, tool schemas, cache breakpoints, compaction protocol, transcript tree — all reverse-engineered from real API calls. The transport layer speaks both the Anthropic Messages API (anthropic.messages.create) and Amazon Bedrock’s binary event-stream protocol.

Architecture

src/
  cli/          main.ts — entrypoint, argument parsing
  config/       TOML + env config loading, discovery from ~/.claude/
  core/         agent loop, compaction, cost tracking, hooks,
                prompt assembly, subagent delegation, cache ledger
  session/      SQLite-backed session store for persistence
  tools/        14 tools defined as typed schemas
  transport/    Anthropic Messages API client + Bedrock stream parser
  tui/          terminal UI with markdown rendering
  types.ts      ContentBlock discriminated union (Text, ToolUse,
                ToolResult, Thinking, RedactedThinking)
  util/         shared utilities

Zero external framework. Dependencies are better-sqlite3, smol-toml, and @clack/prompts. No Express, no ORM. Native node:http and fetch.

14 tools

agent (subagent delegation), fs (read, write, edit), glob, grep, history, memory, patch, readmore, search, shell, skill, todo, webfetch.

Client-side cache prediction

stackpilot maintains a fingerprint ledger of every content block sent. Before each API call, it diffs the current stack against the ledger and predicts which blocks will hit the prompt cache. It verifies against the server response afterwards. This is something Claude Code does internally but never exposes. stackpilot gives you the numbers.

Auto-compaction

When the message stack approaches context limits, stackpilot automatically trims history. Configurable policies control what gets evicted: stale tool results, old turns, or full-history summaries.

Bedrock support

Natively parses AWS Bedrock’s binary event-stream protocol with content-type detection and SigV4 signing via aws4. Config discovery reads ~/.claude/settings.json — if Claude Code works on Bedrock, stackpilot works with no extra setup.

Provider support

Currently Anthropic API only (Claude models). Planned: DeepSeek via Anthropic-compatible endpoint. Not targeting OpenAI — the tool model differs too much from Claude’s.

Context policies

Three policies give you stack control that Claude Code hides:

  • Tool-result paging. Large command output is split across multiple readmore calls instead of flooding context.
  • Read deduplication. Repeated file reads within a session skip the API call entirely.
  • Stack eviction. Old tool results are dropped based on age and relevance heuristics.

Open source at github.com/rguiu/stackpilot (MIT).