Why input grows with the square of the round trips, what to move out of CLAUDE.md into hooks, and how to split work across threads and a second command-line tool.入力が往復の二乗で増える理由、CLAUDE.md からフックへ移すもの、スレッドと別のコマンドに作業を分ける方法。
As long as the history is not compacted or trimmed, every round trip sends the conversation so far as input again. With a fixed context of B tokens and D tokens added per round trip, N round trips send N x B + D x N x (N + 1) / 2 tokens of input. Doubling the length of a thread roughly quadruples the growing part. The exact accounting of the 5-hour window is not published, so treat this as the size of the input, not as a number of hours.履歴が圧縮も切り詰めもされないあいだは、1往復ごとに、それまでの会話が入力としてもう一度送られます。固定の文脈が B、1往復で D 増えるなら、N 往復の入力の合計は N×B + D×N×(N+1)/2 です。スレッドの長さを2倍にすると、増えていく部分はおよそ4倍になります。5時間枠の正確な計算方法は公開されていないので、これは「時間」ではなく「入力の大きさ」として読んでください。
Who the work is for, how the repository is laid out, the few conventions that shape every answer. History, long procedures and rarely used rules go into files the model opens when needed.誰のための仕事か、リポジトリの構成、毎回の答えを左右する少数の約束。経緯・長い手順・たまにしか使わない決まりは、必要な時に開くファイルへ移します。
A rule written as prose costs tokens on every round trip and can still be skipped. A PreToolUse hook is a program: it adds nothing to the context on the turns it lets through, and it stops a call that matches its check. It catches only what the check is written to catch. In .claude/settings.json:文章で書いた決まりは、往復のたびにトークンを使い、それでも読み飛ばされることがあります。PreToolUse のフックはプログラムです。通した回には文脈に何も足さず、検査に合った呼び出しを止めます。止められるのは、検査に書いたものだけです。.claude/settings.json に:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash",
"hooks": [ { "type": "command", "command": "python3 \"$CLAUDE_PROJECT_DIR/hooks/guard.py\"" } ] }
]
}
}
It reads the pending tool call from standard input and exits with code 2 to refuse it. This example matches the common spellings of a force push; a pattern check like this is a gate for known shapes, not a sandbox, so extend it for your own rules.これから実行される呼び出しを標準入力から読み、終了コード2で断ります。この例は、強制 push のよくある書き方に合わせたものです。こうした型の照合は、分かっている形のための関所で、隔離環境ではありません。自分の決まりに合わせて書き足してください。
import json, re, sys
call = json.load(sys.stdin) # the tool call, as JSON on stdin
cmd = call.get("tool_input", {}).get("command", "")
if re.search(r"\bgit\s+push\b.*(\s--force\b|\s-f\b|\s\+\S)", cmd): # --force, -f, or a +refspec
print("refused: force push is not allowed here", file=sys.stderr)
sys.exit(2) # exit code 2 stops the call; the reason goes back to the model
Start a fresh thread when a piece of work is done, carrying over a short written summary instead of the whole history. Hand the review of a finished change to a second AI's command-line tool, which keeps the review's round trips out of the main thread. That tool is a separate subscription, and its findings still have to be brought back as a short summary.ひと区切りついたら新しいスレッドを始め、履歴の全部ではなく短い要約だけを持ち越します。仕上がった変更のレビューは、別のAIのコマンドへ渡します。レビューの往復が、元のスレッドに入りません。その道具は別の契約で、結果は短い要約にして持ち帰る手間が要ります。
It lowers the fixed part on every round trip. The growing part comes from the length of the thread, so splitting threads matters as much. The calculator shows both.毎回かかる固定の部分は下がります。増えていく部分はスレッドの長さから来るので、分けることも同じくらい効きます。計算機で両方を見られます。
A PreToolUse hook that exits with code 2 stops that tool call and its message is given back to the model. It only sees what it is matched to, so it is a gate for the listed tools, not a sandbox.終了コード2を返す PreToolUse のフックは、その呼び出しを止め、理由がモデルに返ります。見えるのは対象にした道具だけなので、指定した道具の関所であって、隔離環境ではありません。
Not measured, and we do not claim it. It reduces the input that a thread re-sends, which you can compute for your own numbers.測っておらず、そうとは言いません。減るのは、スレッドが送り直す入力の量です。自分の数字で計算できます。
Written with AI assistance (Claude). The figures are measured or computed as named on the page. The commands are examples: read them and adapt them to your repository before running. Product links lead to our own paid kits.AI(Claude)の補助を使って書いています。数字は、ページに記したとおりの実測値か計算値です。コマンドは例です。実行の前に読み、自分のリポジトリに合わせて直してください。商品のリンク先は、当方の有料のキットです。