Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Token-Cost Prediction

PRECC ships a token-cost prediction oracle so multi-step plans can budget in tokens, not wall-clock time. Log a prediction before each step, record the actual after the work lands, and the dataset trains a built-in predictor that improves over time.

Log a prediction

Pass a one-line description of the planned step. PRECC categorises it (feat / fix / test / refactor / measurement / doc / chore / unknown), estimates a token count, and prints an id you will use to close the loop.

$ precc predict "Implement read-deltas with mtime check"
id=42 category=feat predicted=5680 tokens (confidence=0.50, model=trained-v1)
Record actual when done: precc predict --record 42 <actual_tokens>

Record the actual

After the step completes, look up the actual token count from your session footer or telemetry and pass it back via the id.

$ precc predict --record 42 6300
Recorded actual=6300 tokens for prediction id=42.

Train trained-v1

Once you have at least ten closed predictions, fit the trained-v1 ridge regression on log10(actual) against log10(description length) plus a one-hot category dummy. The fit is closed-form (Cholesky on the normal equations with ridge λ=1) and runs in milliseconds.

$ precc predict --train
Trained trained-v1 on 22 closed predictions (λ=1).
  Model file : ~/.local/share/precc/predict_model.json
  Confidence : 0.50
  Intercept  :  +1.0016
  log_desc   :  +1.2339
  Categories :
    unknown       +0.4811
    doc           +0.4474
    measurement   +0.3422
    test          +0.1071
    refactor      +0.0326
    feat          +0.0071
    fix           -0.1096
    chore         -0.3063

After training, every new precc predict call uses trained-v1 automatically until you remove or replace the model file. Old predictions keep their original model_version so you can compare predictors over time.

Inspect predictor accuracy

precc predict --eval reports the mean absolute percentage error overall and per category, computed only over closed predictions (rows with both predicted and actual values).

$ precc predict --eval
Predictions logged   : 30
With actuals (closed): 22
Mean predicted       :     1483 tokens
Mean actual          :    47238 tokens
MAPE (statistical)   :     76.4%

By category:
  category        n   predicted      actual    MAPE
  feat            6        4605        5250   26.2%
  unknown         4        1597       30526   52.6%
  test            4         924       38900   56.4%
  ...

List recent predictions

precc predict --list shows recent rows in reverse chronological order. Open rows (no actual) are ready to be closed.

$ precc predict --list --limit 5
id    ts                   category       predicted     actual  conf description
30    2026-05-09 09:40:51  feat                5348          -  0.50 Run the synthetic-fleet pilot...
29    2026-05-09 08:56:48  test                1050          -  0.60 Train predictor: trained-v1...
28    2026-05-09 07:44:18  test                 915     150000  0.60 Implement minimal task-12...

Why tokens, not wall-clock time

Time estimates are unmeasurable post-hoc and do not compose across machines or sessions. Token counts are deterministic, comparable, and grow a labelled dataset that improves the predictor with every closed loop. The whole point of the oracle is to convert estimation from a guessing game into a measurement.

Where data lives

All prediction data is stored locally on your machine. Nothing is uploaded.

~/.local/share/precc/
├── metrics.db                — predictions table (oracle DB)
└── predict_model.json        — trained-v1 coefficients (after `--train`)