The co init command initializes ConnectOnion in an existing directory, perfect for adding agent capabilities to existing projects.
co init [options]Initializes ConnectOnion in the current directory with:
- AI features enabled by default
- Global address/email from
~/.co/ - API keys appended to existing
.env(or created if missing) - Template files added to your project
- Docs always updated to latest version
| Feature | co create |
co init |
|---|---|---|
| Creates new directory | ✅ Yes | ❌ No (uses current) |
| Can work in non-empty dir | ❌ No | ✅ Yes |
| Uses global identity | ✅ Yes | ✅ Yes |
| Copies global API keys | ✅ Yes | ✅ Yes (appends) |
| Supports templates | ✅ Yes | ✅ Yes |
You have a project with existing .env file:
$ cd my-existing-project
$ cat .env
DATABASE_URL=postgres://localhost/mydb
SECRET_KEY=mysecret
$ co init
🧅 ConnectOnion Project Initializer
========================================
✓ Using global identity
✓ Found existing .env file
✓ Appending API keys from ~/.co/keys.env
$ cat .env
DATABASE_URL=postgres://localhost/mydb
SECRET_KEY=mysecret
# ConnectOnion API Keys
OPENAI_API_KEY=sk-proj-xxx
ANTHROPIC_API_KEY=sk-ant-xxxYour existing environment variables are preserved, API keys are appended!
$ mkdir my-new-agent
$ cd my-new-agent
$ co init --yes
✓ Using global identity
✓ Created new .env with API keys from ~/.co/keys.env
✅ ConnectOnion project initialized!Running co init again updates docs to latest version:
$ co init
✓ Project already initialized
✓ Updating .co/docs/ to latest version
✓ .env already has API keys
✅ Documentation updated!When you run co init:
your-project/
├── agent.py # Added if missing (skipped if exists)
├── .env # APPENDED with API keys (created if missing)
├── .co/
│ ├── host.yaml # Project config (uses global identity)
│ └── docs/ # ALWAYS UPDATED to latest version
│ ├── co-vibe-coding-all-in-one.md # Overwritten
│ └── connectonion.md # Overwritten
└── [your existing files remain untouched]
| File/Directory | If Exists | Behavior |
|---|---|---|
agent.py |
Skip | Won't overwrite user code |
.env |
Append | Adds API keys if missing |
.co/docs/ |
Overwrite | Always latest documentation |
.co/host.yaml |
Update | Preserves custom settings |
.gitignore |
Append | Adds ConnectOnion entries |
Creates new .env with API keys from ~/.co/keys.env:
# Created .env
OPENAI_API_KEY=sk-proj-xxx
ANTHROPIC_API_KEY=sk-ant-xxxAppends API keys to existing file:
# Original .env
DATABASE_URL=postgres://localhost
REDIS_URL=redis://localhost
# After co init
DATABASE_URL=postgres://localhost
REDIS_URL=redis://localhost
# ConnectOnion API Keys
OPENAI_API_KEY=sk-proj-xxx
ANTHROPIC_API_KEY=sk-ant-xxxOnly appends missing keys:
# Original .env
OPENAI_API_KEY=sk-proj-old
# After co init (adds missing keys)
OPENAI_API_KEY=sk-proj-old
# ConnectOnion API Keys
ANTHROPIC_API_KEY=sk-ant-xxx # Added
GEMINI_API_KEY=AIza... # AddedNo changes made:
✓ .env already contains all API keysLike co create, co init uses the global configuration:
If ~/.co/ doesn't exist, it's created automatically:
$ co init # First time ever
🚀 Welcome to ConnectOnion!
✨ Setting up global configuration...
✓ Generated master keypair
✓ Your address: 0x7a9f3b2c8d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a
✓ Your email: 0x7a9f3b2c@mail.openonion.ai
✓ Created ~/.co/keys.env
[continues with project initialization...]$ co init # After global config exists
✓ Using global identity
✓ Using global email: 0x7a9f3b2c@mail.openonion.ai
✓ Found OpenAI key in ~/.co/keys.env
✓ Appending to existing .env
[continues with project initialization...]co init [options]
Options:
--template, -t Template to use (minimal/web-research/browser/custom)
--no-ai Disable AI features (not recommended)
--key API key to use (saves to global config)
--force Initialize even in special directories
--yes, -y Accept all defaults, skip prompts
--update-docs Only update documentationSame templates as co create:
- minimal - Basic agent with simple tools
- web-research - Web scraping and research
- browser - Browser automation
- custom - AI-generated based on description
co init warns when initializing in special directories:
- Home directory (
~) - Root directory (
/) - System directories (
/usr,/etc) - Git repositories (warns but allows)
Use --force to bypass warnings if you know what you're doing.
# In current directory
$ co init
# Accept all defaults
$ co init -y
# With specific template
$ co init --template web-research$ cd my-django-app
$ co init
# Your existing .env is preserved
# DATABASE_URL, SECRET_KEY remain
# API keys are appended$ co init --update-docs
✓ Updated .co/docs/ to latest version$ co init --template custom --description "Discord bot integration"The .env append logic is intelligent:
# Pseudo-code of .env handling
existing_env = read(".env")
global_keys = read("~/.co/keys.env")
for key, value in global_keys:
if key not in existing_env:
append_to_env(f"\n# ConnectOnion API Keys\n{key}={value}")This ensures:
- No duplicate keys
- Existing values preserved
- Clear section for ConnectOnion keys
- Original file structure maintained
The .co/docs/ folder is always overwritten to ensure:
- Latest documentation version
- New features documented
- Bug fixes in docs
- Consistent formatting
This is safe because users shouldn't edit framework docs directly.
cd my-web-app
co init
# .env preserved with database URLs
# API keys appended
# Latest docs installedcd old-agent-project
co init
# Docs updated to latest
# Missing API keys added
# Config preservedcd my-scripts
co init
# Creates .env with API keys
# Adds agent.py template
# Your scripts untouchedThe existing key is preserved:
# Original .env
OPENAI_API_KEY=sk-old-key
# After co init - NOT changed
OPENAI_API_KEY=sk-old-keyRe-run init to update:
$ co init --update-docs
✓ Documentation updated to latest versionManually remove and re-init:
$ rm .env
$ co init
✓ Created new .env with latest API keys-
Review .env after init - Check that API keys were appended correctly
-
Keep docs updated - Run
co init --update-docsperiodically -
Don't edit framework docs - They'll be overwritten on update
-
Commit .co/host.yaml - Track project configuration
-
Never commit .env - Keep API keys secret
| Action | Safe? | Why |
|---|---|---|
| Append to .env | ✅ Yes | Only adds missing keys |
| Overwrite docs | ✅ Yes | Framework docs, not user content |
| Skip agent.py | ✅ Yes | Preserves user code |
| Update config | ✅ Yes | Merges, doesn't replace |
co init intelligently integrates ConnectOnion into existing projects:
- Preserves - Your existing
.envvalues - Appends - Only missing API keys
- Updates - Documentation to latest
- Respects - Your existing code
- Uses - Global identity and keys
Perfect for adding AI agents to any Python project without disrupting existing configuration!
Add ConnectOnion to an existing folder safely.
cd existing-project
co init- Uses your global identity from
~/.co(address + email) - Appends missing API keys to
.env(creates it if missing) - Adds
.co/host.yamland refreshes.co/docs/ - Never overwrites your code (skips existing files)
- Warns in special/system directories (e.g.,
~,/) - Shows what will be created or updated
--forcelets you continue when you know what you’re doing
- minimal: basic agent
- browser: browser automation
- custom: describe it, we generate it with AI
co init -t minimal
co init -t browser
co init -t custom --description "Monitor a site and alert me"--template, -t:minimal|browser|custom--key: paste an API key (auto-detects provider and appends to.env)--force: continue in non-empty/special directories--yes, -y: accept defaults and skip prompts
Notes:
- Keeps
.envintact; only appends missing keys - Provider mapping: OpenAI →
OPENAI_API_KEY, Anthropic →ANTHROPIC_API_KEY, Google →GEMINI_API_KEY, Groq →GROQ_API_KEY - Attempts managed-key authentication on success (or run
co authlater)
python agent.py