Token导航 LogoToken导航TokenDH.com
开发敏感数据github未标认证来源可访问clear审计通过

gemini-token-optimizationGemini token optimization 命令行

Agent Skill

gemini-token-optimization 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,896

周安装

79

GitHub Stars

61

下载量

632
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:gemini-token-optimization(Gemini token optimization 命令行)
来源仓库:https://github.com/melodic-software/claude-code-plugins
仓库路径:skills/gemini-token-optimization
安装命令:
npx skills add https://github.com/melodic-software/claude-code-plugins --skill gemini-token-optimization
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/melodic-software/claude-code-plugins --skill gemini-token-optimization

简介

gemini-token-optimization 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Gemini Token Optimization

🚨 MANDATORY: Invoke gemini-cli-docs First

STOP - Before providing ANY response about Gemini token usage: 1. INVOKE gemini-cli-docs skill 2. QUERY for the specific token or pricing topic 3. BASE all responses EXCLUSIVELY on official documentation loaded

Overview

Skill for optimizing cost and token usage when delegating to Gemini CLI. Essential for efficient bulk operations and cost-conscious workflows.

When to Use This Skill

Keywords: token usage, cost optimization, gemini cost, model selection, flash vs pro, caching, batch queries, reduce tokens

Use this skill when:

  • Planning bulk Gemini operations
  • Optimizing costs for large-scale analysis
  • Choosing between Flash and Pro models
  • Understanding token caching benefits
  • Tracking usage across sessions

Token Caching

Gemini CLI automatically caches context to reduce costs by reusing previously processed content.

Availability

Auth MethodCaching Available
API key (Gemini API)YES
Vertex AIYES
OAuth (personal/enterprise)NO

How It Works

  • System instructions and repeated context are cached
  • Cached tokens don't count toward billing
  • View savings via /stats command or JSON output

Maximizing Cache Hits

  1. Use consistent system prompts - Same prefix increases cache reuse
  2. Batch similar queries - Group related analysis together
  3. Reuse context files - Same files in same order

Monitoring Cache Usage

result=$(gemini "query" --output-format json)
total=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.total) | add // 0')
cached=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.cached) | add // 0')
billable=$((total - cached))
savings=$((cached * 100 / total))

echo "Total: $total tokens"
echo "Cached: $cached tokens ($savings% savings)"
echo "Billable: $billable tokens"

Model Selection

Model Comparison

ModelContext WindowSpeedCostQuality
gemini-2.5-flashLargeFastLowerGood
gemini-2.5-proVery largeSlowerHigherBest

Selection Criteria

Use Flash (-m gemini-2.5-flash) when:

  • Processing large files (bulk analysis)
  • Simple extraction tasks
  • Cost is a primary concern
  • Speed is critical
  • Task is straightforward

Use Pro (-m gemini-2.5-pro) when:

  • Complex reasoning required
  • Quality is critical
  • Nuanced analysis needed
  • Task requires deep understanding
  • Context exceeds 1M tokens

Model Selection Examples

