brig

A minimal AI harness

by wrycode (z6MkuCL8…x3Mu)

rad:z3xnCwjbVZMDojzYcmod8AV7837Ua branch master HEAD 5b92b5ae updated 1mo ago
https git clone https://code.wrycode.com/rad:z3xnCwjbVZMDojzYcmod8AV7837Ua.git brig
radicle rad clone rad:z3xnCwjbVZMDojzYcmod8AV7837Ua brig

brig is a minimal agent REPL. Some ways brig is different:

  • intuitive built-in sandboxing
  • works well with text-based workflows
  • (actually) simple and lightweight
  • human-written documentation

Brig runs in a sandbox that blocks all files by default. Also, brig writes text directly to the terminal and does not break native scrolling, selection, and text flow (great for tmux, vim, emacs). Finally, brig is not written in Javascript, and is efficient with tokens and system resources.

I built brig because I wanted a more minimal agent harness that gave me control over what the agents could see, worked well with my text editor, felt safe to run on my machine, and wasn't a huge, mysterious stack of cards.

Installation

Building your own package:

Arch Linux:

  • cd packages/arch/brig-git
  • makepkg

Pop!_OS / Ubuntu:

  • sudo apt install libncurses-dev
  • cd packages/<distro>/
  • ./build-deb.sh

Quickstart

Set your API key:

export OPENROUTER_API_KEY=sk-...   # or NANOGPT_API_KEY=...

(See Providers for more info about AI providers and models.)

Now run brig. You will get a prompt where you can write your message to the agent. Press enter to send your prompt and the agent will start working in the terminal. When the agent finishes, it will drop you back at the prompt.

$ brig
> Explain blindsight in one sentence.
Blindsight is the ability of a person with damage to the visual cortex to respond to visual stimuli they cannot consciously see — for example, accurately pointing at or avoiding an object while denying any visual perception of it.
> What is 2+2?
4
> 

You can pause the agent and get back to your prompt with Ctrl+c any time. If the prompt > character is not displayed, the agent is still running.

Most of the usual keybindings work, just like in a bash shell or python REPL:

  • Ctrl+l clears the conversation history and scrollback, starting a new conversation
  • Ctrl+p/Ctrl+n or up/down arrows scroll your message history
  • Ctrl+d kills the chat
  • Ctrl+j inserts a newline (and Alt+Enter in some terminals)

REPL commands:

  • /config: view the current configuration.
  • /shell: poke around the sandbox
  • /model: select an AI model
  • /reasoning set reasoning level

By default, agents cannot see files in your home directory. You must grant access when you launch brig. For instance, grant access to the current directory: brig +W.

For the full documentation, run brig -h.

Recipes

Here are some hints and usage ideas to get you started.

Protecting Git history

I usually block .git/:

brig +W. +R.git

With .git/ protected, agents won't start writing history without your permission. Also, you can always restore your project from git this way.

Read-only scripting

Sometimes you feel nervous about granting write access to files. Here's a workflow where the agent never directly writes your files:

$ brig +R. +W./out
> Write a script to normalize my ebook titles and save it in ./out/normalize.sh

Now you can review ./out/normalize.sh directly, ask other agents to check the script for errors, etc.

tmpfs overlay

You can have several agents working in the same tree at once without git worktree hacks. Just use the +T sandbox option, and keep a writable ./out where agents can submit finished patches: brig +T. +W.out

Subagents

Brig can delegate tasks to subagents, but it usually won't do so unless you request it:

> Use the reviewer to review main.zig

Subagents can be useful for context and token management, and for parallelizing massive tasks.

Providers

Brig needs to connect to an AI provider. The providers brig currently works with are OpenRouter and NanoGPT. In the future we will support more providers, including self-hosted options like Ollama.

After creating an account, visit one of these pages to create an API key: openrouter, nanogpt

Models

You can find AI models to use on the following pages:OpenRouter, NanoGPT

All you need to do is click on the model name (which copies a slug like deepseek/deepseek-v4.1-flash, the current default model) and save that as BRIG_MODEL in your env. Or use the /model command from the REPL to temporarily set a model.

Brig works with most models. Specifically, we use the OpenAI chat completions API, which is now an industry standard. This means brig cannot use Anthropic models.

You need to check the prices before using. Some models are 100x more expensive. The best bang for your buck are currently Chinese flash models. They can almost be free because they're so efficient with caching, especially Deepseek.

Planning and feedback

As AI models get better at long, complex tasks, they seem to be worse about checking for feedback or alignment with the human's original intent. This is a consequence of how they are benchmarked; if a model responds to a prompt with follow-up questions instead of making all of the decisions on its own, it fails that benchmark run.

If your task turns out to be impossible, agents will keep churning endlessly, trying strange workarounds to solve it. If it was deeply ambiguous, agents will decide (often incorrectly) what you meant. It will never occur to them to stop running and ask the user for help or guidance. They're stupid that way.

Luckily, you can short-circuit this: just ask the agent to surface the decisions first. If you force the collaboration/feedback up front, you can generate a high-quality, aligned context for the agent to go ahead with the changes. My framework for most changes is something like this:

