Skip to content

⚡ Copilot Token Optimization2026-07-18 — duplicate-code-detector #6364

Description

@github-actions

Target Workflow: duplicate-code-detector

Source report: #6363
Estimated cost per run: $8.78 AIC
Total tokens per run: ~258K
Cache hit rate: unknown (single run in report)
LLM turns: unknown (turn count not in export)
Run duration: 5.8 minutes
GitHub API calls: 10

Current Configuration

Setting Value
Tools loaded github (toolsets: issues), bash
Network groups github
Pre-agent steps Yes (5 steps: install jscpd, gather metrics, run jscpd, grep analysis, check existing issues)
Prompt size 7,382 bytes / 201 lines
Model gpt-5.4-mini
jscpd output Top 15 duplicates (already capped)

Recommendations

1. Remove container JS provider scan from pre-agent steps and prompt

Estimated savings: ~40–60K tokens/run (~15–23%)

The prompt body instructs the agent to consider containers/api-proxy/providers/*.js (13 provider files). The agent reads these via bash, loading each file into context. Remove the provider adapter grep loop and its prompt reference:

# In Grep pattern analysis step — delete this block:
- echo '=== Provider adapter patterns ==='
- for f in containers/api-proxy/providers/*.js; do
-   echo "--- $f ---"
-   grep -n '^function|^const.*=.*function|^module.exports' "$f" | head -10
- done

Also remove containers/api-proxy/providers/*.js from the Pre-Computed Analysis section in the prompt body, and remove it from the Repository Context source file list. This eliminates the trigger for agent follow-up reads of 13 JS files (~26K tokens at ~2K/file).


2. Cap jscpd output from 15 to 8 entries and halve grep head limits

Estimated savings: ~15–25K tokens/run (~6–10%)

The jscpd-top.json top-15 includes low-signal results for this small codebase (~24 TypeScript source files). Cut to 8:

- | .[0:15]
+ | .[0:8]

Reduce grep head limits in the Grep pattern analysis step:

- grep -rn 'process\.env\.' src/ --include='*.ts' | grep -v test | head -20
+ grep -rn 'process\.env\.' src/ --include='*.ts' | grep -v test | head -10
- grep -n 'execa|execaSync|docker.*run|docker.*exec' src/docker-manager.ts | head -20
+ grep -n 'execa|execaSync|docker.*run|docker.*exec' src/docker-manager.ts | head -10

3. Shrink the scoring rubric and prompt boilerplate

Estimated savings: ~10–15K tokens/run (~4–6%)

The prompt has an 8-row scoring table, multi-paragraph phase headers, and a verbose example issue template. Specific cuts:

  • Replace the | Factor | Points | scoring table with a one-liner: "Prioritize by line count, security impact, and maintenance burden."
  • Collapse Phase 5 / Phase 6 headers into inline instructions
  • Shorten the issue body template by removing --- horizontal rules and boilerplate run-date line

~800 bytes removable without changing agent behavior.


4. Replace npm install -g jscpd with npx

Estimated savings: ~30–45 seconds run time per invocation (shorter session = lower AIC)

- npm install -g jscpd 2>&1 | tail -3
+ # use npx; no global install needed
- jscpd src --min-lines 10 --min-tokens 50 --reporters json --output /tmp/gh-aw/jscpd-src
+ npx --yes jscpd src --min-lines 10 --min-tokens 50 --reporters json --output /tmp/gh-aw/jscpd-src

5. Raise jscpd thresholds to reduce noise

Estimated savings: ~5–10K tokens/run (~2–4%)

Low thresholds (--min-lines 10 --min-tokens 50) generate many marginal findings. Raise:

- jscpd src --min-lines 10 --min-tokens 50
+ jscpd src --min-lines 15 --min-tokens 70

Fewer entries in jscpd-top.json means shorter agent context and less time processing low-value results.

Expected Impact

Metric Current Projected Savings
Total tokens/run ~258K ~165K ~36%
AIC/run 8.78 ~5.60 ~36%
jscpd top-N 15 8 -7 entries
Grep head lines 20 10 -50%
Provider JS scan 13 files removed eliminated
Prompt size 7,382 bytes ~6,500 bytes ~12%

Implementation Checklist

  • Run jscpd step: change .[0:15] to .[0:8]
  • Grep pattern analysis step: change head -20 to head -10 for both grep patterns
  • Grep pattern analysis step: remove the provider adapter loop entirely
  • Prompt body: remove containers/api-proxy/providers/*.js from Repository Context and Pre-Computed Analysis
  • Prompt body: replace scoring rubric table with a one-line instruction
  • Install step: replace npm install -g jscpd with npx --yes jscpd@latest
  • Raise jscpd thresholds: --min-lines 15 --min-tokens 70
  • Recompile: gh aw compile .github/workflows/duplicate-code-detector.md
  • Trigger workflow_dispatch and compare token usage vs 258K 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 Copilot Token Optimization Advisor · 50.2 AIC · ⊞ 6.4K ·

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