rajatslakhina

Token Trace Kit — AI skill for Claude Code

AI community

Tap-to-token tracing for hybrid on-device + Claude AI features in Swift 6: W3C propagation, device-side tail sampling, default-deny PII redaction, cost per feature, clock-skew correction, offline expo.

How to install Token Trace Kit

This entry records only its repository, not the path inside it, so there is no exact command to give. Open rajatslakhina/token-trace-kit and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Token Trace Kit does

Tap-to-token tracing for hybrid on-device + Claude AI features in Swift 6: W3C propagation, device-side tail sampling, default-deny PII redaction, cost per feature, clock-skew correction, offline export buffer.

Alternatives in AI

  • Axonhub — ⚡️ Open-source AI Gateway — Use any SDK to call 100+ LLMs 3.2k ★
  • DontFeedTheAI — Transparent anonymization proxy for AI-assisted pentesting 654 ★
  • Dsh Auto Review — Second-model AI auto-review for DeepSeek Harness approval requests: a read-only reviewer subagent returns stru 155 ★

README

TokenTrace

**One trace from tap to token: the user's tap, the on-device model, your proxy and the Claude API call, on one clock, with no prompt text in any of it.**

Your AI feature is now four systems. The tap happens in SwiftUI. The first attempt runs on-device. When the model refuses or the device can't run it, the request goes through your backend proxy to a vendor model. On 14 Oct 2026 the Claude Platform launched [OpenTelemetry export in beta](https://platform.claude.com/docs/en/release-notes/overview) for Messages API requests, so the vendor side can now land in the same backend as yours. That only helps if the four halves join into one trace, and on a phone they usually don't. The clock is wrong by seconds. The traces you need (refusals, fallbacks, timeouts) are the ones a 5% head sampler throws away. And the obvious attribute to add while debugging is the prompt.

TokenTrace is a Swift 6 library for the client half of that problem: W3C trace propagation, tail sampling on the device, default-deny redaction, cost attribution per feature, clock-skew correction and a bounded offline export buffer. It has no dependencies and runs on iOS, macOS and Linux.

**Demo app:** [token-trace-demo-app](https://github.com/rajatslakhina/token-trace-demo-app). Tap once and see the tap, the on-device refusal, the proxy and the Claude call as one 5-span waterfall on the server's clock. Then flip *Show without skew correction* and watch the proxy span jump in front of the request that caused it.


Why this matters

Distributed tracing on the server is a solved problem. On a phone, the four assumptions it rests on are all false:

Server assumption On a phone What TokenTrace does
Clocks are NTP-synced to milliseconds The device clock is off by seconds and can jump mid-request Durations use the monotonic clock only. A four-timestamp (NTP-style) estimate from your own proxy's responses, anchored to the monotonic clock, moves exported timestamp