{"slug": "turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claude-md", "title": "Turning your AI instruction file into a table of contents: how I keep CLAUDE.md and AGENTS.md short as they grow", "summary": "A developer described restructuring AI instruction files like CLAUDE.md and AGENTS.md into a table of contents that points to separate knowledge, skills, and task folders rather than holding all rules inline. The entry instruction file stays at 394 lines while the content behind it totals roughly 95,000 lines across about 230 knowledge files, task folders, specialist instructions, and skills, so the AI reads the bulk only when needed. The approach follows Claude Code documentation guidance to keep CLAUDE.md files under 200 lines and split file-specific rules into separately loaded instructions.", "body_md": "Instruction files like `CLAUDE.md` and `AGENTS.md` keep getting longer the more you use them. Every time the AI repeats a mistake you add a rule, and every time you hand it a new kind of work you add a procedure. Before you know it, the file is several hundred lines long.\n\nI don't write the actual content into my instruction file. I give it only the job of a table of contents. The instruction file says only \"what is where, and when to read it,\" and the rules and procedures themselves live in other files. In this article, based on the private repository I actually use, I go through how I split the table of contents from the content, how I write each line of the table of contents, and how I keep the files it points to in good shape.\n\nWhen you keep adding content to an instruction file, the first problem is that the important instructions get buried. The instruction file is read in every conversation, so the longer it gets, the more the AI has to read each time. You end up making it read rules that have nothing to do with the current task, every time, and the instructions you really want followed get lost among everything else.\n\nNext, the same thing tends to get written in two places. If you write the same rule in both the instruction file and a procedure document, fixing only one of them creates a conflict. The AI can't tell which one to trust, and sometimes it follows the older instruction.\n\nOn top of that, people also lose track of what is written where. When the instruction file is long, fixing a rule starts with hunting for the place to fix.\n\nAll of these come from packing both \"directions\" and \"content\" into a single file. If you separate the directions from the content and leave only the directions in the instruction file, these problems shrink considerably.\n\nThe official Claude Code documentation also recommends keeping each `CLAUDE.md` file under 200 lines. Long files use more context and make instructions less likely to be followed, and the documentation says instructions that only apply to part of the code should be split into rules that are loaded only when working with those files.\n\n[https://code.claude.com/docs/en/memory](https://code.claude.com/docs/en/memory)\n\nThe official guidance shows that you should keep the file short and gives you mechanisms for splitting it. This article covers what comes after that: how to point to what you split out, and how to keep it in shape. I based it on a real repository that also covers work beyond coding.\n\nI keep my instruction files and knowledge for AI in a private repository. In this repository, there is only one entry instruction file that the AI reads at the start of a conversation, and the content is split into folders. I described what I write in the entry instruction file in this article:\n\nThe folder structure looks like this:\n\n```\nai-agents/\n├── agents/          # The entry instruction file, plus specialist instructions per organization and role\n├── knowledge/       # Accumulated knowledge (facts, decisions, writing style rules, and so on)\n├── skills/          # Skills that describe the steps for routine work\n├── tasks/           # One folder per frequent task (procedure, request prompt, improvement log)\n├── docs/work-logs/  # Work logs\n└── CHANGELOG.md     # Why the instructions and knowledge were changed\n```\n\nThe entry instruction file is currently 394 lines. Counting the content behind it, the knowledge folder has around 230 files and about 80,000 lines, the per-task folders about 11,000 lines, the specialist instructions about 2,300 lines, and the skills about 1,600 lines. If I had written all of that into the entry file, the AI would be reading close to 100,000 lines in every conversation. The entry file is less than 0.5% of the whole, and the AI reads the rest only when it needs it.\n\nI split the folders by how the AI uses what is in them. Instructions on how to behave for each organization or role go in the specialist instructions folder, facts and decisions that come up in conversation go in the knowledge folder, and how to carry out routine work goes in the skills folder. For frequent tasks, the procedure, the request prompt, and the improvement log are kept together in one folder per task. Because there is a rule for where things go, I don't have to think hard when adding something new.\n\nI am careful not to add too many kinds of places. I used to have a separate folder that collected frequently used request prompts. But once I started putting request prompts in the per-task folders as well, the prompts for the same task ended up split across two folders. When I reviewed the whole repository in May 2026, I retired the prompt folder and let the per-task folders and skills absorb its role. With fewer kinds of places, the table of contents stays short too.\n\nThis split applies, to my own repository, the division of roles among instructions for AI that I laid out in an earlier article (overall instructions, the steps for routine work, and detailed rules such as design and writing style).\n\nIn the entry instruction file, I list each file or folder that holds rules or procedures, one line each, with where it lives. For the per-task folders, it looks like this:\n\n```\n- tasks/<org>/morning-briefing/: Morning briefing (daily)\n- tasks/<org>/article-writing/: Article writing workflow (outline → draft → polish → publish)\n- tasks/<org>/monthly-billing/: Monthly billing check (monthly)\n```\n\nEach line has the location, what is there, and how often it is used. The AI looks at these lines, decides which task the current topic belongs to, and goes to read the procedure in the matching folder. The detailed steps are not written in the line. Anything that doesn't fit in one line goes into the file the line points to.\n\nI also avoid putting information that goes stale quickly into a line. While writing this article, I checked and found that the line pointing to my writing style rules said \"314 lines,\" but the actual file had grown to 778 lines. The AI keeps adding to the files it points to, so volatile information like line counts quickly drifts from reality once it is in the table of contents. As soon as I noticed, I removed the line count from the table of contents.\n\nFor knowledge files, I also add when to read them. For the writing style rules, it is \"when drafting or polishing an article, or when asked to 'polish this'\"; for a file that collects mistakes the AI has repeated in the past, it is \"before making a proposal.\" With the timing written down, the AI opens only the files it needs as the conversation goes.\n\nSome lines go beyond the timing and also say why the file should be read first. For example, the line for the file that summarizes the business premises of my own company says to \"always read it when projects or priorities come up,\" and adds the reason: \"it contains premises you need before thinking about what to do with any individual project, so read it first.\" At the end of that same file, I keep a \"common mistakes\" section listing mistakes the AI actually repeated, and the line in the table of contents tells the AI to check it before making a proposal.\n\nWhether the AI reads a file is decided by this one line in the table of contents. No matter how important the content of a file is, if the line doesn't convey why it needs to be read, the AI won't open it. That is why the more costly it would be for a file to be missed, the more likely I am to add the reason to its line.\n\nI write the lines so that a person can understand them too. They are directions for the AI, but I look at this list often myself. The AI maintains the knowledge files on its own during conversations, adding to them and creating new ones. When I want to follow what the AI has added and where, the lines of the table of contents are my guide.\n\nTo keep the benefit of a table of contents, each rule has to be written in only one place. If the same rule lives in two places, the conflict problem remains even with the table of contents split out.\n\nFor example, my writing style rules are written in only one file in the knowledge folder. I also make them available as a skill, but I don't copy the rules into the skill file. The skill's `SKILL.md` starts with a description like the one below, and its body only says \"the rules themselves are in knowledge/writing-style-guide.md; read that file first when this skill is invoked.\"\n\n```\n---\nname: article-writing-style\ndescription: \"Writing style rules for articles. Use this skill when writing or polishing technical articles for any publishing platform, when \\\"polish this\\\" is requested, ...\"\n---\n```\n\nWith Claude's skills, only the name and description are loaded at first, and the body is read when the conversation suggests the skill is needed. The skill mechanism itself already separates directions from content. Since its body in turn is only a pointer to the writing style guide, the skill file itself works as a table of contents for the guide. When I fix a rule, I only fix the knowledge file, and the same rule is used whether it is read through the skill or through any other route.\n\nThe same idea works for the instruction files of different tools. Claude Code reads `CLAUDE.md` and Codex reads `AGENTS.md`, so the file name each tool reads differs. If you write the same content in both, fixing only one creates a conflict. In an OSS repository I contribute to, `CLAUDE.md` contained a single line: `@AGENTS.md`. Claude Code loads (imports) any file referenced with `@`, so the content only needs to be written once in `AGENTS.md`, and both tools read the same content. The official documentation also recommends that repositories already using `AGENTS.md` create a `CLAUDE.md` that imports it.\n\nHowever, import is not a way to make the instruction file shorter. Imported files are all loaded together with `CLAUDE.md` at startup. The official documentation also says that import helps organize long files but does not reduce the amount of context.\n\nThe table of contents I describe in this article is different from import: it points to where a file is in plain text and lets the AI go read it when needed. At startup only the table of contents is read, so the amount read actually goes down. I use import to keep content in one place, and plain-text directions when I want to reduce how much is read.\n\nTo keep the table of contents short, the rules for how to update each file are also best written in the file itself.\n\nIn my instruction repository, knowledge files that are updated on an ongoing basis have a heading called \"Update triggers and procedure\" at the end. For example, the file with a table of past event editions has rules like these:\n\n```\nUpdate this table when any of the following happens.\n\n1. Planning for a new edition starts → add a row and cite the proposal page as the source\n2. The event is held → change the status to \"Held (YYYY-MM-DD)\"\n3. The theme or speakers change → rewrite the text and add (Revised: YYYY-MM-DD). Do not delete rows\n\nAfter updating, change the last-checked date at the end.\n```\n\nWhen the file itself says when, what, and how to fix things, the entry instruction file only needs the file's location and a one-line description. The AI learns how to update the file the moment it opens it, so there is no need to write update procedures into the entry file.\n\nWith each file carrying its own update rules, adding more files only adds one line each to the entry instruction file.\n\nOnce you separate the table of contents from the content, it becomes possible to update only the table of contents and forget to create the file it points to. This actually happened in my instruction repository.\n\nIt was at the end of April 2026, when I introduced the mechanism of grouping frequent tasks into per-task folders. The entry instruction file got directions to the per-task folders, but the folders themselves were never filled in. For about a week, the AI would follow the directions to read a procedure and find no file there.\n\nIn that same change, important parts of the entry instruction file, such as the organizations I work for and the rules for telling contexts apart, had disappeared: 174 lines in total. The change history only said \"expanded what to do at the end of a session,\" and nowhere was it recorded that the entry file had been heavily cut.\n\nI noticed the gap while reviewing the whole repository. I pulled the entry instruction file from before the deletion out of the Git history, added directions to the mechanisms that had been added since, and rebuilt it. The entry file, which had shrunk to 105 lines, became 325 lines at that point. I also created procedures and request prompts for the per-task folders that had been listed in the directions but left empty.\n\nThis incident taught me two things. One is that after changing the table of contents, you need to check that the files it points to actually exist. If something is listed in the table of contents but the file is missing, the AI trusts the directions, goes to read it, and carries on with nothing. The other is that keeping the table of contents itself in Git is well worth it. Even when the entry instruction file broke badly, I could pull the earlier content from the history, so rebuilding it didn't take long.\n\nI used the same idea in the repository of a hackathon project. For Kokoroe, which I submitted to Built with Claude: Japan 2026, I kept the project's `CLAUDE.md` to 94 lines.\n\n[https://github.com/ikenyal/kokoroe](https://github.com/ikenyal/kokoroe)\n\nThis file covers an overview of the project and the rules to follow, the tech stack and folder structure, and frequently used commands. For work records, under a heading called \"Records (update as you work),\" I only listed which file gets what. It directs the AI to write which Claude Code features were used for what in `docs/how-we-built.md`, design decisions in `docs/decisions.md`, and how the idea changed in `docs/evolution.md`. The records themselves live in those files, and `CLAUDE.md` only points to where they go.\n\nOn the other hand, some parts of `CLAUDE.md` do contain the content itself. Under the heading \"Hard rules\" are the rules to follow at all times while building the project: don't bring in files or code from outside planning folders or other projects, keep all data fictional, and don't commit secrets (a check script runs before each commit), among others. Rules that should be followed during any task risk not being read for some topics if they sit behind a pointer, so I wrote them directly in `CLAUDE.md`, which is read every time. What goes directly in the table of contents and what goes into the files it points to is decided by whether it is needed every time.\n\nDuring the roughly one-week hackathon, Claude Code followed these directions and added to the records with each piece of work. Because `CLAUDE.md` stayed short, the amount read each time hardly changed even as the work progressed and the records grew.\n\nTo keep using it as a table of contents, the most important thing is to add a line to it whenever a file is added. A file not listed in the table of contents might as well not exist for the AI. In my instruction repository, when the AI creates a new file, it also adds a line to the entry instruction file in the same change. Looking at the Git history, the changes that created new reference tables, skills, or per-task folders also updated the entry instruction file.\n\nKeeping content out of the instruction file also means less hesitation each time I add a rule. Figure out which file the rule belongs to, write it there, and add a line to the table of contents if needed. As long as that order is fixed, the instruction file doesn't grow long.\n\nIf you keep the instruction file short as a table of contents, there is little to load first when you move to a new tool. The files with rules and procedures can be read regardless of the tool, so even as tools change, the rules and procedures you have built up can keep being used as they are.\n\nThis is Day 6 of \"A Year with AI,\" a 25-day advent calendar I am writing on my own. See [Day 0](https://dev.to/aws-builders/a-year-with-ai-25-days-of-lessons-from-building-with-ai-agents-an-advent-calendar-from-japan-2ic4) for what the series covers. The original Japanese version is on [Zenn](https://zenn.dev/genda_jp/articles/8b0774f25f12a6).", "url": "https://wpnews.pro/news/turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claude-md", "canonical_source": "https://dev.to/aws-builders/turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claudemd-and-agentsmd-short-1meb", "published_at": "2026-12-05 18:39:24+00:00", "updated_at": "2026-12-05 18:43:26.080858+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Claude Code", "Anthropic"], "also_reported_by": [], "takeaway": "Keeping the entry instruction file to a 394-line table of contents while the referenced knowledge, skills, and task files hold roughly 95,000 lines lets the agent load rules only when a task needs them instead of reading everything every conversation.", "recommendation": {"advice": "Keep CLAUDE.md and AGENTS.md as a short table of contents under 200 lines that says what is where and when to read it, and move rules and procedures into separate files loaded on demand.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claude-md", "markdown": "https://wpnews.pro/news/turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claude-md.md", "text": "https://wpnews.pro/news/turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claude-md.txt", "jsonld": "https://wpnews.pro/news/turning-your-ai-instruction-file-into-a-table-of-contents-how-i-keep-claude-md.jsonld"}}