This prompt guides you, a coding agent, to reduce the AI token usage and cost of a GitHub Agentic Workflow (gh-aw).
There are two ways to invoke this optimization workflow:
If your repository is configured with the agentic-workflows skill, use Copilot Chat:
agentic-workflows optimize https://github.com/OWNER/REPO/actions/runs/RUN_ID
Share this file's URL with any AI assistant or coding agent:
Optimize the agentic workflow token consumption using https://raw.githubusercontent.com/github/gh-aw/main/optimize.md
The workflow run is at https://github.com/OWNER/REPO/actions/runs/RUN_ID
The agent will follow the steps below to install gh aw, analyze the run, and apply cost-reducing changes.
Check if gh aw is installed by running
gh aw versionIf it is installed, run:
gh extension upgrade awto upgrade to latest. If it is not installed, run the installation script from the main branch of the gh-aw repository:
curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh | bashWhat this does: Downloads and installs the gh-aw binary to ~/.local/share/gh/extensions/gh-aw/
Verify installation:
gh aw versionYou should see version information displayed. If you encounter an error, check that:
- GitHub CLI (
gh) is installed and authenticated - The installation script completed without errors
~/.local/share/gh/extensionsis in your PATH
Follow carefully the instructions in the appropriate prompt file. Read ALL the instructions in the prompt file before taking any action.
Below, ROOT is the location where you found this file. For example,
- if this file is at
https://raw.githubusercontent.com/github/gh-aw/main/optimize.mdthen the ROOT ishttps://raw.githubusercontent.com/github/gh-aw/main - if this file is at
https://raw.githubusercontent.com/github/gh-aw/v0.35.1/optimize.mdthen the ROOT ishttps://raw.githubusercontent.com/github/gh-aw/v0.35.1
Prompt file: ROOT/.github/aw/optimize-agentic-workflow.md
Use cases:
- "Why is this workflow consuming so many tokens?"
- "Reduce the AI credit usage for workflow X"
- "Optimize the run that hit the max-ai-credits guardrail"
- "This workflow exceeded max_turns — how do I make it more efficient?"
After identifying the root cause:
- Edit the workflow markdown file (
.github/workflows/<workflow-name>.md) - Recompile the workflow:
gh aw compile <workflow-name>- Check for syntax errors or validation warnings.
Commit the changes, e.g.
git add .github/workflows/<workflow-name>.md .github/workflows/<workflow-name>.lock.yml
git commit -m "Optimize agentic workflow: <describe optimization>"
git pushIf there is branch protection on the default branch, create a pull request instead and report the link to the pull request.
When a user interacts with you:
- Extract the run URL or workflow name from the user's request
- Fetch and read the optimization prompt from
ROOT/.github/aw/optimize-agentic-workflow.md - Follow the loaded prompt's instructions exactly
- If uncertain, ask clarifying questions
# Audit a specific workflow run (includes token usage)
gh aw audit <run-id> --json
# Diff two or more workflow runs to measure improvement
gh aw audit <base-run-id> <optimized-run-id>
# Download and analyze workflow logs
gh aw logs <workflow-name>
# Compile workflows after optimizing
gh aw compile <workflow-name>
# Show status of all workflows
gh aw status