I want to do X. Analyze the code and make a plan to implement it. Don't write any code yet. Instead, present your plan, and ask any questions you need clarified.

The agent will then come back with a plan, and a list of questions, giving you an opportunity to review and make any decisions that need to be made upfront. This also sometimes brings up surprises that are good to know about.

For plans that seem too long for one agent, you can have the agent generate a plan.md file, which you can go edit, ask another agent to review, etc. Then you can work through parts of the plan with different agents using the above prompt.

SSH

The +SSH sandbox option gives access to your ssh-agent without exposing your actual keys in ~/.ssh/. Obviously, use with caution.

Environment variables

All brig options can be set as environment variables*, and you may also want to pass API keys or other things to your agents.

direnv is an ergonomic way to set variables automatically. Brig supports +VAR syntax so you can copy and past direnv's output to your brig command:

direnv: loading ~/code/example.site.com/.envrc
direnv: export +BRAVE_API_KEY +HCLOUD_TOKEN 
meet.wrycode.com $ brig +W. +R. +BRAVE_API_KEY +HCLOUD_TOKEN 
> Do <something> on the Hetzner Cloud API. Use the Brave search tool if you get stuck.

*except for sandbox options, which can only be set on the command line.

Vision

Agents with vision can 'read' image files on disk directly. For web development, just tell your agents to take screenshots with headless chromium or firefox.

Organize your ebook library

See curator.md.

Skills

Skill names and descriptions are added to the system prompt if the files are visible in the sandbox.

Disable this with --no-skills.

AGENTS.md

AGENTS.md (CLAUDE.md as a fallback) is automatically appended to the system prompt. Disable this with --no-agents.md.

Personas

Personas are named alternatives to the default system prompt text, stored in .agents/<name>.md. Use The -p or --persona option:

$ echo "You are an expert code reviewer." > .agents/reviewer.md
$ brig -p reviewer
>

Development

Dependencies:

  • libedit
  • bubblewrap
  • bash
  • zig

Compile:

just build

I use this bash alias to install the development binary:

# Install brig + completions into ~/.bin
brig-install() {
    local src_dir="${1:-$PWD}"      # pass project dir if not in it
    local bin_dir="$HOME/.bin"

    if [[ ! -f "$src_dir/zig-out/bin/brig" ]]; then
        echo "error: $src_dir/zig-out/bin/brig not found (run 'zig build' first?)" >&2
        return 1
    fi
    if [[ ! -f "$src_dir/completions/brig.bash" ]]; then
        echo "error: $src_dir/completions/brig.bash not found" >&2
        return 1
    fi

    cp "$src_dir/zig-out/bin/brig" "$bin_dir/"
    cp "$src_dir/completions/brig.bash" "$bin_dir/"
    source "$bin_dir/brig.bash"

    echo "installed brig -> $bin_dir"
}

Releases

Arch Linux

Version Package Checksum
0.0.4-1 brig-0.0.4-1-x86_64.pkg.tar.zst sha256
0.0.3-1 brig-0.0.3-1-x86_64.pkg.tar.zst sha256
0.0.2-1 brig-0.0.2-1-x86_64.pkg.tar.zst sha256
0.0.1-1 brig-0.0.1-1-x86_64.pkg.tar.zst sha256

Pop!_OS

Version Package Checksum
0.0.4-1 brig-agent_0.0.4-1_amd64.deb sha256
0.0.3-1 brig-agent_0.0.3-1_amd64.deb sha256
0.0.2-1 brig-agent_0.0.2-1_amd64.deb sha256
0.0.1-1 brig_0.0.1-1_amd64.deb sha256

Ubuntu

Version Package Checksum
0.0.4-1 brig-agent_0.0.4-1_amd64.deb sha256
0.0.3-1 brig-agent_0.0.3-1_amd64.deb sha256
0.0.2-1 brig-agent_0.0.2-1_amd64.deb sha256
0.0.1-1 brig_0.0.1-1_amd64.deb sha256

Branches

Recent commits

Latest 12 commits on master.

5b92b5ae Update releases wrycode 1mo ago
1b01254b Fix ReleaseSafe crash when navigating history (up-arrow)
ReleaseSafe's -fsanitize=function traps libedit's intentional narrow/wide function-pointer cast in its history shim. Disable that sanitizer …
wrycode 1mo ago
985e98cd Update releases wrycode 1mo ago
5d909a75 Fix illegal instruction crash on CPUs without SHA-NI
Pin release builds to x86_64_v2 in the deb and PKGBUILD scripts.
wrycode 1mo ago
859d4a5a Add explicit MIT license wrycode 1mo ago
9335415f Improve RELEASES.md generation wrycode 1mo ago
b7af0fab fix packaging scripts wrycode 1mo ago
09cf9975 Rename ubuntu/pop os packages to brig-agent
Conflicts with `brig` package in Ubuntu's repositories.
wrycode 1mo ago
87875b93 Update README wrycode 1mo ago
4e11a28a Update readme and todo.md wrycode 1mo ago
21e49f7d Add packaging infrastructure wrycode 1mo ago
3cdf71dd Cleaned initial commit wrycode 1mo ago