Back to Engineering Blog
AI Development 4 min read

A Working Directory That Cost Us 20x the Tokens

A one-word test prompt cost 329,000 input tokens from the repository folder and 15,000 from an empty one. The difference was files the agent loaded on its own.

Jason NevillBy , Houston, TX
#AI-Logos#Tokens#Grok#CostControl

Key Architectural Takeaways

  • A trivial prompt cost about 329k input tokens when run from the repository, and about 15k from an empty folder.
  • The agent auto-loaded the repository's instruction files and rules regardless of its trust setting.
  • Because the review prompt already carries the diff, the reviewer now runs from a throwaway directory.

The measurement

While tuning review costs, we ran a trivial prompt, effectively "reply OK", through one of our reviewing agents. From inside the repository checkout it consumed about 329,000 input tokens. From an empty directory it consumed about 15,000.

Why

The agent automatically loads instruction files and rule directories from its working directory, and it does so whether or not the run is marked as trusted. In a repository with a lot of written guidance, that is a very large fixed cost on every single call, before the task even starts.

The fix

The review brief already contains the diff, and the review runs in a read-only planning mode that uses no tools. The agent therefore does not need the repository at all. We now launch it from a throwaway temporary directory, and expect input to be about 15k plus the prompt.

A second, related bug

A different failure showed up in the same dispatcher: very large diffs were passed on the command line, and anything over about 128 KiB hit the operating system's argument limit and failed. The prompt is now handed over as a file, with a test that a 300 KiB prompt never appears in the arguments and that the temporary file is removed even on failure.

Takeaway

Know what your tools load implicitly. The cheapest token is the one you never send, and sometimes it's one you didn't know you were sending.

Follow the build on LinkedIn or by RSS.

All Articles

Follow the build

Questions about the build, or spotted something we got wrong? Find us on LinkedIn and GitHub.