google-gemini / google-gemini/gemini-cli

Implement 'Tactful Extraction' logic for token-frugal surgical reads

Open
#19,561 2 comments 0 reactions 1 assignee Claimed by @adamfweidman View on GitHub
🔒 maintainer only area/agent kind/enhancement priority/p3 status/bot-triaged workstream-rollup
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

## Motivation

Current context baseline is approximately 36.6k tokens per turn. Large file reads often 'firehose' the context, leading to bloat (previously observed at +15k tokens/turn).

The goal of 'Tactful Extraction' is to establish a surgical code-discovery hierarchy:
1. **grep_search**: Primary scout for locating symbols.
2. **shell/sed**: scalpel for semantic block extraction (preferred for specific line ranges).
3. **read_file**: surgical range-reading (migrated to 1-based start/end lines).

Telemetry indicates that making ~2.1% more targeted tool calls results in a ~6.9% reduction in total input tokens.

## Changes

- **read_file migration**: Switched from 0-based 'offset'/'limit' to 1-based 'start_line'/'end_line' for better model alignment.
- **Surgical Guidance**: Updated tool descriptions and system prompts to mandate 'token-frugal' behavior.
- **Tool Hierarchy**: Emphasized the use of 'grep_search' and 'sed' via 'run_shell_command' for efficient context management.

## Status

This work is temporarily sidelined in favor of other priorities but remains a key architectural goal for efficiency.

Linked Draft PR: https://github.com/google-gemini/gemini-cli/pull/18924

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.