Skip to content

⚡ Claude Token Optimization2026-08-29 — Smoke Claude #7851

Description

@github-actions

Target Workflow: Smoke Claude (.github/workflows/smoke-claude.lock.yml)

Source report: No open claude-token-usage-report issue was accessible to this run (query returned 0 readable results), so this analysis is based directly on /tmp/gh-aw/token-audit/claude-logs.json (last 7 days, 5 runs).

Total tokens per run: ~5.06K avg (range 4,953–5,099)
AIC (relative cost score) per run: ~41.3 avg (total 206.3 / 5 runs)
LLM turns: not exposed in the log export (total_turns: 0 in summary — turn counts weren't captured for this workflow's runs); target per the workflow's own post-step comment is 1 turn
Model: claude-haiku-4-5 (already the cheapest Claude tier)
Cache read/write rate: not present in the available run-log fields — Anthropic per-turn cache breakdown wasn't captured for this workflow, so no cache table can be produced (see note in Cache Analysis below)

Current Configuration

Setting Value
Tools loaded 1 (bash: [bash]); github: false
Tools actually used bash (single cat of pre-computed JSON), plus safeoutputs add_comment/add_labels/noop
网络 groups none configured (network: key absent) — agent has no outbound HTTP tool surface; the only external call (curl https://github.com) runs in a pre-agent step, not inside the agent sandbox
Pre-agent steps Yes — 5 steps: smoke-test file creation, gh pr list fetch, GitHub.com reachability check, file verification, and final JSON result computation
Prompt size ~1,000 chars (very short: reads one file, branches on one JSON value)

Assessment

This workflow is already close to optimal for a Claude-engine smoke test:

  • github: false avoids loading the ~22-tool default GitHub toolset (~10K+ tokens/turn saved already).
  • All non-deterministic work (API calls, curl checks, JSON assembly) is pre-computed in steps: before the agent runs — there is nothing left for the agent to fetch or reason about.
  • threat-detection.enabled: false avoids an extra LLM safety-classification call.
  • Model is already the cheapest available (claude-haiku-4-5).
  • Average token usage (~5K/run) is low in absolute terms compared to typical Claude-engine workflows.

Because of this, the improvements available are incremental rather than structural. Recommendations below are ordered by estimated impact, but all are modest since the workflow is already well-optimized.

Recommendations

1. Reduce max-turns from 8 to 2

Estimated savings: protects against runaway turns; low direct savings in the common case (~0K tokens/run today since runs already complete in the intended 1 turn), but caps worst-case token spend if the agent ever loops or retries a rejected add_comment/add_labels call.

max-turns: 2

The workflow's own post-step already asserts "target: 1" turn. A max-turns: 8 ceiling allows up to 8x the intended token spend if something goes wrong (e.g., a malformed tool call retry loop). Lowering the ceiling to 2 preserves one retry margin while bounding worst-case cost.

2. Drop the bash tool if the cat step can be replaced by prompt-embedded content

Estimated savings: ~500–700 tokens/turn (one tool schema)

The agent's only bash usage is cat /tmp/gh-aw/agent/final-result.json. Since this file is already produced by a pre-agent step, its contents could instead be interpolated directly into the prompt body via templating (e.g. an env-based {{#runtime-import}} or expression), removing the need to expose the bash tool schema entirely. Only remove this if bash isn't needed for anything else — confirm no other implicit bash usage before removing.

tools:
  github: false
# bash: removed — final-result.json content injected directly into the prompt instead

3. Capture per-turn cache and turn-count metrics for this workflow

Estimated savings: not a token savings, but required to validate future optimizations

The available claude-logs.json export has total_turns: 0 and no cache read/write breakdown for Smoke Claude runs, so this analysis cannot produce the Cache Analysis table requested by the standard report format. Recommend ensuring the Claude engine's per-turn usage (cache_read_input_tokens, cache_creation_input_tokens, turn count) is captured in the log aggregation pipeline so future optimization passes have real cache-hit data instead of only a single token_usage total per run.

Cache Analysis (Anthropic-Specific)

Cache read/write breakdown by turn is not available in the current log export for this workflow (only aggregate token_usage and aic per run were captured; total_turns: 0). No cache table can be produced without this data — see Recommendation 3.

Expected Impact

Metric Current Projected Savings
Total tokens/run ~5.06K ~4.4–4.9K (best case, tool removed) ~3–13%
AIC/run ~41.3 ~36–40 ~3–13%
LLM turns (ceiling) 8 2 -6 (worst-case bound only)
Session time avg ~5.4 min ~unchanged ~0%

Implementation Checklist

  • Lower max-turns: 8max-turns: 2 in .github/workflows/smoke-claude.md
  • Evaluate whether the bash tool can be removed by inlining final-result.json into the prompt via templating
  • Add per-turn cache/turn-count capture to the token-usage log aggregation pipeline so future passes can produce real cache analysis
  • Recompile: gh aw compile .github/workflows/smoke-claude.md
  • Post-process: npx tsx scripts/ci/postprocess-smoke-workflows.ts
  • Verify CI passes on PR
  • 比较 token usage on new run vs baseline (~5.06K tokens/run)

Generated by Daily Claude Token Optimization Advisor · copilot · auto · 35.2 AIC · ⊞ 10.6K ·

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    项目

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions