Skip to content

About

A programming language for AI to write and humans to read: ~40% fewer tokens than Python, runs on Python, explains itself in plain English.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Glass

A programming language for AI to write and humans to read.

Glass programs use ~40% fewer tokens than Python and ~45% fewer than JavaScript. Glass runs on Python, so every Python library works. And it can tell you, in plain English, what any piece of code does.

text = read(args[0]) else: exit("error: {err}")
for word, n in text.lower().find_all("[a-z]+").tally().top(10)
  print("{n} {word}")

That's a complete program, error handling included: the 10 most common words in a file.


Why Glass?

Most code is now written by AI and steered by people who don't read every line. That gives a language two jobs: be cheap for the AI to write and be easy for a human to trust.

  • Fewer tokens, so AI work is faster and cheaper. No colons, braces, self, return at the end, lambda, f"...", or try/except blocks, and a standard library built to chain: xs.tally().top(3).
  • The code explains itself. glass sig shows what every function touches (files, network, ...), what it changes, and whether it can fail. Glass works this out from the code, so nobody has to write it down and it can't go stale. glass explain turns a program into plain-English steps.
  • Mistakes are caught before anything runs. Misspelled names, wrong arguments, unhandled failures, and missed cases are all reported with the exact fix, which an AI can apply in one pass.
  • No hidden exceptions. Anything that can fail must be handled where it's called, in one or two tokens: try f(), f() else 0, or f() else: ....
  • As capable as Python. use numpy, use requests, anything on pip. Speed is the same as Python, because Glass compiles to Python.
  • Easy for AI to learn. With one 1,600-token guide, fresh Claude models wrote 24 of 24 test programs correctly (results).

Install

pip install git+https://github.com/arjuncode/glass-lang

Needs Python 3.10+. No other dependencies. Or clone the repo and run ./glass from it, with no install at all.

Your first program

echo 'print("hello from glass")' > hello.glass
glass hello.glass

Then try the commands that make Glass different:

glass check app.glass     # find problems without running anything
glass sig app.glass       # what each function touches, changes, and whether it can fail
glass explain app.glass   # the whole program in plain English

New to Glass? Read Learn Glass in 10 minutes.

Glass vs. Python

The same JSON web API in both:

Python (169 tokens)Glass (49 tokens)
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import parse_qs, urlparse


class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        url = urlparse(self.path)
        if url.path != "/add":
            self.send_response(404)
            self.end_headers()
            self.wfile.write(b"not found")
            return
        q = parse_qs(url.query)
        body = json.dumps({"sum": int(q["a"][0]) + int(q["b"][0])}).encode()
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.end_headers()
        self.wfile.write(body)


HTTPServer(("127.0.0.1", 8080), Handler).serve_forever()
fn handle(req)
  if req.path != "/add": return (404, "not found")
  {"sum": int(req.query["a"]) + int(req.query["b"])}

serve(8080, handle)

Using Glass with your AI agent

  1. Put docs/AI_GUIDE.md in your agent's instructions: Claude Code's CLAUDE.md, Cursor rules, or a system prompt.
  2. Ask for what you want, in Glass.
  3. Have the agent run glass check → glass test → glass run. It can fix anything check reports from the message alone.
  4. Before you trust the result, read glass sig, or glass explain for the full picture.

The numbers

The same 7 programs written idiomatically in each language, standard library only, all producing identical output. Tokens were counted with a real 151k-vocabulary LLM tokenizer.

Glass Python JavaScript Go Rust C
tokens (7 programs) 561 922 1032 1308 1515 2303
Glass saves 39% 46% 57% 63% 76%

Glass wins every task. Per-task numbers, all the programs, and the counting script are in bench/. (Go and Rust weren't compiled here. The tokenizer is Qwen2.5's, since Claude's isn't public, so treat exact numbers as approximate.)

Commands

glass FILE [args] check, then run
glass check FILE report problems; run nothing
glass test FILE run the file's test blocks
glass sig FILE one line per function: what it touches, changes, and whether it can fail
glass explain FILE the program in plain English
glass trace FILE run it, printing every step and every changed value
glass py FILE show the Python that Glass generates

Learn more

How it works

.glass → parse → analyze (check + infer contracts) → Python → run

Glass is a compiler to Python, written in plain Python with no dependencies (~5k lines in glasslang/). Errors always point at your Glass line, never at the generated Python.

Limits

  • Python speed. Fine for apps, scripts, servers, and data work (numpy runs at native speed), but not for tight loops of pure number crunching.
  • Types are optional. Glass checks the types it can see and the ones you write. That's fewer guarantees than Rust or Go.
  • Python libraries are tracked by module, not by function. Glass knows requests uses the network, but not exactly which calls do.
  • Not yet built: editor support (syntax highlighting, language server), a formatter, and a package manager for Glass modules (pip works for Python packages).

Repo layout

glass            run Glass without installing (./glass file.glass)
glasslang/       the compiler and runtime; std/ holds modules written in Glass
docs/            LEARN.md (tutorial), AI_GUIDE.md (for AI), SPEC.md (reference)
examples/        example programs
tests/           test suite (python3 tests/run_all.py) and the AI evaluation
bench/           the token comparison against other languages

License

MIT

About

A programming language for AI to write and humans to read: ~40% fewer tokens than Python, runs on Python, explains itself in plain English.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages