Skip to content

⚡ Claude Token Optimization2026-07-17 — smoke-claude #6319

Description

@github-actions

Target Workflow: smoke-claude

Source report: No claude-token-usage-report issue found (gh CLI not authenticated in this environment)
Estimated cost per run: ~$0.049 USD (49 AIC)
Total tokens per run: ~4,084
Cache read rate: N/A (usage-only artifact; no per-turn breakdown available)
Cache write rate: N/A
LLM turns: 1 (prompt is pre-computed; agent reads JSON and calls safeoutputs)

Current Configuration

Setting Value
Tools loaded 1: bash only
Tools actually used 1: bash (reads pre-computed JSON)
Network groups None (github: false)
Pre-agent steps Yes (5 steps)
Prompt size ~2,300 chars
Model claude-haiku-4-5
max-turns 8

Observations

This workflow is already well-optimized:

  • ✅ Uses only bash tool — minimal tool surface
  • github: false — eliminates ~22 GitHub MCP tool schemas (~15K tokens)
  • ✅ 5 pre-agent steps: pre-compute all deterministic work (API data, reachability check, result JSON)
  • ✅ Agent has one clear task: read /tmp/gh-aw/agent/final-result.json and call safeoutputs
  • ✅ Haiku model — lowest cost Claude tier
  • ⚠️ max-turns: 8 is set but only 1 turn is needed; agent completes in a single turn

Recommendations

1. Reduce max-turns from 8 to 2

Estimated savings: No token savings, but reduces maximum possible runaway cost by 75%.

The prompt instructs "After calling safeoutputs, stop immediately." With all data pre-computed and a clear single-step task, 1 turn is always sufficient. Setting max-turns: 2 provides a safety buffer while preventing any runaway multi-turn loops.

# Change in smoke-claude.md:
max-turns: 2  # was: 8

2. Reduce Prompt Verbosity (~500 tokens)

Estimated savings: ~500–800 tokens/run (~12–20%)

The prompt body contains detailed instructions about safeoutputs calling conventions that repeat information already enforced by the safe-outputs schema. The "pass arguments inline as a single JSON object" paragraph and the "Never call add_comment or add_labels with empty arguments" warning add ~300 chars but are scaffolding reminders rather than task logic.

Suggested minimal prompt:

# Smoke Test: Claude Engine Validation

Run: ${{ github.run_id }}

Read `/tmp/gh-aw/agent/final-result.json` (one bash call).

The JSON has: `result` (PASS/FAIL), `api_status`, `gh_check`, `file_status`, `event`, `pr_number`.

If `event` is `pull_request`: call `add_comment` with `item_number: pr_number` and a body listing each check result, then call `add_labels` with `["smoke-claude"]` only if `result` is `PASS`.

Otherwise: call `noop` with the result summary.

This cuts ~800 chars (~200 tokens) without losing task clarity.

3. High GH API Call Variance on Schedule Events

Observed: Schedule-triggered runs show 12–16 GH API calls vs 4–5 for PR-triggered runs.

This is likely the pre-agent gh pr list step fetching more data on schedule triggers (no PR context). This is pre-agent work (not agent LLM tokens), but the higher call count on schedule events is worth investigating. If gh pr list is returning more results on schedule events, consider --limit 1 instead of --limit 2, or caching the PR list result.

Cache Analysis

No per-turn token breakdown is available (only usage artifact was downloaded). To get Anthropic-specific cache write/read data, rerun with --artifacts all:

gh aw logs download --run-id <RUN_ID> --artifacts all

Haiku with a ~4K token context is unlikely to benefit significantly from prompt caching (cache writes cost 25× cache reads on Anthropic). Given the single-turn pattern, cache writes are not reused across turns, making caching a net cost increase.

Expected Impact

Metric Current Projected Savings
Total tokens/run ~4,084 ~3,300 -~19%
Cost/run (AIC) ~49 ~40 -~18%
LLM turns 1 1 0
Max-turns cap 8 2 -75% runaway risk
Session time ~4.8m ~4.5m (est.) -~6%

Implementation Checklist

  • Reduce max-turns: 8max-turns: 2 in .github/workflows/smoke-claude.md
  • Trim prompt body (remove safeoutputs calling-convention boilerplate)
  • Recompile: gh aw compile .github/workflows/smoke-claude.md
  • Post-process: npx tsx scripts/ci/postprocess-smoke-workflows.ts
  • Verify CI passes on PR
  • Compare token usage on new run vs baseline

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Daily Claude Token Optimization Advisor · 42.8 AIC · ⊞ 6.3K ·

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions