◉ANTIGRAVITY LABJP
Articles/Tips & Best Practices
✦ Tips & Best Practices/2026-11-26Beginner

When the End of a Shared AGENTS.md Never Reaches Antigravity, Find the 24,000-Byte Cut First

If Codex, Claude Code and Antigravity share one AGENTS.md, Antigravity truncates everything past 24,000 bytes, and the cap still cannot be changed in 1.5.17. A small script shows which headings get cut, plus the order I use to split the file without breaking the other tools.

Antigravity424AGENTS.md15rules4CodexClaude Code10tips38

I was reviewing an agent's diff one evening in the repository for my own website. The very last line of AGENTS.md says I deploy to production by hand. Claude Code and Codex, reading the same file, had respected that. Antigravity's agent went ahead and proposed the deploy command anyway.

The file itself was fine. The rule was right there at the bottom. The problem was length: the file was under 10,000 characters, but most of it is Japanese, and in bytes it had crossed Antigravity's limit.

The short version first: as of agy 1.5.17, that limit cannot be changed from settings. So for now, the reliable move is not raising the ceiling but knowing where the cut lands and moving the lines you cannot afford to lose above it.

The limit is 24,000 bytes, counted after includes are expanded

The official Rules documentation describes two limits.

LimitHow it is countedWhat happens past it
24,000 bytes per fileBytes after expanding @[label](path) includesThe end of that file is truncated
20,000 tokens across always_on rulesGlobal plus always_on rules combinedThe largest files are demoted to a path-and-description pointer

