co init
Add ConnectOnion to an existing folder safely. Preserves your code and .env, appends only what's missing, refreshes docs to the latest version.
Quick Start: cd existing-project && co init โ your existing files stay put, ConnectOnion slots in around them.
init vs create
Use co create for a fresh project in a new directory. Use co init when you already have a folder โ Django app, scripts, or an existing ConnectOnion project you want to refresh.
| Feature | co create | co init |
|---|---|---|
| Creates new directory | Yes | No (uses current) |
| Works in non-empty dir | No | Yes |
| Uses global identity (~/.co/) | Yes | Yes |
| Handles existing .env | Creates fresh | Appends missing keys |
| Refresh docs anytime | On creation | Every run / --update-docs |
Basic Usage
Drop into any directory and run co init:
Common one-liners:
What Gets Added
co init adds a small set of files. Everything else in your project stays exactly as it was.
Files created:
Identity (address + email) lives in ~/.co/keys.env and ~/.co/host.yaml โ shared across every project. The per-project .co/host.yaml only stores project-specific overrides.
File Safety
Each file has a clear, predictable behavior. Your code is never touched.
| File / Directory | If Exists | Behavior |
|---|---|---|
| agent.py | Skip | Won't overwrite your code |
| .env | Append | Adds only API keys that are missing |
| .co/docs/ | Overwrite | Always pinned to latest framework docs |
| .co/host.yaml | Update | Merges, preserves custom keys |
| .gitignore | Append | Adds ConnectOnion entries if missing |
How .env Is Merged
Global API keys live in ~/.co/keys.env. co init reads them and intelligently merges into your project's .env โ four cases, all safe.
Case 1 โ No .env File
Creates a fresh .env with your global keys.
Case 2 โ .env Exists, No API Keys
Appends the API keys section. Your variables stay intact.
Case 3 โ .env Has Some API Keys
Existing keys are preserved. Only the missing ones are added.
Case 4 โ .env Has All Keys
Nothing to do โ file isn't modified.
Provider mapping
When you pass --key, the provider is auto-detected from the prefix:
- โข OpenAI โ
OPENAI_API_KEY - โข Anthropic โ
ANTHROPIC_API_KEY - โข Google โ
GEMINI_API_KEY - โข Groq โ
GROQ_API_KEY
Templates
Same templates as co create โ pick the closest fit, you can always edit afterward.
minimal
Basic agent with simple tools. Good starting point.
playwright
Browser automation โ clicking, scraping, screenshots.
custom
Describe what you want โ generated by AI.
Refreshing Docs
The .co/docs/ folder ships with the framework โ it's overwritten on every co init so the agent always has the current docs in context.
For a docs-only refresh in an existing project, use --update-docs:
Don't edit framework docs. They'll be overwritten on the next update. Put your own project rules in .co/OO.md instead โ that file is yours, never touched by init.
Special Directory Warnings
co init refuses (or warns) when run in directories that probably aren't projects:
- โข Home directory (
~) - โข Root directory (
/) - โข System directories (
/usr,/etc) - โข Existing git repositories โ warns, then continues
If you really mean it, pass --force:
Command Reference
| Option | Short | Description |
|---|---|---|
| --template | -t | minimal | playwright | custom |
| --key | โ | Paste an API key โ provider auto-detected, appended to .env |
| --force | โ | Continue in non-empty or special directories |
| --yes | -y | Accept defaults, skip prompts |
| --update-docs | โ | Refresh .co/docs/ only โ leaves everything else alone |
| --no-ai | โ | Disable AI features (not recommended) |
Common Workflows
Add agents to a Django app
Refresh an older ConnectOnion project
Convert a scripts folder into an agent project
Troubleshooting
My .env had a different OPENAI_API_KEY โ was it overwritten?
No. co init never replaces an existing key. Your old value stays. To use the global one, delete the line and re-run co init.
The docs in .co/docs/ look out of date
Run co init --update-docs. The folder is always overwritten with the latest framework docs.
I want a clean .env from scratch
Remove it manually, then re-init: rm .env && co init.
Refused to run โ "special directory"
You're probably in ~, /, or a system path. Move into a project folder, or pass --force if you really mean it.
Best Practices
co init --update-docs keeps the agent's context fresh..co/OO.md.
ConnectOnion