gas-best-practices
AGENTS.md4 starsChanged 4 months agoMITView on GitHub
Universal entry point for any AI coding assistant. Read this file first when working with Google Apps Script code. Apply these rules when you detect any of: - Files with .gs extension - appsscript.json in project root - .clasp.json in project root - User mentions "Google Apps Script", "GAS", or "clasp" (or Thai: "แอปสคริปต์", "สคริปต์ชีต") - Code uses SpreadsheetApp, DriveApp, HtmlService, UrlFetchApp, or other GAS services - doGet / doPost / onEdit / onFormSubmit handlers, or time-driven triggers - google.script.run…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- gas-best-practicesSkill
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
When working on GAS code, consult rules/<topic>.md based on the task:
- Distinctive: line 62
When suggesting GAS code:
- Distinctive: line 65
Use Thai for user-facing error messages, English for log messages
- Very specific: line 66
Default to let/const, ES6+ (V8 runtime is standard now)
≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — gas-best-practices
Universal entry point for any AI coding assistant. Read this file first when working with Google Apps Script code.
Trigger conditions
Apply these rules when you detect any of:
- Files with
.gsextension appsscript.jsonin project root.clasp.jsonin project root- User mentions "Google Apps Script", "GAS", or "clasp" (or Thai: "แอปสคริปต์", "สคริปต์ชีต")
- Code uses
SpreadsheetApp,DriveApp,HtmlService,UrlFetchApp, or other GAS services doGet/doPost/onEdit/onFormSubmithandlers, or time-driven triggersgoogle.script.runcalls in HTML files
How to use
When working on GAS code, consult rules/<topic>.md based on the task:
| Task | Read |
| New project setup, file organization | rules/project-structure.md |
| Read/write Sheet, batch operations, merged cells | rules/spreadsheet-ops.md |
Web app with google.script.run | rules/web-app-rpc.md |
| HTML head, viewport, partial includes | rules/htmlservice-frontend.md |
| External frontend (GitHub Pages) + GAS API | rules/external-frontend.md |
| PDF generation from template | rules/pdf-generation.md |
| Drive folders, file sharing, image preview | rules/drive-ops.md |
| Concurrent operations | rules/lock-service.md |
| Caching queries | rules/cache-service.md |
| Overwrite protection, bulk-delete guard, post-edit verification | rules/data-integrity.md |
| Year/month/enum dropdowns | rules/dynamic-dropdowns.md |
| Auth, role check, OAuth scopes | rules/security.md |
| Adding tables/columns to live system | rules/schema-migrations.md |
| Error handling, Thai user messages | rules/error-handling.md |
| Custom Sheet menus | rules/onopen-menu.md |
| Debug, log, execution history | rules/testing-debugging.md |
| Log at RPC boundaries (client + server) | rules/logging-boundaries.md |
| Time-driven / onEdit / onFormSubmit triggers | rules/triggers.md |
| External APIs, LINE Messaging API, webhooks | rules/urlfetch-external-api.md |
| Deploy not updating, /dev vs /exec, rollback, .claspignore | rules/deployment-versioning.md |
| Batch jobs beyond the 6-minute limit | rules/long-running-jobs.md |
| Email notifications, quotas, admin error alerts | rules/email-notifications.md |
| API keys / config — Properties vs Config sheet | rules/properties-service.md |
Core principles (cross-cutting)
- Every server function callable from client returns a
Result<T>envelope — never throw to client - Read sheets once with
getDataRange().getValues()— batch-write when no merged cells; write cell-by-cell only in merged zones - Lazy resource creation — folder IDs, sheets, columns auto-create on startup, store in Config sheet
- Cache user lookups + computed results via
CacheService.getScriptCache()with explicit invalidation - Wrap concurrent mutations in
LockService.getScriptLock()withtry/finally { releaseLock() } - Admin-editable values go in the Config sheet, secrets go in Script Properties — never hardcoded
- Thai user-facing error messages + English
Logger.logfor developers - Log every RPC boundary —
console.login client,Logger.login server (entry + exit) - Force text format for numeric fields with leading zeros — phone, ID card, postal code (
setNumberFormat('@')+ apostrophe prefix) - Recompute critical values server-side — never trust client-calculated percentages/totals
Output format for the AI
When suggesting GAS code:
- Reference the rule number/file (e.g., "per
rules/spreadsheet-ops.mdRule #2") - Show
✗ Badand✓ Goodpatterns when correcting common mistakes - Use Thai for user-facing error messages, English for log messages
- Default to
let/const, ES6+ (V8 runtime is standard now) - Suggest
LockServicefor any function that mutates shared state
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

