Environment variables, runtime tuning, session storage, and token cost. For API key setup, see Getting Started. A complete example session log is available in the repository at docs/sample-session.jsonl.

Agent & TUI Tuning Variables

These variables can be set in your shell or prepended to a command to adjust Book’s runtime behaviour without touching any config file.

Variable Description Default

BOOK_MAX_TURNS

Maximum agent loop iterations (tool-call turns) per run before the loop stops with an error.

200

BOOK_MAX_UNPRODUCTIVE_TURNS

Maximum consecutive unproductive turns (all tool results errored and no assistant text) before the loop stops early.

3

BOOK_DISABLE_PRUNING

Set to true or 1 to send the full raw message history to the provider on every turn, skipping all pruning and proactive compaction. Useful for debugging.

off

BOOK_CACHE_MAX_TURN_AGE

Number of agent turns a read_file / grep / ls cache entry remains live before it is eagerly evicted.

5

BOOK_HIDE_TOOL_RESULTS

Comma-separated list of tool names whose result panels are hidden from the TUI centre-panel (e.g. read_file,grep). Results are still sent to the LLM; only the display is suppressed.

(none)

# Example: cap at 50 turns, hide noisy read_file panels
export BOOK_MAX_TURNS=50
export BOOK_HIDE_TOOL_RESULTS=read_file,grep

Session JSONL & Token Usage / Cost

Each Book session is stored as a newline-delimited JSON (JSONL) file under ~/.bk/agent/sessions/. Every assistant message persisted to disk carries a usage object that records token counts and computed cost for that turn.

JSONL usage field layout

{
  "type": "assistant",
  "model": "claude-sonnet-4-6",
  "usage": {
    "input":         1024,
    "output":         256,
    "cacheRead":        0,
    "cacheCreation":    0,
    "totalTokens":   1280,
    "cost": {
      "input":    0.000307,
      "output":   0.000384,
      "cacheRead":    0.0,
      "cacheWrite":   0.0,
      "total":    0.000691
    }
  },
  ...
}

Note on field names: The serialized JSONL uses cacheCreation (not cacheWrite) for cache-write token counts โ€” matching the AgentsView v0.26.1 Pi parser field convention. Inside Kotlin code the property is still named cacheWrite.

Cost computation

Token costs are computed automatically from an internal per-model pricing table shipped with Book. When the active model is recognized:

  • cost.input โ€” input tokens ร— input rate

  • cost.output โ€” output tokens ร— output rate

  • cost.cacheRead โ€” cache-read tokens ร— cache-read rate

  • cost.cacheWrite โ€” cache-creation tokens ร— cache-creation rate

  • cost.total โ€” sum of all four fields

For unrecognized or zero-priced models, all cost fields remain 0.0. Token counts are always present regardless of whether pricing data is available.

Accessing usage/cost in extensions

Extension scripts registered via .bk.kts see the same computed values through event payloads โ€” no additional parsing of JSONL is needed:

// Read per-turn usage & cost from BookEvent.TurnEnd
registerEventHandler(BookEvent.TurnEnd::class) { event, ctx ->
    val totalTokens = event.message.usage.totalTokens
    val costUsd     = event.message.usage.cost.total
    ctx.displayMessage("[Usage] tokens=$totalTokens cost=\$${"%.6f".format(costUsd)}")
}

// Aggregate across all turns via BookEvent.AgentEnd
registerEventHandler(BookEvent.AgentEnd::class) { event, ctx ->
    val totalCost = event.messages
        .filterIsInstance<AssistantMessage>()
        .sumOf { it.usage.cost.total }
    ctx.displayMessage("[Usage] run cost=\$${"%.6f".format(totalCost)}")
}

See the Extension API Guide for full Usage and Cost field references, and the cost-tracker.bk.kts example.

LLM Reasoning & Thinking Modes (ADR-20261002)

Book supports interacting with advanced LLMs (such as OpenAI reasoning models and Anthropic Claude models) featuring built-in thinking and reasoning capabilities.

Controlling Reasoning Effort

  1. Startup Flag (--effort) & Saved Config: Pass --effort <level> when launching Book (bk --effort high), taking explicit precedence over replayed historical session logs or saved configuration. Unless --no-save-effort is passed, --effort persists the specified level as the global default in book.json and prints a confirmation notice.

  2. Slash Commands (/effort & /effort-default): Type /effort [level] or /effort-default <level> in the TUI:

    • /effort high โ€” sets reasoning effort level for the active session only (session-scoped; zero configuration file writes).

    • /effort-default high โ€” sets reasoning effort level and saves it as the global default in book.json.

    • /effort (bare) โ€” in the TUI, opens an interactive modal effort selection screen initialized to the current active reasoning effort. The selection screen hint bar displays selection controls and mentions /effort-default <level> for saving global defaults.

  3. Keyboard Shortcut (Ctrl+Shift+E): Press Ctrl+Shift+E in the TUI to quickly cycle through effort levels. If pressed on a non-reasoning model, a notice Reasoning effort not applied (note: current model does not support reasoning) is displayed.

  4. ACP Session Initialization (_meta): ACP IDE clients (such as Xcode) can pass book.effort in the session/new or session/load _meta payload:

json { "_meta": { "book.effort": "high" } } ` When loading a session without `book.effort in _meta, the reasoning level recorded in session history is restored. If book.effort is supplied in _meta, it overrides the historical level. If neither _meta nor history specifies a reasoning level, the session is materialized with the current global default (EffortLevel.DEFAULT or startup --effort). Each ACP session stores its effort in sessionEffort independently so concurrent sessions remain isolated.