Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/opencode/src/cli/cmd/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { SkillTool } from "../../tool/skill"
import { BashTool } from "../../tool/bash"
import { TodoWriteTool } from "../../tool/todo"
import { Locale } from "../../util/locale"
import { VuHitraSettings } from "@/project/vuhitra-settings"

type ToolProps<T extends Tool.Info> = {
input: Tool.InferParameters<T>
Expand Down Expand Up @@ -315,6 +316,10 @@ export const RunCommand = cmd({
}
})()

if (args.profile && directory && !args.attach) {
await VuHitraSettings.setActiveProfile(args.profile as string, directory)
}

const files: { type: "file"; url: string; filename: string; mime: string }[] = []
if (args.file) {
const list = Array.isArray(args.file) ? args.file : [args.file]
Expand Down
5 changes: 5 additions & 0 deletions packages/opencode/src/cli/cmd/tui/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Filesystem } from "@/util/filesystem"
import type { Event } from "@opencode-ai/sdk/v2"
import type { EventSource } from "./context/sdk"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
import { VuHitraSettings } from "@/project/vuhitra-settings"

declare global {
const OPENCODE_WORKER_PATH: string
Expand Down Expand Up @@ -111,6 +112,10 @@ export const TuiThreadCommand = cmd({
return
}

if (args.profile) {
await VuHitraSettings.setActiveProfile(args.profile as string, cwd)
}

const worker = new Worker(workerPath, {
env: Object.fromEntries(
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] !== undefined),
Expand Down
20 changes: 20 additions & 0 deletions packages/opencode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { DbCommand } from "./cli/cmd/db"
import { SetCommand } from "./cli/cmd/set"
import { InitCommand } from "./cli/cmd/init"
import { IndexCommand } from "./cli/cmd/indexer"
import { Profiles } from "./project/profiles"
import { VuHitraSettings } from "./project/vuhitra-settings"
import path from "path"
import { Global } from "./global"
import { JsonMigration } from "./storage/json-migration"
Expand Down Expand Up @@ -65,6 +67,10 @@ const cli = yargs(hideBin(process.argv))
type: "string",
choices: ["DEBUG", "INFO", "WARN", "ERROR"],
})
.option("profile", {
describe: "profile to use",
type: "string",
})
.middleware(async (opts) => {
await Log.init({
print: process.argv.includes("--print-logs"),
Expand All @@ -76,6 +82,20 @@ const cli = yargs(hideBin(process.argv))
})(),
})

if (opts.profile) {
const dir = process.cwd()
if (!/^[A-Za-z0-9_\-.]+$/.test(opts.profile)) {
UI.error(`Invalid profile name: ${opts.profile}`)
process.exit(1)
}
const available = await Profiles.list(dir)
if (!available.includes(opts.profile)) {
UI.error(`Profile "${opts.profile}" not found. Available profiles: ${available.join(", ") || "(none)"}`)
process.exit(1)
}
await VuHitraSettings.setActiveProfile(opts.profile, dir)
}

process.env.AGENT = "1"
process.env.OPENCODE = "1"

Expand Down
11 changes: 10 additions & 1 deletion packages/web/src/content/docs/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ opencode [project]
| `--prompt` | | Prompt to use |
| `--model` | `-m` | Model to use in the form of provider/model |
| `--agent` | | Agent to use |
| `--profile` | | Profile to use (overrides active profile in settings for this run) |
| `--port` | | Port to listen on |
| `--hostname` | | Hostname to listen on |

---
#### Examples

```bash
# Start with a specific profile
opencode --profile fast

# Combine profile with agent
opencode --profile quality --agent alice
```

## Commands

Expand Down
12 changes: 12 additions & 0 deletions packages/web/src/content/docs/profiles.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ The active profile name is displayed below the input field in the TUI.

---

## Command Line

You can also select a profile when starting OpenCode from the command line:

```bash frame="none"
opencode --profile fast
```

This overrides the active profile stored in `.vuhitra/settings.json` for the duration of the run.

---

## Use Cases

### Different Models for Different Tasks
Expand Down
Loading