An agentic session is an expensive, context-heavy interaction in which an agent reads files, formulates a plan, changes code, runs tests, reads results, and iterates. A session can consume 5x–20x more tokens than standard completion, so exploration must be constrained rather than treated as free productivity. section 9.2.2 section 9.5.2
Choose the interaction mode and guardrails according to task scope:
- Use inline editing for a clearly described change touching one file; reserve agent mode for changes spanning files or requiring architectural understanding. section 9.2.2
- Constrain exploration with reusable commands that specify relevant files, output format, retry limits, and a token budget. section 9.5.2
- Restrict irrelevant file reads and filter command output so test failures and build warnings, rather than unbounded logs, enter the context. section 9.5.2
- Measure sessions while they run and stop when iteration is wandering instead of converging; unmanaged exploration can multiply cost without improving the result. section 9.2.2 section 9.5.2
A bounded refactoring session
A focused-refactor command can require reading only directly relevant files, producing a diff, running existing tests, allowing at most two fixes, and targeting fewer than 50,000 tokens. This replaces an unconstrained cleanup session that might use 500,000 tokens across forty tool calls and fifteen iterations. section 9.5.2
Listing 9.6 Custom slash commands for cost-controlled agent workflows
markdown <!-- .claude/commands/focused-refactor.md --> # Focused Refactor Refactor the specified function or module with these constraints: - Read ONLY the files directly relevant to the change - Do NOT explore the broader codebase unless explicitly needed - Generate ONLY the changed code (diff format preferred) - Do NOT explain changes unless asked - Run existing tests after changes; do NOT write new tests - If tests fail, fix the issue in max 2 iterations, then stop and report what's unresolved - Budget: aim to complete in under 50,000 tokens total $ARGUMENTS
Inspect a reusable command template for converting broad agent work into a constrained, repeatable workflow. section 9.5.2
