{"slug": "additional-instructions-for-agents-md-focusing-on-token-optimization", "title": "Additional instructions for AGENTS.md focusing on token optimization", "summary": "A developer introduced a set of guidelines for an AI agent's AGENTS.md file to optimize token usage. The instructions prioritize using a pre-computed AST knowledge graph (graph.json) and the rtk CLI proxy to reduce token consumption by 60-90%. The workflow emphasizes retrieving minimal information, using ast-grep for code searches, and avoiding full directory reads.", "body_md": "Always retrieve the smallest amount of information necessary. Escalate only when necessary. Stop escalating as soon as sufficient information has been obtained.\n\nPreferred order:\n\n- Need code structure?\n`graph.json`\n\n. - Need symbols?\n`ast-grep`\n\n. - Need repository metadata?\n`rtk`\n\n. - Need implementation? Source files.\n- Use repository-wide search as last resort\n\nAvoid reading entire directories or the whole repository unless explicitly requested.\n\n**rtk** is a CLI proxy that filters and compresses command outputs, saving 60-90% tokens.\nUse `rtk`\n\nwhenever possible because it preserves the relevant information while reducing LLM token consumption.\n\nAlways prefix shell commands with `rtk`\n\n:\n\n```\n# Instead of:    Use:\nls -la           rtk ls -la\ngit status       rtk git status\ngit log -10      rtk git log -10\ndocker ps        rtk docker ps\n```\n\nOther examples where you can use `rtk`\n\n:\nOther examples where you can use `rtk`\n\n:\n\n```\nrtk tree\nrtk read\nrtk cat\nrtk git diff\nrtk diff\nrtk npm run test\nrtk curl <url>\nrtk pytest\nrtk jest\nrtk vitest\nrtk playwright test\nrtk lint\nrtk prettier --check .\n```\n\nA pre-computed AST knowledge graph (`graph.json`\n\n) is available at: `graphify-out/graph.json`\n\nUse `graph.json`\n\nbefore searching or reading multiple source files.\n\nWorkflow:\n\n- Read\n`graph.json`\n\n. - Identify the relevant symbols, files, and dependency paths.\n- Read only the source files required for the task.\n- Avoid scanning unrelated files.\n\nUse the graph for:\n\n- dependency tracing\n- call-path discovery\n- identifying high-centrality modules\n- impact analysis before refactoring\n- locating symbol definitions\n\nNever read an entire directory simply to locate a symbol. Use `graph.json`\n\nto locate the symbol first, then read only the relevant files.\n\nThe graph is generated from AST extraction and represents extracted structural relationships only. Treat graph edges as authoritative for structural relationships. Do not infer dependencies that are absent from the graph.\n\nPrefer `ast-grep`\n\nover `grep`\n\nwhenever searching source code.\n\nUse `ast-grep`\n\nfor:\n\n- locating function definitions\n- locating class definitions\n- locating method implementations\n- finding imports\n- matching AST patterns\n- performing structural search\n\nUse `grep`\n\nonly for:\n\n- Markdown\n- JSON\n- YAML\n- log files\n- generated text\n- plain-text configuration\n\nAvoid using `grep`\n\nto search programming language source code when `ast-grep`\n\ncan answer the query.", "url": "https://wpnews.pro/news/additional-instructions-for-agents-md-focusing-on-token-optimization", "canonical_source": "https://gist.github.com/arisetyo/8d6282bb1035ffb87c7cdb5341e944ce", "published_at": "2026-07-01 09:44:58+00:00", "updated_at": "2026-07-01 15:48:31.573190+00:00", "lang": "en", "topics": ["developer-tools", "artificial-intelligence", "large-language-models", "ai-agents"], "entities": ["rtk", "ast-grep", "graph.json", "AGENTS.md"], "alternates": {"html": "https://wpnews.pro/news/additional-instructions-for-agents-md-focusing-on-token-optimization", "markdown": "https://wpnews.pro/news/additional-instructions-for-agents-md-focusing-on-token-optimization.md", "text": "https://wpnews.pro/news/additional-instructions-for-agents-md-focusing-on-token-optimization.txt", "jsonld": "https://wpnews.pro/news/additional-instructions-for-agents-md-focusing-on-token-optimization.jsonld"}}