Skip to content

[copilot-token-optimizer] CLI Consistency Checker - Token Optimization (2.5M-3.2M tokens/run savings) #33338

@github-actions

Description

@github-actions

Target Workflow

Workflow: CLI Consistency Checker
Selected: Highest token usage in 7-day window (4.13M tokens)
Analysis period: 2026-05-13 to 2026-05-19 (7 days)
Runs analyzed: 1 run (§26102456365)
Not recently optimized: Last optimization was 2026-05-06 (different workflows)

Why selected: This workflow consumes 4.13M tokens per run despite being a read-only inspection task that only creates one issue. Agentic assessments flag it as "resource_heavy_for_domain" with 50% of turns being data-gathering work that could move to deterministic pre-agent steps.


Token Profile Summary

Metric Value
Total tokens 4,129,650
Effective tokens 27,770,906 (includes cache reads)
Cache read tokens 3,626,013 (88.8% of input)
Output tokens 45,411
Turns 69
Action minutes 15
Avg tokens/turn 59,851
Cache efficiency 88.8%
Conclusion Success (no errors)

Ranked Recommendations

1. Move CLI Data Collection to Pre-Agent Steps ⭐⭐⭐

Estimated savings: 2,000,000-2,500,000 tokens/run (60% reduction)
Effort: Medium
Risk: Low

Evidence: The workflow spends 69 turns executing CLI commands and collecting help output. Agentic assessment reports "partially_reducible" with 50% of turns being data-gathering that could move to deterministic steps.

Action: Add pre-agent: steps to build CLI and collect all --help output before agent starts:

