Token optimization

  1. caveman — terse output
  2. rtk — CLI-output filtering
  3. Graph + RAG retrieval instead of reading files
  4. Model routing — cheap/local for easy work
  5. Measure first

Context is the budget. aiflow attacks token cost from four directions — the first two are on by default. Prefer full, unfiltered output instead? Initialise or reconfigure with aiflow init --no-token-saving / aiflow change-settings --no-token-saving — it switches caveman and rtk off in one go.

Honest expectation: aiflow’s quality rules (tests, coverage gates, static analysis, architect review) deliberately spend tokens on getting things right — so per-task savings are only partial. The net win is that a requirement implemented production-ready on the first pass needs no re-prompting, no re-sharpening, and no rework: that saves more tokens and time than any filter.

caveman — terse output

A compressed output mode: the agent drops filler and speaks tersely. ~75% fewer output tokens; code, commits, and security warnings stay in full prose. Toggle in .aiflow/config.json (caveman.enabled, caveman.mode: full|lite|ultra).

rtk — CLI-output filtering

Verbose command output (installs, test runs, build logs) is filtered/compressed before it enters context — errors and diffs are preserved, noise is trimmed. Typically 60–90% fewer tokens on noisy commands. Enabled per project by aiflow.

Graph + RAG retrieval instead of reading files

The biggest silent cost is re-reading whole files. aiflow routes questions through the code memory: graphify (structure) and cocoindex-code (semantic RAG, ~70% fewer tokens than opening files). The agent locates the few relevant chunks, then opens only those.

Model routing — cheap/local for easy work

Send trivial/background steps to cheaper or local Ollama models via claude-code-router, keeping top Claude models for hard reasoning:

aiflow shell --router

See Models & context7.

Measure first

aiflow cost      # ccusage: real token/cost baseline

Optimise what the numbers show, not what you guess. Combined, these routinely cut total token spend by a large multiple on real projects.


aiflow · MIT License · Copyright (c) 2026 Cyber93de. aiflow is an independent integration and is not affiliated with the projects it builds on (Claude Code, Beads, graphify, CocoIndex, Context7, Ollama, rtk, and others).

This site uses Just the Docs, a documentation theme for Jekyll.