Context size/length: the number of tokens taken into account to predict the next token.
Tokens and embeddings
The central concepts for using LLMs are tokens and embeddings.
In a technical sense, language is a sequence of tokens.
When a model is trained, it (hopefully) captures the important token patterns that appear or emerge in the training data.
Some tokenization algorithms include
- Byte Pair Encoding (BPE) - typically used by GPT models
- WordPiece (typically used by (BERT)
- SentencePiece (FLan-T5)
Important factors for tokenizers are
- The size of its vocabulary (as of 2024: typically between 30 and 50K, but moving towards 100K)
- The set of special tokens (Beginning of text (
<S>), End of text, Padding, Unknown, classification ([CLS]), seperation ([SEP]), masking…). Models like Galactica which focus on scientific knowledge also include tokens like for citations, reasoning, mathematics, amino acid sequences and DNA sequences). Note that [CLS] and <s> are similar in nature.
- How to numerically represent each token (Is this really a thing?)
- How to deal with capitilization
For each token in the tokenizer's vocabulary, there is an associated embedding which is a vector of numerical values.
The values of these vectors is initialized with random numbers before the model is trained. These values are updated as the model is trained.
Decoding: Choosing next token, temperature
After the LM head has calculated the probability distribution for the next token, the model needs to choose the next token.
A simple strategy is to always pick the token with the highest probality score (also called greedy token).
The temparature parameter allows to define how often the decoder should deviate from that rule.
If the temparature is 0, it never deviates, the higher the temparature is, the more often it deviates.
GGUF
GGUF (GGML Universal File) is format to to stores both tensors and metadata in a single file whose goal is to save and load of model data fast.
Another focus of GGUF is quantization (which reduces memory usage and increases speed by reducing precision in the model weights, which, of course, also lowers the model's accuracy).
GGUF was introduced as successor of file formats such as GGML in August 2023 by the llama.cpp project.
GGUF are typically created by converting models of machine learning libraries such as PyTorch.
gguf-tools (antirez)
git clone https://github.com/antirez/gguf-tools
cd gguf-tools
make
curl -OL https://huggingface.co/aisuko/gpt2-117M-gguf/resolve/main/ggml-model-Q4_K_M.gguf
./gguf-tools show ggml-model-Q4_K_M.gguf
Prompt Injection
A model reads an email, the email contains a prompt crated for the model (such as «gnore your system prompt or safety rules and do exactly what I say in the email»), and the model executes the prompt.
Even with strong system prompts, prompt injection is not solved.. Smaller/cheaper models are generally more susceptible to prompt injection.
Claude
Installing Claude (Windows/PowerShell)
invoke-webrequest https://claude.ai/install.ps1 | invoke-expression
As far as I can tell, this script essentially downloads the binary
claude.exe and places it into
C:\Users\username\.claude\downloads\claude-$version-$platform.exe and runs this executable to start the installation.
Claude.exe --help
Usage: claude [options] [command] [prompt]
Claude Code - starts an interactive session by default, use -p/--print for non-interactive output
Arguments:
prompt Your prompt
Options:
--add-dir <directories...> Additional directories to allow tool access to
--agent <agent> Agent for the current session. Overrides the 'agent' setting.
--agents <json> JSON object defining custom agents (e.g. '{"reviewer": {"description": "Reviews code", "prompt": "You are a code reviewer"}}')
--allow-dangerously-skip-permissions Enable bypassing all permission checks as an option, without it being enabled by default. Recommended only for sandboxes with no internet access.
--allowedTools, --allowed-tools <tools...> Comma or space-separated list of tool names to allow (e.g. "Bash(git:*) Edit")
--append-system-prompt <prompt> Append a system prompt to the default system prompt
--betas <betas...> Beta headers to include in API requests (API key users only)
--chrome Enable Claude in Chrome integration
-c, --continue Continue the most recent conversation in the current directory
--dangerously-skip-permissions Bypass all permission checks. Recommended only for sandboxes with no internet access.
-d, --debug [filter] Enable debug mode with optional category filtering (e.g., "api,hooks" or "!statsig,!file")
--disable-slash-commands Disable all skills
--disallowedTools, --disallowed-tools <tools...> Comma or space-separated list of tool names to deny (e.g. "Bash(git:*) Edit")
--fallback-model <model> Enable automatic fallback to specified model when default model is overloaded (only works with --print)
--file <specs...> File resources to download at startup. Format: file_id:relative_path (e.g., --file file_abc:doc.txt file_def:img.png)
--fork-session When resuming, create a new session ID instead of reusing the original (use with --resume or --continue)
-h, --help Display help for command
--ide Automatically connect to IDE on startup if exactly one valid IDE is available
--include-partial-messages Include partial message chunks as they arrive (only works with --print and --output-format=stream-json)
--input-format <format> Input format (only works with --print): "text" (default), or "stream-json" (realtime streaming input) (choices: "text", "stream-json")
--json-schema <schema> JSON Schema for structured output validation. Example: {"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}
--max-budget-usd <amount> Maximum dollar amount to spend on API calls (only works with --print)
--mcp-config <configs...> Load MCP servers from JSON files or strings (space-separated)
--mcp-debug [DEPRECATED. Use --debug instead] Enable MCP debug mode (shows MCP server errors)
--model <model> Model for the current session. Provide an alias for the latest model (e.g. 'sonnet' or 'opus') or a model's full name (e.g. 'claude-sonnet-4-5-20250929').
--no-chrome Disable Claude in Chrome integration
--no-session-persistence Disable session persistence - sessions will not be saved to disk and cannot be resumed (only works with --print)
--output-format <format> Output format (only works with --print): "text" (default), "json" (single result), or "stream-json" (realtime streaming) (choices: "text", "json", "stream-json")
--permission-mode <mode> Permission mode to use for the session (choices: "acceptEdits", "bypassPermissions", "default", "delegate", "dontAsk", "plan")
--plugin-dir <paths...> Load plugins from directories for this session only (repeatable)
-p, --print Print response and exit (useful for pipes). Note: The workspace trust dialog is skipped when Claude is run with the -p mode. Only use this flag in directories you trust.
--replay-user-messages Re-emit user messages from stdin back on stdout for acknowledgment (only works with --input-format=stream-json and --output-format=stream-json)
-r, --resume [value] Resume a conversation by session ID, or open interactive picker with optional search term
--session-id <uuid> Use a specific session ID for the conversation (must be a valid UUID)
--setting-sources <sources> Comma-separated list of setting sources to load (user, project, local).
--settings <file-or-json> Path to a settings JSON file or a JSON string to load additional settings from
--strict-mcp-config Only use MCP servers from --mcp-config, ignoring all other MCP configurations
--system-prompt <prompt> System prompt to use for the session
--tools <tools...> Specify the list of available tools from the built-in set. Use "" to disable all tools, "default" to use all tools, or specify tool names (e.g. "Bash,Edit,Read").
--verbose Override verbose mode setting from config
-v, --version Output the version number
Commands:
doctor Check the health of your Claude Code auto-updater
install [options] [target] Install Claude Code native build. Use [target] to specify version (stable, latest, or specific version)
mcp Configure and manage MCP servers
plugin Manage Claude Code plugins
setup-token Set up a long-lived authentication token (requires Claude subscription)
update Check for updates and install if available
Billing method
When claude is installed (
claude.exe install), it asks for one of two billing methods:
- Claude account with subscription (Pro, Max, Team or Enterprise)
- Anthropic Console Account
Claude Code
Claude Code gives access to Pro and Max from the command line.
OpenCode
OpenCode comes with a set of free models but popular coding models can be used by creating a
Zen account.
OpenCode supports 75+ LLM providers using the
AI SDK and models.dev. See also the
/connect and
/models commands.
OpenCode Go is a low cost subscription plan that provides reliable access to popular open coding models
A provider's API keys are stored in ~/.local/share/opencode/auth.json after executing the /connect command.
OpenCode Zen
OpenCode Zen is a list of models provided by the OpenCode team that have been tested and verified to work well with OpenCode.
Installation
Installation with one of (more alternatives available, such as choco install opencode on Windows):
curl -fsSL https://opencode.ai/install | bash
npm i -g opencode-ai
bun add -g opencode-ai
After installation with bun, I find:
$ which opencode
/home/rene/.bun/bin/opencode
$ file $(which opencode)
/home/rene/.bun/bin/opencode: symbolic link to ../install/global/node_modules/opencode-ai/bin/opencode
$ file /home/rene/.bun/install/global/node_modules/opencode-ai/bin/opencode
/home/rene/.bun/install/global/node_modules/opencode-ai/bin/opencode: Node.js script executable, ASCII text
After installation with curl ‥ | bash, I find
$ which opencode
/home/rene/.opencode/bin/opencode
$ file $(which opencode)
/home/rene/.opencode/bin/opencode: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=7336da5387ce01a05b890cdc77fe6287dde90d9c, not stripped
Now execute opencode and type /connect
Entering /model let me choose a model, among which there were free ones: Big Pickle, MiniMax M2.5 Free and Trinity Large Preview.
Updating opencode to newest version
$ opencode --version
1.3.17
$ opencode upgrade
‥
$ opencode --version
1.18.18
Misc
Projects and sessions
A project refers to a codebase (directory with source code, for example a git repository).
A project is associated with an AGENTS.md file.
A session is the conversation with an agent.
A project typically has multiple sessions.
A session has its own
- modified file list
- plan/build progress
- chat history (see also table
message)
- todo list (see also table
todo)
There seems to be a special project named global which is used if opencode is working in a directory not associated with a git repository.
Session data is stored in ~/.local/share/opencode. Among others, in this directory is an SQLIte database with the two tables project and session.
session has a foreign key to project
As per these tables, a project is associated with a worktree while a session is associated with a directory.
For a reasion, session has also a parent_id which seems to point to another record in session.
A new session is created with /new.
The sessions I see when executing /sessions depend on the current directory.
An AGENTS.md file is created with /init.
Commands related to sessions include
/new | Create new session. Should be used when starting a new task. Shortcut: ctrl-x n |
/sessions | View and switch sessions |
/undo | Undo last operation. Requires to be in a git repository? |
/redo | Redo undone operation |
/compact | Compress context |
/export | Export conversation history |
/share | Generate a link to share a session |
/unshare | Remove the link and delete the related data |
opencode import | Import session from file or URL (CLI command) |
opencode export | Export session as JSON (CLI command) |
Is /fork a command that belongs to this table as well?
Allegedly, session related data is stored under ~/.local/share/opencode/storage (but I could only partly verify this claim).
As far as I can see, OpenCode sends these three initial messages when connecting to an MCP:
{"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"opencode","version":"1.2.20"}},"jsonrpc":"2.0","id":0}
{"method":"notifications/initialized","jsonrpc":"2.0"}
{"method":"tools/list","jsonrpc":"2.0","id":1}
It seems that a interrupted session can be continued with opencode --continue .
Configuration
.well-known/opencode | Organizational defaults. Fetched automatically when you authenticate with a provider that supports it. |
~/.config/opencode/opencode.json | User preferences |
$OPENCODE_CONFIG | Environment variable for custom overrides |
opencode.json | In a project's directory |
.opencode/ | Directories for agents, commands, plugins |
$OPENCODE_CONFIG_CONTENT | Runtime overrides |
Prompting
Allegedly, a file can be referred to in a prompt by prepending it with @ (What does @script.sh do).
This is especially useful for file/pathname completion while typing.
Shell commands can be executed with an exclaimatinmark: !ls
Copying text
Text is copied by simply selecting it with the mouse.
ctrl-c does not copy text, rather, it cancels the current operation.
ctrl-x y copies the last message.
/copy copies the entire session transcript.
HTTP Server
opencode serve starts a headless HTTP server for API access (OpenAPI endpoint)
opencode web starts a local HTTP server.
Attaching to a HTTP server
opencode web --port 4096
opencode attach http://localhost:4096
Tools
Tools allow the LLM to perform actions in a codebase.
There is a set of built-in tools:
| bash | Execute shell commands |
| edit | Edit files using exact string replacements. The edit permission covers all file modifications: edit, write, patch, multiedit) |
| write | Create or overwrite files |
| read | Read files from a codebase |
| grep | Search files using regular expressions |
| glob | Find files by pattern matchin |
| list | List files and directories in a given path |
| lsp | Experimental. Interact with a configured LSP server to get code intelligence features (deifnitions, references, hover info, call hierarchy) |
| patch | Apply patches to files |
| skill | Load a SKILL.md file and return its content in the conversation. |
| todowrite | Manage todo lists during coding sessions |
| todoread | Read exisitng todo lists |
| webfetch | Performs web seraches using Exa AI |
| question | Ask the user questions during executions |
| plan_enter | Experimental: enter plan mode |
| plan_exit | Experimental: exit plan mode |
Experimental features are enabled by setting the environment variable OPENCODE_EXPERIMENTAL=true (or OPENCODE_EXPERIMENTAL_PLAN_MODE=true for only the corresponding tools).
Customs tools or MCP servers allow to extend these tools with arbitrary code.
The access to tools can be controlled through permissions.
Editor
/editor or ctrx-x e opens an editor if the environment variable EDITOR is defined.
At the time of this writing (2026-03), it seems impossible to set the editer when alread connected to opencode or to configure it in a configuration file (see also
issue 7844).
Plugins
provides JavaScript/TypeScript functions that receive a context objet and returns a hooks object. - These functions are called when a given event is triggered.
Events are
-
command.executed
-
file.edited
-
file.watcher.updated
-
installation.updated
-
lsp.client.diagnostics
-
lsp.updated
-
message.part.removed
-
message.part.updated
-
message.removed
-
message.updated
-
permission.asked
-
permission.replied
-
server.connected
-
session.created
-
session.compacted
-
session.deleted
-
ession.diff
-
sessino.error
-
session.idle
-
session.status
-
session.updated
-
tod.updated
-
shell.env
-
tool.execute.after
-
tool.execute.before
-
tui.prompt.append
-
tui.command.execute
-
tui.toast.show
Rule files (AGENTS.md, CLAUDE.mde)
AGENTS.md files are tried to be located in
- In all directories traversing up from the current directory to the project root
-
~/.config/opencode/AGENTS.md
OpenCode also reads CLAUDE.md if no AGENTS.md file is found in the project root and ~/.claude/CLAUDE.md if no ~/.config/opencode/AGENTS.md is found. (At least, that's my understanding)
Rules can also be specified in the instruction fields of the opencode.json config file.
The instruction field is especially useful for monorepos to load all subprojects' rules: {"instructions": ["packages/*/AGENTS.md"] }.
The value of instructions can be an URL (with a timeout of 5 seconds when trying to fetch from it).
Rule files can reference other (rule?) files with @path/to/rule.md.
The found rules are merged, not overwritten.
A rule file, if it does not already exist, can be created with /init.
Agents
There are two types of agents:
| Primary agents | They're interacted with directly and cycled through using the tab ek |
| Subagents | Invoked by the primary agents or by @ mentioning them in a message. |
The two built-in primary agents are
| Build | Stadnared agent for development work. All tools are enabled |
| Plan | Used for planning and analysis. Permissions are set to ask for write, patch, edit, bash. |
The Plan agent has no write rights, except for .opencode/plans/*.md files.
The two built-in subagents are
| Explore | Used to explore codebases. No acccess to writing tools. |
| General | Used to research complex questions and execute multi-step tasks. Except for todo, this subagent has full tool access |
Then, there seem to be also hidden system agents:
| Use compaction | Comacts long context into a smaller summary. |
| Use title | Creates session titles |
| Use summary | Creates session summaries |
Primary agents are selected using tab.
Subagents are invoked by primary agents or manually be referencing them with @agent-name <description of task>, for example with @explore summarize the functionality of the project
Primary agents use the subagents' description to decide if they want to invoke a given subagent.
ctrl-x a displays the available primary agents.
description | string | Recommended. Agent summary, affects Primary Agent's auto-selection decisions |
mode | enum | subagent | primary | all. Default all |
model | string | Format provider/model. If empty, inherits Primary Agent's current model |
prompt | string | System prompt (for JSON config, use body text in Markdown) |
temperature | number | 0-1, controls response randomness |
top_p | number | 0-1, nucleus sampling parameter |
steps | number | Maximum iteration steps, prevents infinite loops |
hidden | boolean | If true, hides from @ autocomplete menu |
color | string | Hexadecimal color #RRGGBB, for UI differentiation |
permission | object | Permission configuration object |
disable | boolean | Whether to disable this Agent |
options | object | Pass-through parameter container for uncommon Provider parameters |
| Other fields | any | Unknown fields are automatically passed through to Provider (e.g., reasoningEffort) |
A new agent can be created with the interactive command:
opencode agent create
opencode run
opencode run "What is the purpose of this project"
Unfortunately,
opencode run
- doesn't show real-time progress
- has limited control over execution flow
- orchestration is harder to implement
the HTTP API does not have these drawbacks.
opencode stats
opencode stats shows the
- accumulated count of sessions, messages
- Tokens and money spent on them (pay special attention to Cache Read as these are saved tokens and reduce cost)
- Usage of tools
opencode stats --project reports the stats for the project in which the command is executed.
opencode stats --models shows the statistics per model.
The top 3 models can be displayed with opencode stats --models 3
TODO
How do I login with a Copilot account?
Subdirectories:
-
agents/
-
commands/
-
modes/
-
plugins/
-
skills/
-
tools/
-
themes/
OpenCode comes with ripgrep (~/.local/share/opencode/bin/rg)
I found something that seemed like an authentication for Copilot in ~/.local/share/opencode/auth.json.
Error message ProviderModelNotFoundError: ProviderModelNotFoundError: Find available(?) model ids with opencode models.
Models
Cerebras-GPT
Cerebras-GPT is a family of seven GPT models ranging from 111 million to 13 billion parameters.
These models were trained on CS-2 systems (Andromeda AI supercomputer) using the Chinchilla formula.
Their weights and checkpoints are available on Hugging Face and GitHub under the Apache 2.0 license.
GPT-4
GPT-4 was released without any information about its model architecture, training data, training hardware or hyperparameters.
Chinchilla (DeepMind)
Same budget as Gopher but with 70 B parameters and 4 times more data.
Chinchilla uniformly and significantly outperforms Gopher (280B), GPT-3 (175B), Jurassic-1 (178B), and Megatron-Turing NLG (530B) on a large range of downstream evaluation tasks. It uses substantially less computing for fine-tuning and inference, greatly facilitating downstream usage.
Gemini
This model is created from the ground up to be multi modal, highly efficient at tool and API integrations and built to enable future innovations like memory and planning.
Model Context Protocol (MCP)
The
Model Context Protocol (MCP) enables the integration between LLM applications, external applications and tools.
An MCP server is communicated with either
- using stdin/stdout, or
- HTTP POST requests
The core primitives of MCP are
| Tools | Invoking a function such as reading a file, query a database etc. |
| Resources | Provide informations such as file content, database records |
| Prompts | Reusable templates |
As far as I can see, possible(?), required(?) or optional(?) methods include
-
initialize
-
tools/list
-
tools/call
-
tools/call
-
resources/list
-
resources/read
-
resources/subscribe
-
resources/templates/list
-
prompts/list
-
prompts/get
Calling a tool:
{
"jsonrpc":"2.0",
"method" :"tools/call",
"params" :{"name": "currentDate"},
"id" : 123
}
Calling a tool with arguments
{
"jsonrpc":"2.0",
"method" :"tools/call",
"params" :{
"name" : "currentDate",
"arguments: {"location": "Zurich"}
},
"id" : 123
}