Google Apps Script clasp: Develop Locally with VS Code

The online Apps Script editor is fine for quick scripts, but for anything serious you want a real editor, git version control, and a proper development workflow. clasp is Google's official CLI that lets you develop Apps Script locally and push changes to Google.

Install clasp

You need Node.js installed. Then:

npm install -g @google/clasp

Log in to your Google account

clasp login

This opens a browser window to authorise clasp with your Google account.

Create a new project

# Create a new standalone script clasp create --title "My Script" --type standalone # Or create a script bound to a Sheet (pass the spreadsheet ID) clasp create --title "My Sheet Script" --parentId "YOUR_SPREADSHEET_ID" --type sheets

This creates a .clasp.json file in your directory linking it to the Apps Script project.

Clone an existing project

clasp clone "YOUR_SCRIPT_ID"

Find the script ID in the Apps Script editor under Project Settings.

Push and pull code

# Push local changes to Apps Script clasp push # Pull latest code from Apps Script to local clasp pull

Open the script in the browser

clasp open

Watch for changes and auto-push

clasp push --watch

This keeps watching your local files and pushes every time you save — great during active development.

TypeScript support

clasp has built-in TypeScript support. Rename your files from .js to .ts and clasp will compile them before pushing.

Install the Apps Script type definitions for full autocomplete:

npm install --save-dev @types/google-apps-script

Now your editor knows about SpreadsheetApp, GmailApp, DriveApp, and all other services — with full type checking.

function sendEmail(recipient: string, subject: string, body: string): void { GmailApp.sendEmail(recipient, subject, body); } function getSheetData(): string[][] { const sheet: GoogleAppsScript.Spreadsheet.Sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); return sheet.getDataRange().getValues(); }

Project structure example

A typical clasp project looks like this:

my-script/ ├── .clasp.json ← Links to your Apps Script project ├── .claspignore ← Files to exclude from push (like node_modules) ├── appsscript.json ← Script manifest (scopes, timezone, etc.) ├── src/ │ ├── main.ts │ ├── utils.ts │ └── config.ts ├── package.json └── tsconfig.json

.claspignore

Keep local files out of your Apps Script project:

node_modules/** .git/** *.md package.json tsconfig.json

Manage versions and deployments

# Create a new versioned snapshot clasp version "v1.0 - initial release" # List all versions clasp versions # Deploy a version as a Web App or API Executable clasp deploy --versionNumber 1 --description "Production" # List deployments clasp deployments

Tips

  • Add .clasp.json to .gitignore if you're sharing the repo — it contains your script ID.
  • Use appsscript.json to pin OAuth scopes explicitly so you're not surprised by permission prompts.
  • clasp supports multiple environments by maintaining separate .clasp.json files for dev and prod script IDs.
  • Run clasp logs to stream Stackdriver logs from your deployed script directly in the terminal.