Configuration
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 |
|---|---|---|
|
Maximum agent loop iterations (tool-call turns) per run before the loop stops with an error. |
|
|
Maximum consecutive unproductive turns (all tool results errored and no assistant text) before the loop stops early. |
|
|
Set to |
off |
|
Number of agent turns a |
|
|
Comma-separated list of tool names whose result panels are hidden from the TUI centre-panel (e.g. |
(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(notcacheWrite) for cache-write token counts โ matching the AgentsView v0.26.1 Pi parser field convention. Inside Kotlin code the property is still namedcacheWrite.
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
-
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-effortis passed,--effortpersists the specified level as the global default inbook.jsonand prints a confirmation notice. -
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 inbook.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.
-
-
Keyboard Shortcut (
Ctrl+Shift+E): PressCtrl+Shift+Ein the TUI to quickly cycle through effort levels. If pressed on a non-reasoning model, a noticeReasoning effort not applied (note: current model does not support reasoning)is displayed. -
ACP Session Initialization (
_meta): ACP IDE clients (such as Xcode) can passbook.effortin thesession/neworsession/load_metapayload:
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.