# CTX-001: 컨텍스트 트래커 정확한 추정 — Task Breakdown

Spec: `.agents/spec-docs/done/CTX-001-context-tracker-accurate-estimate.md`

## Plan

- [x] TC-01: terminal provider usage → `getContextState().usedTokens` reflects the provider total
- [x] TC-02: no provider usage on latest message → serialized fallback (existing behavior preserved)
- [x] TC-03: tracker imports/uses `estimateContextTokensFromMessages` (not `estimateSerializedContextTokens`)
- [x] TC-04: agent-session build + test + `pnpm typecheck` + `harness:scan` pass
- [x] swap import + `updateFromHistory` to the accurate shared estimator

## Test Plan

`ContextWindowTracker.updateFromHistory` now uses `estimateContextTokensFromMessages(history).usedTokens`
— the same accurate estimator the core execution guards use — instead of the crude
`estimateSerializedContextTokens` (history-JSON char heuristic that excluded the system prompt + tool
schemas and the provider's real token counts). This fixes the under-reported `Context` display and
aligns session auto-compact with the core guards (new count ≥ old → compaction can only trigger earlier,
never later; no overflow risk). Verified by unit tests (provider-based reflection + serialized fallback),
an import-swap check, and build/test/typecheck/scan. `Usage` (cumulative billed input across the turn's
agentic rounds) remains a distinct, legitimately larger metric than `Context` (current window occupancy).
