How PocketCode's AI Works Under the Hood
A technical look at how we designed PocketCode's AI assistant: smart autocomplete, contextual chat, and dozens of tools integrated with the app's modules.
How PocketCode's AI Works Under the Hood
PocketCode's artificial intelligence isn't a generic chatbot glued to an editor. It's an integrated system that understands your project, your code, and the modules you're using. In this post, we'll tell you how we built it.
General Architecture
The AI system has three main layers:
1. Smart Autocomplete (LSP)
Autocomplete works through the Language Server Protocol (LSP). When you type code, the editor sends context (current file, cursor position, open files) to the AI model, which returns completion suggestions.
What makes our autocomplete different:
- Full project context: It doesn't just see the current file, but the project structure, imports, and dependencies
- Optimized models: We use temperature 0.0 and topK=1 for maximum suggestion accuracy
- Smart cache: We separate cache by model (chat vs completion) to avoid context contamination
- Fill-in-the-Middle (FIM): The model receives code before AND after the cursor for more precise suggestions
2. Contextual Chat
The AI chat isn't a simple prompt-response. When you ask a question:
- The current open file is analyzed
- Selected code is extracted (if there's a selection)
- The project structure is included
- Everything is sent as context to the model
This means you can ask "what does this function do?" without having to copy and paste code.
3. Module Tools (Tool Calling)
This is the most powerful part. The AI can invoke dozens of tools to interact directly with the app's modules. A representative sample:
| Tool | What it does |
|---|---|
create_file | Creates files in your project |
run_in_terminal | Executes commands in the integrated terminal |
db_query | Runs queries against the database |
design_list | Lists and reads visual-designer projects |
git_status | Checks Git status |
read_file | Reads project files |
semantic_search | Searches the codebase by meaning |
grep_search | Searches the codebase by pattern |
When you tell the AI "create a ViewModel for the user list", it doesn't just generate code — it creates the file, places it in the correct folder, and updates the necessary imports.
Security
All execution goes through strict validations:
- Command injection: Terminal commands are sanitized against injection
- Sandboxing: Commands can only run within the project directory
- Timeouts: Every operation has a time limit to prevent zombie processes
- Null safety: All tools validate null values before executing
Supported Models
PocketCode works with multiple AI providers under a BYOK (bring-your-own-key) or OAuth login model through the official CLIs. Pocket Code is not an AI provider: every request goes directly from the device to the provider you pick, and usage is billed by the provider under their policy.
- Gemini (Google) — API key (BYOK). Default model, excellent for Kotlin/Android
- OpenAI / Codex (GPT-4, o-series) — API key or OAuth via the Codex CLI
- Anthropic Claude (Sonnet, Opus, Haiku) — API key or OAuth via the Claude Code CLI
- GitHub Copilot — login with your GitHub account (13 multi-vendor models)
- Custom (OpenAI-compatible) — any
/v1endpoint: OpenRouter, a local Ollama, or your own server - Local, offline models via Ollama — free, no API key needed
Every provider is free. PocketCode never charges for model access; the paid tier is for its own tools (Swarmcode, cloud sync).
Users connect their account or API key in Settings > API Keys.
What's Coming
We're working on:
- RAG (Retrieval-Augmented Generation): So the AI searches Android and Kotlin documentation before answering
- Multi-file editing: Edit multiple files in a single operation
- Prompt templates: Reusable prompt templates for common tasks
Conclusion
PocketCode's AI isn't a bolted-on component — it's an integral part of the development experience. Every app module (terminal, database, designer, Git) is connected, and the AI can orchestrate them all.
You can see the complete development status in our status post.
AI Assistant