It applies to AGENTS.md, GEMINI.md and every .agents/rules/*.md. English text is roughly one byte per character, so a purely English file has a lot of room. Japanese, Chinese or Korean text takes about three bytes per character, and accented or emoji-heavy text sits somewhere in between. If your rules mix languages, character counts will mislead you.

On GitHub, issue #1863 asks for a configurable cap along the lines of Codex's project_doc_max_bytes, which defaults to 32 KiB. According to the report, 1.5.16 rejects attempts such as --settings '{"maxRuleFileBytes":65536}' with unknown setting, and a follow-up comment confirms nothing changed in 1.5.17.

There has been real progress, to be fair. The cut now happens on a line boundary and leaves a <truncated N bytes> marker in the model's context. But in the issue's reproduction, the model rarely noticed the marker or went back to read the rest. A marker being present and the content being read are two different things.

A small tool that shows which headings fall past the cut

What I actually needed to know was not "is it over" but "which section disappears". So I wrote a script that expands includes, counts bytes, and lists the line where the cut falls along with every heading after it. It needs Python 3.10 or later and nothing else. The messages are in Japanese because that is what I work in; the logic is what matters.

#!/usr/bin/env python3
"""Antigravity のルール 1 ファイル 24,000 バイト上限で、どの見出しから先が切られるかを示す。"""
import re
import sys
from pathlib import Path
 
LIMIT = 24_000                       # 公式ドキュメントの per-file 上限(@ 取り込み展開後)
VALID_TRIGGERS = {"always_on", "model_decision", "glob", "manual"}
INCLUDE = re.compile(r"@\[([^\]]*)\]\(([^)]+)\)")
FRONTMATTER = re.compile(r"\A---\n(.*?)\n---\n?", re.S)
 
 
def expand(path: Path, seen=None) -> str:
    """@[label](path) を展開する。取り込み先のフロントマターは捨てる(公式の挙動に合わせる)。"""
    seen = seen or set()
    if path.resolve() in seen:       # 循環参照で止まらないように
        return ""
    seen.add(path.resolve())
    text = path.read_text(encoding="utf-8")
 
    def repl(m):
        target = Path(m.group(2)).expanduser()
        if not target.is_absolute():
            target = path.parent / target
        if not target.exists():
            print(f"  ! 取り込み先が見つかりません: {m.group(2)}")
            return m.group(0)
        body = FRONTMATTER.sub("", expand(target, seen), count=1)
        return body
 
    return INCLUDE.sub(repl, text)
 
 
def headings_after_cut(text: str):
    """切り詰め位置と、その後ろに残る見出しを返す(コードブロック内の # は数えない)。"""
    used, cut_line, fenced, after, current = 0, None, False, [], None
    for no, line in enumerate(text.splitlines(keepends=True), 1):
        if line.lstrip().startswith("```"):
            fenced = not fenced
        is_heading = not fenced and line.startswith("#")
        used += len(line.encode("utf-8"))
        if cut_line is None and used > LIMIT:
            cut_line = no            # 公式は行の境目で切るので、この行から先は届きません
            if current and not is_heading:
                after.append(f"    L{current[0]}: {current[1]}  ← 途中で切れます")
        if cut_line is None and is_heading:
            current = (no, line.strip())
        elif cut_line is not None and is_heading:
            after.append(f"    L{no}: {line.strip()}")
    return cut_line, after
 
 
def check_trigger(path: Path, raw: str) -> str | None:
    if ".agents/rules" not in path.as_posix() and "config/rules" not in path.as_posix():
        return None                  # AGENTS.md / GEMINI.md はフロントマター不要
    m = FRONTMATTER.match(raw)
    if not m:
        return "フロントマターがありません(黙って捨てられます)"
    t = re.search(r"^trigger:\s*['\"]?([\w-]+)", m.group(1), re.M)
    if not t or t.group(1) not in VALID_TRIGGERS:
        return f"trigger が不正です: {t.group(1) if t else 'なし'}"
    return None
 
 
def main(args):
    files = [Path(a) for a in args] or [
        p for p in [Path("AGENTS.md"), Path("GEMINI.md"),
                    Path(".agents/AGENTS.md"), Path(".agents/GEMINI.md")] if p.exists()
    ] + sorted(Path(".agents/rules").glob("*.md"))
    over = 0
    for f in files:
        raw = f.read_text(encoding="utf-8")
        text = expand(f)
        size = len(text.encode("utf-8"))
        mark = "OVER" if size > LIMIT else ("near" if size > LIMIT * 0.9 else "ok")
        print(f"[{mark}] {f}  {size:,} / {LIMIT:,} bytes ({len(text):,} 文字)")
        if problem := check_trigger(f, raw):
            print(f"  ! {problem}")
            over += 1
        if size > LIMIT:
            over += 1
            cut, after = headings_after_cut(text)
            print(f"  L{cut} 以降が届きません。切られる見出し:")
            print("\n".join(after) or "    (見出しなし)")
    return 1 if over else 0
 
 
if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))

Run python3 agents_md_cut.py from the repository root and it checks AGENTS.md, GEMINI.md and .agents/rules/*.md together. Against a 26,572-byte test file I built for this, it printed:

[OVER] AGENTS.md  26,572 / 24,000 bytes (10,636 文字)
  L291 以降が届きません。切られる見出し:
    L215: ## デプロイと push の約束  ← 途中で切れます
    L358: ## 削除の約束
[ok] .agents/rules/bad.md  30 / 24,000 bytes (30 文字)
  ! trigger が不正です: alwaysOn

In plain terms: everything from line 291 is lost, the deploy-and-push section is cut halfway through, the deletion section is gone entirely, and one rule file has an invalid trigger.

Three choices are worth explaining:

  • It expands before counting because the docs say the limit is checked after expansion. A tiny file that pulls in a large reference with @[ref](./ref.md) is still over.
  • It reports the section that is cut mid-way, since a heading that sits just under the limit while its body gets truncated is the hardest case to spot.
  • It validates trigger, because a file in .agents/rules/ with missing frontmatter or a value like alwaysOn is silently discarded. Splitting a file only to have the new piece vanish defeats the purpose.

It exits with status 1 when anything is over or invalid, so it drops straight into a pre-commit hook:

#!/bin/sh
# .git/hooks/pre-commit
python3 tools/agents_md_cut.py || {
  echo "A rule file is over 24,000 bytes or has an invalid trigger" >&2
  exit 1
}

Questions I had while splitting a shared file

Will splitting with includes get me under the limit?

No. @[label](path) is expanded before the check, so for the limit it is still one file. Includes reduce maintenance, not what gets loaded; I wrote about that in What @ Includes Actually Shrink When You Split Agent Rule Files.

If I move rules into .agents/rules/, will the other tools see them?

Antigravity will. The limit is per file, so several files marked trigger: always_on each get their own 24,000 bytes. But that is an Antigravity mechanism, and you cannot assume Codex or Claude Code read that folder the same way. The issue makes the same point: it is not a portable workaround for a shared file.

So what should stay in AGENTS.md?

What worked for me was keeping only the promises every tool must honor in AGENTS.md and moving Antigravity-only detail into .agents/rules/. Then I moved the rules about irreversible actions, such as deploys, pushes and deletions, to the very top. Truncation always takes the end, so the lines you cannot afford to lose belong at the front. At worst, what drops is detail.

What if I end up with too many always_on files?

Then you hit the 20,000-token aggregate budget instead, and the largest files get demoted to pointers. The counting approach in I Counted My Rules Against the 20,000-Token Budget in Antigravity 2.17.0 Before Upgrading helps here. Long procedures that are not needed on every turn fit model_decision better, so only the description is shown up front. If you are unsure whether something is a rule or a skill, When You Cannot Decide Between Rules and Skills may help.

The line I drew

For a long time I appended every new rule to the bottom of the file. I wrote the newest rules because they mattered most, yet for a tool with a ceiling that order guaranteed the newest rules would be the first to disappear. Looking back, stacking things in chronological order is how you keep meeting notes, not how you write rules.

Rules I cannot afford to lose go on top; detail I can live without goes below. That is the one ordering I keep whenever I rearrange a shared file. Codex defaults to 32 KiB and Antigravity stops at 24,000 bytes, so each tool's ceiling sits at a different height. Designing for the lowest one, so that the first part of the file is enough on its own, means it behaves the same in every tool I open it with.

One thing to do next

Run the script once against the AGENTS.md you share today. Even if nothing shows OVER, a near result (above 90% of the limit) is a good reason to pick one rule from the end and move it to the top. As an indie developer with a single repository, simply knowing where the cut falls has made those late-night diff reviews a lot calmer for me.

Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

✦ Tips2026-11-19
Before an Agent Clones Your Template Repo, Hand It a Trap Index: One Line per Fix, the Reasons Kept in One Place
When you copy a running site to start the next one, an agent carries the fixes over but leaves the reasons behind. A symptom-first trap index, a one-page porting plan written before the copy, and three small scripts that catch drift between the index, the source docs and their mirrors.
✦ Tips2026-11-17
Why a Small sizes Value Shrinks the Image Itself, and the CSS Line to Add When width and height Attributes Stretch It
The day I added responsive images, one artwork shrank and another stretched sideways. How sizes sets the displayed size, the one CSS line for width and height attributes, and how to work out sizes for tall art in a frame, with numbers and a check script.
✦ Tips2026-10-30
The sed -i That Worked on Linux and Stalled on My iMac: Checking an Agent's Steps Before You Run Them
A sed -i step that ran fine on Linux can stall on a Mac or leave backup files behind. Here is what I reproduced with GNU sed, the forms that behave the same on both, and a short check to run first.