Give Your AI Agent Lens Studio Context
Context engineering for Lens Studio - what an AI coding assistant needs to know, what Lens Studio and CLAD already give it, and how to add your own context folder and rules.
An AI coding assistant writes better Lens code when it has the right information in front of it: how a Lens Studio project works, which API runs where, working examples, and what is in the scene right now. Choosing and managing that information is called context engineering. This page explains what context Lens Studio and CLAD give the assistant already, and how to add more for your project.
What context engineering is
Context engineering is choosing the information an AI assistant has available while it reasons. Prompt engineering is about writing good instructions; context engineering is about deciding what information should be present at each moment, so the assistant gives accurate, relevant results.
Like people, AI assistants have limited attention. The more information you add, the harder it gets for them to focus on what matters. Good context engineering finds the smallest set of high-value information that gets the result you want.
The more closely your context fits your project, the better the assistant works. Generic context gives generic results; specific, well-chosen context gives precise help.
Why Lens Studio context matters
Lens Studio has its own APIs, frameworks, and patterns, which differ from general software development. Without the right context, an assistant might:
- Suggest API patterns that don't exist in Lens Studio.
- Use deprecated methods.
- Miss platform-specific features.
- Give generic answers that don't use what Lens Studio can do.
- Break the TypeScript decorator conventions Lens Studio components use.
With the right context, the assistant can:
- Follow working examples from your own project.
- Follow the patterns in Snap's official packages.
- Suggest the APIs and frameworks that fit your platform.
- Stay consistent with your project's structure.
- See what your Lens Studio workspace looks like right now.
When building for SPECS, context matters even more: SPECS has its own APIs, packages, and practices that don't exist for Snapchat Lenses, such as Interaction Kit, UI Kit, Sync Kit, and the SPECS camera and speech APIs.
What an assistant needs to know about a Lens Studio project
| Context | Why the assistant needs it |
|---|---|
| The project's rules | Lens scripts aren't browser JavaScript: there's no window or DOM, components extend BaseScriptComponent, and units are centimeters |
| The two APIs | Lens scripts use the Lens API; changing the editor itself uses the Editor API. Their names and patterns differ, and mixing them is a common error |
| API typings | The exact classes and members, so the assistant doesn't invent them |
| Package source | How Interaction Kit, UI Kit, and other packages actually work, in the version installed |
| Working examples | Complete projects that show APIs and packages used together |
| The live project | The current scene, assets, Logger output, and what the Preview shows |
What Lens Studio gives every assistant
Lens Studio writes these into the project folder and keeps them up to date:
AGENTS.md: the project rules, read by Codex, Cursor, and other assistants. It covers the runtime environment, the project folders and which ones not to touch, script and rendering order, the difference between the Lens API and the Editor API, and placing objects without overlap.CLAUDE.mdpoints Claude Code at the same file.Support/StudioLib.d.tsandSupport/editor.d.ts: the typings of the Lens API and the Editor API for the Lens Studio version you run.Cache/TypeScript/Src/Packages/: the TypeScript source of each installed package. An assistant may read it but never change it, because Lens Studio regenerates the folder.
The MCP server's tools give the live project: the scene and assets, compile results and the Logger, screenshots of panels and the Preview, the installed packages with their documentation, and a search of the Lens Studio documentation.
What CLAD adds
The CLAD plugin adds skills, each a focused guide to one area (scripting, materials, physics, UI, testing, publishing), which the assistant loads only when the task needs it. This keeps the assistant's context small until it needs more. CLAD's skills already package the context that helps with Lens development, especially for SPECS, so they're a good starting point. See CLAD Agents and Skills.
Add a context folder to your project
For more context than Lens Studio and CLAD give, create a .context/ folder in the project and fill
it with resources the assistant should read: sample projects, package source, and documentation.
This isn't an industry standard, only a practice that helps; adapt it to your project.
mkdir .context
A folder for a SPECS project might look like this:
.context/
├── specs-docs/
│ ├── apis/
│ ├── frameworks/
│ └── best-practices/
├── specs-packages/
│ ├── InteractionKit/
│ ├── SyncKit/
│ └── UIKit/
└── specs-samples/
├── AI Playground/
├── Sync Kit Air Hockey/
└── Throw Lab/
Sample projects
Complete sample projects show working implementations of features, real API usage, how packages combine, and how a whole project is organized.
When building for SPECS, clone the SPECS samples into the folder:
cd .context
git clone https://github.com/specs-devs/samples.git specs-samples
You can also add Lens Studio templates that match what you build, tutorial projects for the features you use, community examples, and your own earlier projects.
Package source
Package source shows the assistant the official component patterns, decorator usage (@component,
@input, @ui.*), import paths, and how similar features are built. Lens Studio already keeps the
source of every installed package in Cache/TypeScript/Src/Packages/. To give the assistant a copy
it can always find, copy those folders into .context/specs-packages/ (or a folder named for your
platform). A .lspkg file is a ZIP archive, so you can also unzip a copy of one from Packages/.
Documentation
Save the documentation pages you need as Markdown in .context/ (for example .context/specs-docs/):
the APIs your Lens uses, framework guides, best practices, and scripting guides. The Lens Studio
MCP server can also search the Lens Studio documentation itself, with its
QueryLensStudioKnowledgeBase tool.
When building for SPECS, that might be the SPECS APIs you use (ASR Module, Camera Module, Bluetooth) and the SPECS frameworks (Interaction Kit, UI Kit, Sync Kit).
Editor screenshots
Screenshots let the assistant see your current interface, debug layout and placement visually,
check which objects are selected, and read error messages. The Lens Studio MCP server takes them on
demand: CapturePanelScreenshotTool captures a panel (the Preview, Scene, or Inspector), and
CaptureRuntimeViewTool captures the running Lens. Ask the assistant to take one when it would
help, or let CLAD's /verify-preview skill take them as it checks its work.
Point the assistant at the context folder
Nothing reads the .context/ folder on its own. Add a rule that tells the assistant to check it
first:
| Assistant | Where the rule goes |
|---|---|
Every assistant that reads AGENTS.md (Codex, Cursor, Claude Code through CLAUDE.md) | AGENTS.md, after the Lens Studio managed block. See Add Your Own Rules for an AI Agent |
| Cursor | A rule file in .cursor/rules/. See Rules in the Cursor documentation |
| VS Code (GitHub Copilot) | A custom agent in .github/agents/. See Use Lens Studio MCP in VS Code |
This rule, adapted from Snap's own, tells the assistant to search the context folder before it answers. Change the folder names to match yours:
# Context folder reference
## Check the context folder first
Before answering any question about Lens Studio APIs, packages, components, or implementation patterns:
1. Search the `.context/` folder recursively, through every subfolder, for relevant examples,
package code, and sample implementations.
2. Use your file search tools to find the relevant TypeScript files, components, or patterns.
3. Reference the actual code you found, with its full file path.
## What the context folder holds
- `.context/specs-docs/`: SPECS documentation. Use it for explanations, complete code examples for
each API, framework features, and design guidelines.
- `.context/specs-packages/`: package source. Use it for component patterns, decorator usage
(`@component`, `@input`, `@ui.*`), and correct import paths.
- `.context/specs-samples/`: complete sample projects by topic. Use them to see how APIs and
packages work together and how projects are organized.
## Workflow when the user asks about a feature, API, or implementation
1. Search all three folders, including every subfolder.
2. Show the actual implementations and file paths you found.
3. Apply those patterns to the user's project, consistent with the official implementations.
## Principles
1. The context folder is the main reference: it holds working implementations.
2. Never guess. If unsure, search the context folder first.
3. Search every nested folder.
4. Cite real files with full paths.
5. Use the same patterns and style as the context.
6. If the context disagrees with the installed package source in Cache/TypeScript/Src/Packages,
trust the installed version: the context copy may be older.
For a full agent prompt, see Add Your Own Rules for an AI Agent.
Best practices for Lens Studio context
Keep the context focused. Include what matters, not everything: the packages and APIs this project uses, the frameworks you actually use, and samples that match your Lens. Leave out documentation for features you don't use, and outdated or deprecated examples.
Organize it in folders. Give docs, packages, and samples their own folders, with clear subfolders, as in the example layout.
Keep it up to date. As the project grows, add the source of new packages, add samples for new features, and remove documentation that no longer applies. Refresh copied package source when you update a package.
Fit the rules to your workflow. Adapt the example rule to your folder layout, your project's conventions, your team's coding standards, and how you debug.
Test and adjust. Start small, watch where the assistant struggles or gives generic advice, add context for those gaps, and refine the rules as you go.
Limits of the context an assistant has
- The typings and rules match the running Lens Studio. An assistant can't know about a feature newer than the version you have open.
- Package source is the installed version. If a guide or sample describes a newer package, update the package before asking the assistant to follow it.
- Your project's intent isn't written anywhere until you write it. State what the Lens is for,
and what must not change, in the prompt or in
AGENTS.md.
Related
- Add Your Own Rules for an AI Agent: add rules and a full agent prompt.
- Connect Your Agent to Lens Studio: how Lens Studio writes these files.
- CLAD Agents and Skills: what the CLAD skills cover.