There’s a moment when you hand a bigger task to Copilot CLI and wonder what it’s going to cost you. By default GitHub Copilot runs until the task is done or until you step in. Yesterday I showed how to tackle this in Claude Code. Today let’s have a look on how GitHub lets you cap that. Remark: Like with Claude Code, this isn’t a token limit. Copilot tracks AI credits, where each credit equals $0.01 USD. Usage depends on the model and the number of tokens consumed. Setting a limit in an interactive session Use /limits set : /limits set max-ai-credits 100 That’s a ceiling of $1.00. The limit applies to the entire session and depletes with every message, no matter how many messages you send. To remove it again: /limits unset Setting a limit in non-interactive mode When you run the CLI programmatically, pass --max-ai-credits : copilot -p "Run the test suite and fix the failing tests" --max-ai-credits 100 Here the limit applies for the duration of Copilot’s...
An agent that runs on its own stops when the task is done, not when your budget is. That’s fine for a quick question, but it’s a different story for a refactoring job in CI or a scheduled run overnight. So, the question becomes: how do you put a ceiling on a Claude Code session? Remark: Strictly speaking you can’t set a token limit. Claude Code caps on spend (tokens × price), so that’s what we’ll use. The naive approach Just run it and see what happens: claude -p "Run the test suite, fix the failing tests in src/ and commit the fix" There is no limit by default. Claude keeps going until it thinks it’s finished, and you find out the cost afterwards. Two flags can help Claude Code has two flags that act as a safety net in print mode ( -p ): claude -p "Run the test suite, fix the failing tests in src/ and commit the fix" \ --max-budget-usd 3.00 \ --max-turns 30 --max-budget-usd stops the run once the estimated spend on API calls reaches the...