# Bulk file analysis - use Flash
for file in src/*.ts; do
  gemini "List all exports" -m gemini-2.5-flash --output-format json < "$file"
done

# Security audit - use Pro for quality
gemini "Deep security analysis" -m gemini-2.5-pro --output-format json < critical-auth.ts

# Cost tracking with model info
result=$(gemini "query" --output-format json)
model=$(echo "$result" | jq -r '.stats.models | keys[0]')
tokens=$(echo "$result" | jq '.stats.models | to_entries[0].value.tokens.total')
echo "Used $model: $tokens tokens"

Batching Strategy

Why Batch?

  • Reduces API overhead
  • Increases cache hit rate
  • Provides consistent context

Batching Patterns

Pattern 1: Concatenate Files

# Instead of N separate calls
# Do one call with all files
cat src/*.ts | gemini "Analyze all TypeScript files for patterns" --output-format json

Pattern 2: Batch Prompts

# Combine related questions
gemini "Answer these questions about the codebase:
1. What is the main architecture pattern?
2. How is authentication handled?
3. What database is used?" --output-format json

Pattern 3: Staged Analysis

# First pass: Quick overview with Flash
overview=$(cat src/*.ts | gemini "List all modules" -m gemini-2.5-flash --output-format json)

# Second pass: Deep dive critical areas with Pro
echo "$overview" | jq -r '.response' | grep "auth\|security" | while read module; do
  gemini "Deep analysis of $module" -m gemini-2.5-pro --output-format json
done

Cost Tracking

Per-Query Tracking

result=$(gemini "query" --output-format json)

# Extract all cost-relevant stats
total_tokens=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.total) | add // 0')
cached_tokens=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.cached) | add // 0')
models_used=$(echo "$result" | jq -r '.stats.models | keys | join(", ")')
tool_calls=$(echo "$result" | jq '.stats.tools.totalCalls // 0')
latency=$(echo "$result" | jq '.stats.models | to_entries | map(.value.api.totalLatencyMs) | add // 0')

echo "$(date): tokens=$total_tokens cached=$cached_tokens models=$models_used tools=$tool_calls latency=${latency}ms" >> usage.log

Session Tracking

# Track cumulative usage across a session
total_session_tokens=0
total_session_cached=0
total_session_calls=0

track_usage() {
  local result="$1"
  local tokens=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.total) | add // 0')
  local cached=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.cached) | add // 0')

  total_session_tokens=$((total_session_tokens + tokens))
  total_session_cached=$((total_session_cached + cached))
  total_session_calls=$((total_session_calls + 1))
}

# Use in workflow
result=$(gemini "query 1" --output-format json)
track_usage "$result"

result=$(gemini "query 2" --output-format json)
track_usage "$result"

echo "Session total: $total_session_tokens tokens ($total_session_cached cached) in $total_session_calls calls"

Optimization Checklist

Before Large Operations

  • Choose appropriate model (Flash vs Pro)
  • Check if caching is available (API key or Vertex)
  • Plan batching strategy
  • Set up usage tracking

During Operations

  • Monitor cache hit rates
  • Track per-query costs
  • Adjust model if quality insufficient
  • Batch similar queries

After Operations

  • Review total usage
  • Calculate effective cost
  • Identify optimization opportunities
  • Document learnings

Quick Reference

Cost-Saving Commands

# Use Flash for bulk
gemini "query" -m gemini-2.5-flash --output-format json

# Check cache effectiveness
gemini "query" --output-format json | jq '{total: .stats.models | to_entries | map(.value.tokens.total) | add, cached: .stats.models | to_entries | map(.value.tokens.cached) | add}'

# Minimal output (fewer output tokens)
gemini "Answer in one sentence: {question}" --output-format json

Cost Estimation

Rough token estimates:

  • 1 token ~ 4 characters (English)
  • 1 page of code ~ 500-1000 tokens
  • Typical source file ~ 200-2000 tokens

Keyword Registry (Delegates to gemini-cli-docs)

TopicQuery Keywords
Cachingtoken caching, cached tokens, /stats
Model selectionmodel routing, flash vs pro, -m flag
Costsquota pricing, token usage, billing
Output controloutput format, json output

Test Scenarios

Scenario 1: Check Token Usage

Query: "How do I see how many tokens Gemini used?" Expected Behavior:

  • Skill activates on "token usage" or "gemini cost"
  • Provides JSON stats extraction pattern Success Criteria: User receives jq commands to extract token counts

Scenario 2: Reduce Costs

Query: "How do I reduce Gemini CLI costs for bulk analysis?" Expected Behavior:

  • Skill activates on "cost optimization" or "reduce tokens"
  • Recommends Flash model and batching Success Criteria: User receives cost optimization strategies

Scenario 3: Model Selection

Query: "Should I use Flash or Pro for this task?" Expected Behavior:

  • Skill activates on "flash vs pro" or "model selection"
  • Provides decision criteria table Success Criteria: User receives model comparison and recommendation

References

Query gemini-cli-docs for official documentation on:

  • "token caching"
  • "model selection"
  • "quota and pricing"

Version History

  • v1.1.0 (2025-12-01): Added Test Scenarios section
  • v1.0.0 (2025-11-25): Initial release

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

26.54%
按下载量换算168

OpenCode

24.76%
按下载量换算156

Antigravity

20.88%
按下载量换算132

Codex

13.48%
按下载量换算85

Gemini CLI

7.94%
按下载量换算50

Cursor

3.92%
按下载量换算25

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills