Amazon Q Developer CLI でプロンプト中にコンテキストウィンドウの使用率を表示できるようになったので使ってみた

Amazon Q Developer CLI でプロンプト中にコンテキストウィンドウの使用率を表示できるようになったので使ってみた

2025.10.02

いわさです。

前回、Amazon Q Developer CLI で実験的な機能を有効化するためのスラッシュコマンドが v1.15.0 で実装されたことを紹介しました。

https://dev.classmethod.jp/articles/qdev-cli-experiment/

この実験的機能として v1.17.0 でおもしろい機能がリリースされています。
Amazon Q Developer のセッション中はトークンに応じてコンテキストウィンドウを消費していきますが、上限があってある一定のところまで行くとレスポンスの速度・質が悪くなったり、コンテキストが失われたりします。そのため/usageコマンドなどを使うことでたまに現在の使用率を気にする必要がありました。

v1.17.0 で次のプルリクエストで実装されたものなのですが、チャットプロンプト上に現在のコンテキストウィンドウの使用率を表示できるようになりました。

https://github.com/aws/amazon-q-developer-cli/pull/2994

こちらの機能を有効化して使ってみたので紹介します。

有効化

有効化の方法ですが、冒頭のブログで紹介した/experimentスラッシュコマンドを使い、「Context Usage Indicator」機能を有効化します。

			
			
    ⢠⣶⣶⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣶⣦⡀⠀
 ⠀⠀⠀⣾⡿⢻⣿⡆⠀⠀⠀⢀⣄⡄⢀⣠⣤⣤⡀⢀⣠⣤⣤⡀⠀⠀⢀⣠⣤⣤⣤⣄⠀⠀⢀⣤⣤⣤⣤⣤⣤⡀⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢠⣤⡀⣀⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠋⠀⠀⠀⠙⣿⣿⡆
 ⠀⠀⣼⣿⠇⠀⣿⣿⡄⠀⠀⢸⣿⣿⠛⠉⠻⣿⣿⠛⠉⠛⣿⣿⠀⠀⠘⠛⠉⠉⠻⣿⣧⠀⠈⠛⠛⠛⣻⣿⡿⠀⢀⣾⣿⠛⠉⠻⣿⣷⡀⠀⢸⣿⡟⠛⠉⢻⣿⣷⠀⠀⠀⠀⠀⠀⣼⣿⡏⠀⠀⠀⠀⠀⢸⣿⣿
 ⠀⢰⣿⣿⣤⣤⣼⣿⣷⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⢀⣴⣶⣶⣶⣿⣿⠀⠀⠀⣠⣾⡿⠋⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⡇⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⢹⣿⣇⠀⠀⠀⠀⠀⢸⣿⡿
 ⢀⣿⣿⠋⠉⠉⠉⢻⣿⣇⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⣿⣿⡀⠀⣠⣿⣿⠀⢀⣴⣿⣋⣀⣀⣀⡀⠘⣿⣿⣄⣀⣠⣿⣿⠃⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⣀⣀⣀⣴⣿⡿⠃
 ⠚⠛⠋⠀⠀⠀⠀⠘⠛⠛⠀⠘⠛⠛⠀⠀⠀⠛⠛⠀⠀⠀⠛⠛⠀⠀⠙⠻⠿⠟⠋⠛⠛⠀⠘⠛⠛⠛⠛⠛⠛⠃⠀⠈⠛⠿⠿⠿⠛⠁⠀⠀⠘⠛⠃⠀⠀⠘⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠿⢿⣿⣿⣋⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢿⡧

╭─────────────────────────────── Did you know? ────────────────────────────────╮
│                                                                              │
│   Ask me directly about my capabilities! Try questions like "What can you    │
│                    do?" or "Can you save conversations?"                     │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

/help all commands  •  ctrl + j new lines  •  ctrl + s fuzzy search
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🤖 You are chatting with claude-sonnet-4

> /experiment

⚠ Experimental features may be changed or removed at any time

? Select an experiment to toggle ›
  Knowledge                 [OFF] Enables persistent context storage and retrieval across chat sessions (/knowledge)
  Thinking                  [OFF] Enables complex reasoning with step-by-step thought processes
  Tangent Mode              [OFF] Enables entering into a temporary mode for sending isolated conversations (/tangent)
  Todo Lists                [OFF] Enables Q to create todo lists that can be viewed and managed using /todos
  Checkpoint                [OFF] Enables workspace checkpoints to snapshot, list, expand, diff, and restore files (/checkpoint)
                                  Note: Cannot be used in tangent mode (to avoid mixing up conversation history)
❯ Context Usage Indicator   [OFF] Shows context usage percentage in the prompt (e.g., [rust-agent] 6% >)

		

有効化されると、早速コンテキストウィンドウの使用率が表示されました。
起動直後ですが既に 9% 使用していますね。エージェントの設定やグローバルコンテキストあたりかな。

			
			> /experiment

 Context Usage Indicator experiment enabled

9% > 

		

使用率を増やしていく

ここからコンテキストウィンドウを使用していってみます。
今回は/context addで適当なドキュメントファイルをコンテキストとして追加してみました。

			
			11% > /context add sample_document.md

Added 1 path(s) to context.
Note: Context modifications via slash command is temporary.

14% > 

		

おお、コンテキストファイルが追加されることで使用率が 3% 増えましたね。
これはわかりやすいかも。

どんどん追加していってみます。

			
			14% > /context add sample_document2.md

Added 1 path(s) to context.
Note: Context modifications via slash command is temporary.

17% > /context add sample_document3.md

Added 1 path(s) to context.
Note: Context modifications via slash command is temporary.

19% > /context add sample_document4.md

Added 1 path(s) to context.
Note: Context modifications via slash command is temporary.

22% > /context add sample_document5.md

Added 1 path(s) to context.
Note: Context modifications via slash command is temporary.

24% >

		

良いですね。24% まで来ました。
以前からある/usageでも使用率を確認してみます。

			
			24% > /usage

Current context window (48570 of 200k tokens used)
██████████████████|██████████████████████████████████████████████████████████████ 24.28%

█ Context files: ~25740 tokens (12.87%)
█ Tools:     ~17400 tokens (8.70%)
█ Q responses:   ~5400 tokens (2.70%)
█ Your prompts:  ~30 tokens (0.02%)

💡 Pro Tips:
Run /compact to replace the conversation history with its summary
Run /clear to erase the entire chat history
Run /context show to see tokens per context file

		

/usageだと少数部分まで表示されますが、整数部分は一致していますね。
やはりツール関係の読み込みで 9% 近くトークンを使っていたみたいです。MCP サーバー 4つ構成していたのですが、そのせいかもしれない。

Amazon Q Developer では/compactコマンドでこれまでのコンテキストを圧縮することが出来ます。
以下は Amazon Q Developer IDE の機能を紹介したブログですが、CLI でも使用可能です。

https://dev.classmethod.jp/articles/qdev-ide-compact/

使ってみましょう。

			
			24% > /compact

✔ Conversation history has been compacted successfully!

22% > 

		

おお...24% だった仕様率が 22% に変わりました。

50% を超えると色が変わる

ちなみに先程の時点では使用率を示す文字色は次のように緑色でした。

4D44AD16-89EC-4636-9CED-A0906B1F5727_4_5005_c.jpeg

プルリクエストの内容を見てみると、どうやら使用率が増えると色が変わるみたいです。やってみましょう。

902B0556-6A53-4FAF-AB47-0A79B548049E_4_5005_c.jpeg

おお、50% を超えたあたりから黄色になりました。
トークンまずまず使ってるので気にしようね。という警告的な感じでしょうか。

90% を超えるとさらに色が変わるらしいが...

さらに、仕様によると 90% を超えると赤色になるらしいです。
試してみたかったのですが、80% を超えたあたりからなぜか トークンが増えなくなりました。

6B704601-E63A-4A60-83DE-12859B74F370.png

その後、/context showを使ってみたところ Amazon Q Developer CLI がクラッシュしてしまいました。

			
			83% > /context show

👤 Agent (q_cli_default):
    AmazonQ.md 
    AGENTS.md 
    README.md 
    .amazonq/rules/**/*.md 

💬 Session (temporary):
    sample_document.md (1 match)
    sample_document2.md (1 match)
    sample_document3.md (1 match)
    sample_document4.md (1 match)
    sample_document5.md (1 match)
    doc.md (1 match)
    doc2.md (1 match)
    doc3.md (1 match)
    doc4.md (1 match)
    doc5.md (1 match)
    doc6.md (1 match)
    doc7.md (1 match)
    doc8.md (1 match)
    doc9.md (1 match)

14 matched files in use:
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc7.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc9.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/sample_document5.md (~5120 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/sample_document3.md (~5120 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc2.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc8.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/sample_document.md (~5120 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc3.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/sample_document4.md (~5120 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc4.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/sample_document2.md (~5120 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc5.md (~21150 tkns)
💬 /Users/iwasa.takahito/work/hoge1002qdev/doc6.md (~21150 tkns)

Total: ~215950 tokens

Total token count exceeds limit: 150000. The following files will be automatically dropped when interacting with Q. Consider removing them. 

The application panicked (crashed).
Message:  range end index 10 out of range for slice of length 7
Location: crates/chat-cli/src/cli/chat/cli/context.rs:254

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

		

その後何度か試してみたのですが、今回の機能の有無にかかわらず、80% を超えたところで/context showを行うとエラーで終了してしまいますね。

さいごに

本日は、Amazon Q Developer CLI でプロンプト中にコンテキストウィンドウの使用率を表示できるようになったので使ってみました。

これはシンプルで使いやすい機能ではないでしょうか。
Amazon Q Developer CLI を長時間使い続けているといつの間にかコンテキストが失われたりレスポンスがおかしくなって困ることがよくあるので、この機能を有効化しておくとトークンの使用状況を気にしたり、必要に応じてコンテキストのクリアをしたりとか対策できそうですね。

この記事をシェアする

FacebookHatena blogX

関連記事

Amazon Q Developer CLI でプロンプト中にコンテキストウィンドウの使用率を表示できるようになったので使ってみた | DevelopersIO