|
| 1 | +# Amp CLI Notes |
| 2 | + |
| 3 | +## Log Sources |
| 4 | + |
| 5 | +- Amp session usage is recorded under `${AMP_DATA_DIR:-~/.local/share/amp}/threads/` (the CLI resolves `AMP_DATA_DIR` and falls back to `~/.local/share/amp`). |
| 6 | +- Each thread is stored as a JSON file (not JSONL) named `T-{uuid}.json`. |
| 7 | +- Token usage is extracted from the `usageLedger.events[]` array in each thread file. |
| 8 | +- Cache token information (creation/read) is extracted from `messages[].usage` for detailed breakdown. |
| 9 | + |
| 10 | +## Token Fields |
| 11 | + |
| 12 | +- `inputTokens`: total input tokens sent to the model. |
| 13 | +- `outputTokens`: output tokens (completion text). |
| 14 | +- `cacheCreationInputTokens`: tokens used for cache creation (from message usage). |
| 15 | +- `cacheReadInputTokens`: tokens read from cache (from message usage). |
| 16 | +- `totalTokens`: sum of input and output tokens. |
| 17 | + |
| 18 | +## Credits |
| 19 | + |
| 20 | +- Amp uses a credits-based billing system in addition to standard token counts. |
| 21 | +- Each usage event includes a `credits` field representing the billing cost in Amp's credit system. |
| 22 | +- Credits are displayed alongside USD cost estimates in reports. |
| 23 | + |
| 24 | +## Cost Calculation |
| 25 | + |
| 26 | +- Pricing is pulled from LiteLLM's public JSON (`model_prices_and_context_window.json`). |
| 27 | +- Amp primarily uses Anthropic Claude models (Haiku, Sonnet, Opus variants). |
| 28 | +- Cost formula per model: |
| 29 | + - Input: `inputTokens / 1_000_000 * input_cost_per_mtoken` |
| 30 | + - Cached input read: `cacheReadInputTokens / 1_000_000 * cached_input_cost_per_mtoken` |
| 31 | + - Cache creation: `cacheCreationInputTokens / 1_000_000 * cache_creation_cost_per_mtoken` |
| 32 | + - Output: `outputTokens / 1_000_000 * output_cost_per_mtoken` |
| 33 | + |
| 34 | +## CLI Usage |
| 35 | + |
| 36 | +- Treat Amp as a sibling to `apps/ccusage`, `apps/codex`, and `apps/opencode`. |
| 37 | +- Reuse shared packages (`@ccusage/terminal`, `@ccusage/internal`) wherever possible. |
| 38 | +- Amp is packaged as a bundled CLI. Keep every runtime dependency in `devDependencies`. |
| 39 | +- Entry point uses Gunshi framework with subcommands: `daily`, `monthly`, `session`. |
| 40 | +- Data discovery relies on `AMP_DATA_DIR` environment variable. |
| 41 | +- Default path: `~/.local/share/amp`. |
| 42 | + |
| 43 | +## Available Commands |
| 44 | + |
| 45 | +- `ccusage-amp daily` - Show daily usage report |
| 46 | +- `ccusage-amp monthly` - Show monthly usage report |
| 47 | +- `ccusage-amp session` - Show usage by thread (session) |
| 48 | +- Add `--json` flag for JSON output format |
| 49 | +- Add `--compact` flag for compact table mode |
| 50 | + |
| 51 | +## Testing Notes |
| 52 | + |
| 53 | +- Tests rely on `fs-fixture` with `using` to ensure cleanup. |
| 54 | +- All vitest blocks live alongside implementation files via `if (import.meta.vitest != null)`. |
| 55 | +- Vitest globals are enabled - use `describe`, `it`, `expect` directly without imports. |
| 56 | +- **CRITICAL**: NEVER use `await import()` dynamic imports anywhere, especially in test blocks. |
| 57 | + |
| 58 | +## Data Structure |
| 59 | + |
| 60 | +Amp thread files have the following structure: |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "id": "T-{uuid}", |
| 65 | + "created": 1700000000000, |
| 66 | + "title": "Thread Title", |
| 67 | + "messages": [ |
| 68 | + { |
| 69 | + "role": "assistant", |
| 70 | + "messageId": 1, |
| 71 | + "usage": { |
| 72 | + "model": "claude-haiku-4-5-20251001", |
| 73 | + "inputTokens": 100, |
| 74 | + "outputTokens": 50, |
| 75 | + "cacheCreationInputTokens": 500, |
| 76 | + "cacheReadInputTokens": 200, |
| 77 | + "credits": 1.5 |
| 78 | + } |
| 79 | + } |
| 80 | + ], |
| 81 | + "usageLedger": { |
| 82 | + "events": [ |
| 83 | + { |
| 84 | + "id": "event-uuid", |
| 85 | + "timestamp": "2025-11-23T10:00:00.000Z", |
| 86 | + "model": "claude-haiku-4-5-20251001", |
| 87 | + "credits": 1.5, |
| 88 | + "tokens": { |
| 89 | + "input": 100, |
| 90 | + "output": 50 |
| 91 | + }, |
| 92 | + "operationType": "inference", |
| 93 | + "fromMessageId": 0, |
| 94 | + "toMessageId": 1 |
| 95 | + } |
| 96 | + ] |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +## Environment Variables |
| 102 | + |
| 103 | +- `AMP_DATA_DIR` - Custom Amp data directory path (defaults to `~/.local/share/amp`) |
| 104 | +- `LOG_LEVEL` - Control logging verbosity (0=silent, 1=warn, 2=log, 3=info, 4=debug, 5=trace) |
0 commit comments