pre-agent:
  - name: Build CLI and collect help output
    run: |
      cd /home/runner/work/gh-aw/gh-aw
      make build
      mkdir -p /tmp/gh-aw/agent/help-output
      ./gh-aw --help > /tmp/gh-aw/agent/help-output/main.txt
      # Collect all command help
      for cmd in $(./gh-aw --help | grep -E '^\s+\w+' | awk '{print $1}'); do
        ./gh-aw $cmd --help > /tmp/gh-aw/agent/help-output/${cmd}.txt 2>&1 || true
      done
      # Collect all help into one file
      cat /tmp/gh-aw/agent/help-output/*.txt > /tmp/gh-aw/agent/all-help.txt

Prompt change: Replace "Step 1: Build and Verify the CLI" and "Step 2: Run ALL CLI Commands with --help" with:

"All CLI help output has been pre-collected in /tmp/gh-aw/agent/all-help.txt (1,742 lines, 55 commands). Read this file to analyze command consistency."

Expected outcome: Reduces from ~69 turns to ~10-15 turns (agent only analyzes, doesn't execute)


2. Remove Unused Tools ⭐⭐

Estimated savings: 150,000-200,000 tokens/run (ambient context reduction)
Effort: Low
Risk: Very low

Evidence: MCP tool usage logs show only 1 tool call: safeoutputs.create_issue. The workflow configures cli-proxy, edit, and web-fetch but never uses them.

Configured tools:

  • cli-proxy: true0 calls (never used)
  • edit: {}0 calls (workflow is read-only)
  • web-fetch: {}0 calls (no external fetching)
  • bash: ["*"] → Used for CLI execution ✅

Action: Remove from frontmatter:

tools:
  cli-proxy: true  # ❌ Remove - never used
  edit:            # ❌ Remove - never used (read-only workflow)
  web-fetch:       # ❌ Remove - never used
  bash:            # ✅ Keep - needed for CLI execution
    - "*"

Expected outcome: Reduces ambient context size by ~150K-200K tokens/run


3. Reduce Network Access Scope ⭐

Estimated savings: 50,000-75,000 tokens/run
Effort: Low
Risk: Very low

Evidence: Network configuration allows [defaults, node, "api.github.com", "proxy.golang.org", "sum.golang.org"] but the workflow is purely local CLI inspection — no network calls observed.

Action: Reduce network scope:

network:
  allowed: [defaults]  # Remove: node, api.github.com, proxy/sum.golang.org

Expected outcome: Reduces network policy ambient context


4. Streamline Prompt Structure ⭐⭐

Estimated savings: 300,000-500,000 tokens/run
Effort: Medium
Risk: Low

Evidence: Prompt is 310 lines with 29 section headers. Includes 4 agent delegation sections (help-style-checker, help-text-typo-scanner, docs-cross-referencer, flag-consistency-checker) that are never used — workflow runs as single agent.

Action:

  1. Remove agent delegation sections (~50 lines, ~10K tokens)

    • ## agent: help-style-checker
    • ## agent: help-text-typo-scanner
    • ## agent: docs-cross-referencer
    • ## agent: flag-consistency-checker
  2. Consolidate step instructions (reduce from 29 sections to ~10)

    • Merge "Step 3" subsections into concise bullet points
    • Remove redundant examples in "Step 4: Report Findings"
  3. Simplify issue format template (trust agent formatting)

    • Keep high-level structure guidance
    • Remove detailed markdown examples
  4. Trust agent to discover commands (remove explicit enumeration)

    • Remove "Main Help", "All Commands", "MCP Subcommands" subsections under Step 2

Expected outcome: Reduces prompt from 310 lines to ~150-180 lines while maintaining clarity


Total Estimated Savings

Scenario Savings New Tokens/Run Reduction
Conservative 2,500,000 1,629,650 60%
Optimistic 3,200,000 929,650 78%

Implementation Priority

Phase 1 — Quick Wins (1 week)

Phase 2 — High Impact (2 weeks)

  • Add pre-agent data collection steps (Recommendation rejig docs #1)
  • Expected savings: 2,000,000-2,500,000 tokens/run

Phase 3 — Polish (1 week)


Caveats

  1. Single run sample: Only 1 run available in 7-day window — patterns may vary across multiple runs
  2. Workflow frequency: Runs weekdays only (~5 runs/week) — total weekly impact is moderate
  3. Pre-agent execution time: May add 30-60s to workflow duration for CLI build and help collection
  4. Prompt changes: Validate output quality with test run after streamlining prompt structure

Supporting Data - Configured vs Used Tools

Frontmatter configuration (.github/workflows/cli-consistency-checker.md):

tools:
  cli-proxy: true
  edit:
  web-fetch:
  bash:
    - "*"
network:
  allowed: [defaults, node, "api.github.com", "proxy.golang.org", "sum.golang.org"]

MCP tool usage (from run 26102456365 logs):

{
  "summary": [
    {
      "server_name": "safeoutputs",
      "tool_name": "create_issue",
      "call_count": 1,
      "total_input_size": 0,
      "total_output_size": 0
    }
  ],
  "servers": [
    {
      "server_name": "safeoutputs",
      "request_count": 1,
      "tool_call_count": 1
    }
  ]
}

Tools never called: cli-proxy (0), edit (0), web-fetch (0)

Supporting Data - Agentic Assessments

Assessment 1 - Resource Heavy:

{
  "kind": "resource_heavy_for_domain",
  "severity": "high",
  "summary": "This General Automation run consumed a heavy execution profile for its task shape.",
  "evidence": "turns=69 tool_types=0 duration=14m8s write_actions=0",
  "recommendation": "Compare this run to similar successful runs and trim unnecessary turns, tools, or write actions."
}

Assessment 2 - Partially Reducible:

{
  "kind": "partially_reducible",
  "severity": "low",
  "summary": "About 50% of this run's turns appear to be data-gathering that could move to deterministic steps.",
  "evidence": "agentic_fraction=0.50 turns=69",
  "recommendation": "Move data-fetching work to frontmatter steps: (pre-agent) writing to /tmp/gh-aw/agent/ or post-steps: (post-agent) to reduce inference cost. See the DeterministicOps guide."
}

Supporting Data - Prompt Structure

Current prompt statistics:

  • Total lines: 310
  • Total words: 1,285
  • Sections (##): 29
  • Subsections (###): Multiple nested levels

Section breakdown:

  1. Critical Requirement
  2. Step 1: Build and Verify the CLI
  3. Step 2: Run ALL CLI Commands with --help (with 3 subsections)
  4. Step 3: Check for Consistency Issues (with 5 subsections)
  5. Step 4: Report Findings (with 10+ nested subsections)
  6. Step 5: Summary
  7. Security Note
  8. Remember
  9. 4 agent delegation sections (unused)

Recommendation: Consolidate to ~8-10 top-level sections without deep nesting


References:

Generated by ⚡ Copilot Token Usage Optimizer · ● 9.8M ·

To install this agentic workflow, run

gh aw add githubnext/agentic-ops/workflows/copilot-token-optimizer.md@c780d8324935fe1fb30fce545832c10a8f904039
  • expires on May 26, 2026, 3:57 PM UTC

Metadata

Metadata

Type

No type
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