For agents · Claude Code
Write Tern with Claude Code.
Claude Code hasn’t seen much Tern, so the setup gives it what it needs to get Tern right anyway: a project file that tells it how to check its work, and a skill that teaches it the language.
1. Install Tern
curl -fsSL https://ternlang.dev/install.sh | shmacOS or Linux, arm64 or x86_64. Tern compiles through C, so it also needs clang (xcode-select --install on a Mac, sudo apt install clang on Debian or Ubuntu).
2. Add the Tern skill
A skill is instructions Claude Code loads when a task needs them. The Tern skill loads whenever it touches a .tn file or a tern.mod, and covers the rules that differ from Python, where the docs live, and the check-and-test loop.
mkdir -p ~/.claude/skills/tern
curl -fsSL https://ternlang.dev/agents/claude-code/SKILL.md -o ~/.claude/skills/tern/SKILL.mdThat installs it for every project. To share it with a team, put it in the repository at .claude/skills/tern/SKILL.md instead. Read it first: it’s about a hundred lines.
3. Start from a template
tern new myapp --template web # or cli, or lib
cd myapp && claudeThe project has a CLAUDE.md (it includes AGENTS.md) with the rules for this project: read tern guide before calling a library, run tern check --json after every change and follow each hint, and finish with tern test. The web template is a working JSON API with accounts on SQLite, migrations, tests and a page, so Claude Code extends something that already passes.
4. Ask for something
Describe the app the way you would for any language, for example:
Build a link shortener: POST /links takes a URL and returns a slug,
GET /{slug} redirects and counts the click, GET /links/{slug}/stats
returns the count. Store links in SQLite. Write tests for each endpoint.From a fuller spec of that app and an empty directory, an agent built it in 273 lines of Tern, passing all 32 acceptance checks. The app was 408 KB and idled in 4.4 MB (the full comparison with Go and TypeScript).
When it gets stuck
- It writes Python.
range(),append,xs.sort(): the compiler’s hint says what to write instead, and the skill tells Claude Code to follow hints rather than guess again. - It invents a function. Tell it to run
tern guide NAMEfor that module (tern guide json,tern guide sqlite). The guide prints the real API. - It wants the whole language.
tern versionprints Tern’s install directory.docs/reference.mdthere is the whole language on one page, andllms-full.txtadds every library.