GitHub Agentic Workflows function like an automated cleaning crew for your repositories, tackling minor issues tirelessly. While they significantly improve code quality and hygiene, the costs associated with their token usage can escalate quickly, especially since these workflows run automatically and often invisibly. Fortunately, optimizing automated tasks is more straightforward than optimizing interactive developer sessions, which are unpredictable. Because agentic workflows are defined in YAML and repeated consistently, we can systematically reduce their token footprint.
Understanding Token Usage in Agentic Workflows
At GitHub, we rely on hundreds of agentic workflows for maintenance and continuous integration (CI), all running under real API rate limits. To cut costs, we first needed to understand where tokens were going. The challenge was that each agent framework — Claude CLI, Copilot CLI, Codex CLI — emitted logs in different formats, and historical data was often incomplete.

Centralized Logging with Token-Usage Artifacts
Our security architecture provided a solution: an API proxy that prevents agents from directly accessing authentication credentials. This proxy allowed us to capture token usage uniformly across all runs, regardless of the underlying framework. Now, every workflow outputs a token-usage.jsonl artifact — one record per API call containing input tokens, output tokens, cache-read tokens, cache-write tokens, model, provider, and timestamps. Combined with workflow logs, this gives a comprehensive historical view of token consumption, enabling targeted optimizations for future runs.
Implementing Automated Optimization Workflows
With reliable token data, we built two daily optimization workflows that continuously monitor and improve efficiency.
The Daily Token Usage Auditor
This workflow reads token usage artifacts from recent runs, aggregates consumption by workflow, and posts a structured report. It flags any workflow showing a significant recent increase in usage, highlights the most expensive workflows, and notes anomalies — for example, a workflow that normally completes in four LLM turns suddenly requiring 18. The Auditor acts as an early warning system, ensuring no workflow silently becomes a cost burden.

The Daily Token Optimizer
When the Auditor identifies a problematic workflow, the Optimizer examines its source code and recent logs. It then creates a GitHub issue detailing concrete inefficiencies and proposing specific optimizations. This automated review has uncovered many inefficiencies that manual inspection would have missed. By having workflows optimize other workflows, we create a self-improving system that grows more efficient over time.
Notably, both the Auditor and Optimizer are themselves agentic workflows, closing the loop on continuous improvement.
Preliminary Results and Future Directions
We began systematic token optimization in April 2026, focusing on the most frequently used workflows. Early results show a marked reduction in token consumption, with some workflows using 30–40% fewer tokens after adjustments. The Auditor and Optimizer have become indispensable tools in our CI pipeline, and we plan to extend their capabilities to more workflows and to share best practices with the community.
By making token efficiency a first-class concern in our agentic workflow design, we not only reduce costs but also lower latency and improve responsiveness. The lessons learned here apply broadly: any team using automated agents can benefit from centralized logging, automated auditing, and self-optimizing pipelines.
For more details on setting up your own token usage logging, see our guide on centralized logging. To learn about building custom optimization workflows, explore the Automated Optimization section.