How a Kompile Session Works
From opening a repository to getting a verified answer back, here is what you actually see — and what Kompile does for you automatically on every agent turn, including how exploration, edits, tool calls, and token/cost tracking work at every step.
flowchart TD
START["1. Open a Session"] --> NEW["New chat\nkompile chat → auth & model"]
START --> RES["Pick up where you left off\nkompile chat --continue / kompile resume"]
NEW --> PROMPT["2. You Send a Prompt"]
RES --> PROMPT
PROMPT --> CTX["3. Context Assembled Automatically\n• Memories & past incidents\n• Reminders, AGENTS.md & skills\n• Pending background wakes"]
CTX --> EXP["4. Explore (Bounded & Token-Aware)\n• code_search, lsp, glob, grep, read\n• Large outputs cached as ref:ID\n• Broad research offloaded to cheap workers"]
EXP --> EDIT["5. Edit & Verify Safely\n• Read-before-edit & Enforcer checks\n• edit_batch / draft / file locks / /diffs\n• lsp check, build & tests"]
EDIT --> DONE["6. Wrap Up & Save\n• Optional Judge check & auto-compaction\n• Transcript, diffs & memories saved"]
CTX -.-> OBS["Live Telemetry Anytime\nTopBar ctx/tok • /cost • /usage\n/stats tools • /dashboard-tools\n/subagent-breakdown • /diffs"]
EXP -.-> OBS
EDIT -.-> OBS
DONE -.-> OBS1. Starting a session (or resuming one)
First time: auth → model → chat
Open your repository and launch Kompile in the terminal (or browser):
cd /path/to/your/repo
kompile chat # Terminal UI
# or
kompile chat --web # Browser workspace on :8081On first run, Kompile walks you through three quick choices and saves them so future launches drop you straight into the prompt:
- How you want to run — Standard Chat (Kompile's own agent loop with any provider/model), Passthrough (run Claude Code, Codex, Antigravity
agy, or OpenCode inside Kompile), or Resume an existing session. - Sign in / pick a provider — OAuth login (Claude, ChatGPT/Codex, Antigravity, GitHub Copilot), API key (Anthropic, OpenAI, OpenRouter, Fireworks, Together, Gemini, etc.), or a local model.
- Pick a model — Choose from live models returned by your provider (plus thinking/reasoning effort where supported).
TIP
You can also skip menus with direct flags (kompile chat --provider openai --auth oauth --model gpt-5.6-sol) or run kompile onboard once to detect installed CLIs and import existing chats.
Returning later: resume (even on a different vendor)
You don't start from scratch when you close your terminal or switch tools:
kompile chat --continue # Resume your most recent chat in this repo
kompile resume # Browse chats across Kompile, Claude, Codex, agy, OpenCode, Cursor, etc.
kompile resume-all # Reopen all recently active chats after a reboot or crashWant to continue an existing conversation on a different vendor?
- At resume time:
kompile chat --resume <id> --provider openrouter --model anthropic/claude-sonnet-4-5orkompile resume --session-id <id> --agent codex. - Mid-conversation without exiting: Run
/auth(or/provider) in terminal chat — or/model <vendor>:<model>in the Web Harness — to change vendor, account, or model while keeping your conversation and background tasks intact. See Import, Resume & Vendor Switching.
2. What happens on a standard agent turn
Suppose you type:
"Fix the OAuth token refresh race condition and add a regression test."
Before the model even generates its first token — and through exploration, editing, and verification — Kompile runs a predictable four-step turn lifecycle.
Step 1: Context is assembled automatically
Kompile builds the turn context around your prompt so you don't have to repeat standing instructions or re-explain repo conventions:
- Relevant memories (
<memory_context>): Automatically pulls in standing rules and top matching entries from project (.kompile/memory/) and global (~/.kompile/memory/) memory — plus warn-only notes from relevant past incidents so the agent avoids repeating known traps. See Persistent Memory. - Your reminders (
<kompile_reminders>): Any standing project or user reminders you configured (for example, "Plan before making changes", "Run tests before finishing", or build-command rules) are attached to the turn automatically. See Reminders. - Repo instructions & skills: Loads your project's
AGENTS.md/ rules and exposes your saved/skillsprompt templates. Optional heavy tool groups (crawl, graph, delegation) stay deferred until activated so they don't bloat every prompt's input tokens. - Pending background updates: Delivers any background build completions or subagent reports that arrived since your last turn.
Step 2: How the agent explores your codebase — and what it costs
Before editing anything, the agent has to find the right files and understand how they fit together. In many harnesses, exploration is the hidden #1 token sink: dumping whole files or huge grep outputs into context forces the model to re-read tens of thousands of tokens on every single follow-up round.
Kompile keeps exploration fast and economical in four ways:
- Narrow before reading: The agent locates files with
glob, runs targeted regexes withgrep/grep_batch, jumps straight to symbols withcode_search/code_graph(your local index — zero LLM tokens spent walking directories) andlsp(symbols,definition,references), and then reads only the exact line ranges it needs withread/read_batch. The Enforcer blocks raw shell substitutes (cat,find,grep) that tend to dump unbounded output. - Large outputs stay out of context (
ref:IDhandles): When a search, file read, or build log is large, Kompile caches the full output on disk and hands the model a compact reference handle instead of pasting 2,000 lines straight into the prompt. The model pulls only the matching lines viafetch_result/fetch_result_batch. - No blind full-price re-reads: Kompile tracks recently read files (
file_context/file_activity) and flags when unchanged files were already read across sessions or subagents, avoiding duplicate token burn. - Offload broad research to cheaper models: When a task needs wide exploration across many modules, the agent can delegate read-only research to a
task/multi_tasksubagent routed to a fast, economical model (/subagent-config), returning only a concise summary to your main frontier thread.
How exploration shows up in your bill / quota:
- Uncached input & cache writes (
new context written): Every new file slice or tool result pulled into the conversation is billed once as fresh input / cache write — keeping reads bounded directly lowers this cost. - Cache reads (
carried context re-read): Previously read context is served from the provider's prompt cache on later rounds (typically ~0.1× the input rate) as long as the prefix stays stable. - Inspect exploration cost anytime: Run
/subagent-breakdownto see exactly how many tokens a worker spent on startup, skills, tools, and tool results, or/dashboard-toolsand/stats toolsto spot oversized reads or noisy loops.
Step 3: How the agent edits, verifies & stays safe
Once the agent knows what to change, Kompile guards the edit and test cycle:
- Read-before-edit: The Enforcer requires the agent to read a file before modifying it (
edit,edit_batch,edit_patch,write) so replacements match exact file text instead of guessing. - Batched edits (fewer round-trips): Related changes across multiple files can be read in one
read_batchand applied atomically in oneedit_batchoredit_patch, cutting down extra model round-trips and repeated input-token costs. - Multi-agent file locks & reviewable
drafts: When multiple sessions or subagents work in the same repo, file locks (edit_coordinator) prevent silent overwrites. If you want to review a refactor before it touches your working tree, ask the agent to stage changes as a Git-backeddraftfirst. - Every edit is recorded: Applied edits are indexed automatically so
/diffsshows recent changes and unified diffs at any time without spending tokens asking the model to re-read files. - Verification: The agent checks touched files with compiler-grade diagnostics (
lsp action=check) and runs builds/tests throughbuildor monitoredprocessruns. - You stay in control while it runs:
- Type a follow-up and press
Entermid-turn to queue it for the next turn (press↑on a blank prompt to edit your queued draft). - Press
Ctrl+Bto push a slow subagent or build to the background while you keep chatting. - Press
↓below the prompt to inspect live process logs or message a running subagent directly.
- Type a follow-up and press
- Automatic quota failover: If your active provider or account hits a quota wall before producing output, your configured
/model failoverladder automatically continues the turn on the next backup account or vendor — without overwriting your preferred primary model.
Step 4: Wrap-up, Judge check, auto-compaction & saving
Before handing control back to your prompt:
- Optional Judge audit: If enabled (
/judge), The Judge reviews the turn for unverified claims, skipped tests, or drift from your goal and feeds concrete corrections back before accepting completion. - Auto-compaction: On long sessions, Kompile automatically summarizes older turns before hitting the model's context ceiling (
/auto-compact), keeping your memories and active instructions intact. - Saved automatically: Your full transcript, tool-call journal, token/cost entries, file diffs, and any new memories are persisted locally under
~/.kompile/conversations/— immediately resumable from the terminal, browser (kompile chat --web), or another vendor.
3. Seeing tokens, cost, quota & tool calls at any step
Every model request and tool call is journaled as it happens. You don't have to wait until a session ends — stateless inspection commands run immediately even while a response is still streaming:
Always visible on screen
- Top bar: Shows live context-window usage (
ctx: 42k/200k) and session tokens (tok: 18.4k). - Results Sidebar & Activity Pane: Lists every tool call (
read,grep,edit,build, etc.), running build, and active subagent as it runs.
Check tokens, cash cost & subscription quotas anytime
Kompile separates pay-as-you-go API spend (PER_TOKEN) from subscription / coding-plan quotas (PLAN) — so Claude Pro or ChatGPT Plus logins never invent fake dollar bills, and unpriced models are flagged honestly instead of showing $0.00. Every priced request breaks down uncached input, cache write (5m vs. 1h TTL), cache read, and output tokens.
/cost # Last 24h: requests, tokens, USD spend, plan share
/cost session # Just this session (main thread + its subagents)
/cost session subagents # Subagent spend only in this session
/cost 7d models # 7-day breakdown grouped by model
/cost quota # Fitted quota-window share across subscription/plan routes
/usage # Live vendor account credits, 5h/7d quota meters, and reset times
/judge cost # Token and dollar overhead spent on Judge audits aloneInspect tool calls, exploration overhead & file edits anytime
/stats tools # Tool call counts, sizes, and payloads (filter: tool:read, session:ID)
/dashboard-tools # Most-called tools and output volume (spot noisy loops / oversized reads)
/dashboard-tokens # Token split between main thread and subagents
/subagent-breakdown # Recent subagents; `/subagent-breakdown <id>` shows startup/skills/tools/results tokens
/timeline # Chronological stream of prompts, tool calls, edits, and subagent events
/diffs # Recent file edits in this session with unified diffs(Outside chat, run kompile usage cost --window 24h, kompile usage cost --quota, or kompile stats from your shell, open the /insights tab in kompile chat --web, or let an agent inspect spend with the cost MCP tool. See Cost Estimation & Quota Attribution for full details.)
4. Queuing follow-up messages while the agent works (Chat Queue)
You never have to sit idle waiting for a long turn to finish before writing your next instruction — or stage a multi-step batch of follow-ups one by one. Kompile includes a disk-backed FIFO chat queue built directly into both the terminal and Web Harness.
How it works day to day
- Type and press
Enterwhile the agent is busy: Your message is immediately appended to the queue and appears in the Queue Pane below your prompt (with aQ:<n>counter in the status bar). - Edit before it sends (
↑arrow): Press↑on a blank prompt to pull the latest queued message back into your input box and edit it in place. While you are editing it, Kompile locks that item inEDITINGstate so auto-dequeue will never send a half-finished draft out from under you. - Stage a batch ahead of time: Even while idle, use
/queue <text>to line up several steps, reorder or tweak them, and let Kompile work through them sequentially. - Automatic or manual draining: Auto-dequeue is enabled by default — as soon as the current turn completes, Kompile automatically sends the next queued message in order (one turn at a time, never overlapping). Toggle
/auto-dequeueoff whenever you want to hold queued drafts and send them manually with/queue-sendor/queue-send-all. - Survives restarts & shared with Web / peer agents: Each session's queue is saved to
~/.kompile/queues/queue-<sessionId>.json(deduplicated and rolled back to the front if a dispatch fails), shared live withkompile chat --web(in the Session Configuration Queue section and/queue*commands), and also carries actionable peer mail from sibling agents working in the same repository.
/queue <text> # Add a message to the end of the queue
/queues # List all queued messages with their 8-char IDs
/queue-edit <id> <new text> # Edit a queued message in place (or press ↑ on a blank prompt)
/queue-move <id> <n> # Move a queued message to 1-based position n
/queue-remove <id> # Cancel one queued message
/queue-clear # Clear all queued messages
/queue-send [id] # Send the next queued message (or a specific ID) when idle
/queue-send-all # Drain all queued messages sequentially in order
/queue-status # Show queue depth and auto-dequeue state
/auto-dequeue # Toggle automatic sending at turn boundaries5. Everyday commands to know
| When you want to… | Run this |
|---|---|
| Start chatting (or open browser UI) | kompile chat / kompile chat --web |
| Resume your last chat or pick any chat | kompile chat --continue / kompile resume |
| Switch vendor, account, or model mid-chat | /auth (or /provider) · /model |
| Set up automatic backup vendors for quota limits | /model failover |
| Queue, edit, reorder, or drain follow-ups mid-turn | Type + Enter · ↑ to edit · /queues · /queue-move · /auto-dequeue |
| See tokens, spend, quota meters, or tool calls | /cost · /usage · /stats tools · /dashboard-tools · /subagent-breakdown |
| Check recent edits or what the agent remembers | /diffs · /memory · /recall <topic> |
| Free context tokens or reclaim disk space | /compact · /gc |
| Adjust display layout, guardrails, or subagents | /ui · /enforcer · /judge · /subagent-config |
Where to go next
- Standard Daily Workflow — Practical day-to-day routine: initializing a repo, watching
/cost&/usage, creating/skills, staging withdraft, and capping subagents. - Cost Estimation & Quota Attribution — How
PER_TOKENvs.PLANbilling, cache-write TTLs,ModelPriceCatalog, and fitted quota windows work. - Import, Resume & Vendor Switching — Resuming across all supported vendors (
claude,codex,agy,opencode, etc.) and switching vendors live mid-conversation. - Persistent Memory & Reminders — How
<memory_context>and<kompile_reminders>keep agents aligned across turns. - The Enforcer & The Judge — Pre-tool guardrails and post-turn quality/drift checks.
- How the Chat REPL Works — Under-the-hood architecture:
SetupWizard, session bootstrap, the six-stage agent execution loop, input routing, and crash-safe event wakes.