Token Efficiency Encyclopedia

Grep-Result Tool Output

For search or discovery tools, return matching lines or snippets rather than full directory trees or file contents. Let the model request specifics only when needed.

How It Works

A search tool returns only the lines that match the query, with file paths and line numbers. The model sees a compact list of hits and can then request the full content of specific files if it needs more context.

Benefits

Example

Instead of returning the full content of 10 files:

{
  "matches": [
    {"file": "src/auth.py", "line": 42, "text": "def verify_token(token):"},
    {"file": "src/middleware.py", "line": 15, "text": "token = request.headers.get('Authorization')"}
  ]
}

Anti-patterns

See Also

Tools