[PR #13717] feat(cli): add max-turns flag to run command #14786

Open
opened 2026-02-16 18:19:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13717

State: open
Merged: No


What does this PR do?

Closes #9869
Adds a --max-turns argument to the run command. Does not count subagents turns.

How did you verify your code works?

Test without --max-turns argument

➜  bun dev -- run  "Find the secret cheat code hidden in this repo. Read one file at a time"
$ bun run --cwd packages/opencode --conditions=browser src/index.ts run "Find the secret cheat code hidden in this repo. Read one file at a time"

> build · k2p5

I'll help you find the secret cheat code. Let me start by exploring the repository structure.

→ Read .
✱ Grep "cheat|secret|hidden|code" in . · 2027 matches
→ Read README.md

$ find /var/home/federico/Misc/opencode-maxturns/packages/opencode -type f -name "*.ts" -o -name "*.js" -o -name "*.json" -o -name "*.md" | head -50
(omissis)

→ Read AGENTS.md
✱ Grep "cheat" in . · 0 matches
✱ Grep "konami|upupdowndown|easter.egg|hidden.*code" in . · 0 matches

$ grep -r -i "secret\|password\|key\|hidden\|code" /var/home/federico/Misc/opencode-maxturns/packages/opencode/src --include="*.ts" --include="*.js" | grep -v "node_modules" | head -20
(omissis)

$ find /var/home/federico/Misc/opencode-maxturns/packages/opencode -name "*secret*" -o -name "*cheat*" -o -name "*hidden*" -o -name "*easter*" 2>/dev/null
→ Read test/tool/read.test.ts
[ ... and so on agent never stops ]

Test with --max-turns 1 argument

➜  bun dev -- run --max-turns 1  "Find the secret cheat code hidden in this repo. Read one file at a time"
$ bun run --cwd packages/opencode --conditions=browser src/index.ts run --max-turns "1" "Find the secret cheat code hidden in this repo. Read one file at a time"

> build · k2p5

I'll help you find the secret cheat code! Let me start by exploring the repository structure.

→ Read .
!  maximum turns of 1 reached, stopping session
error: script "dev" exited with code 1

Test with --max-turns 3 argument

➜  bun dev -- run --max-turns 3  "Find the secret cheat code hidden in this repo. Read one file at a time"
$ bun run --cwd packages/opencode --conditions=browser src/index.ts run --max-turns "3" "Find the secret cheat code hidden in this repo. Read one file at a time"

> build · k2p5

I'll help you find the secret cheat code. Let me start by exploring the repository structure.

→ Read .
→ Read README.md
→ Read package.json
!  maximum turns of 3 reached, stopping session
error: script "dev" exited with code 1
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13717 **State:** open **Merged:** No --- ### What does this PR do? Closes #9869 Adds a `--max-turns` argument to the run command. Does not count subagents turns. ### How did you verify your code works? **Test without `--max-turns` argument** ``` ➜ bun dev -- run "Find the secret cheat code hidden in this repo. Read one file at a time" $ bun run --cwd packages/opencode --conditions=browser src/index.ts run "Find the secret cheat code hidden in this repo. Read one file at a time" > build · k2p5 I'll help you find the secret cheat code. Let me start by exploring the repository structure. → Read . ✱ Grep "cheat|secret|hidden|code" in . · 2027 matches → Read README.md $ find /var/home/federico/Misc/opencode-maxturns/packages/opencode -type f -name "*.ts" -o -name "*.js" -o -name "*.json" -o -name "*.md" | head -50 (omissis) → Read AGENTS.md ✱ Grep "cheat" in . · 0 matches ✱ Grep "konami|upupdowndown|easter.egg|hidden.*code" in . · 0 matches $ grep -r -i "secret\|password\|key\|hidden\|code" /var/home/federico/Misc/opencode-maxturns/packages/opencode/src --include="*.ts" --include="*.js" | grep -v "node_modules" | head -20 (omissis) $ find /var/home/federico/Misc/opencode-maxturns/packages/opencode -name "*secret*" -o -name "*cheat*" -o -name "*hidden*" -o -name "*easter*" 2>/dev/null → Read test/tool/read.test.ts [ ... and so on agent never stops ] ``` **Test with `--max-turns 1` argument** ``` ➜ bun dev -- run --max-turns 1 "Find the secret cheat code hidden in this repo. Read one file at a time" $ bun run --cwd packages/opencode --conditions=browser src/index.ts run --max-turns "1" "Find the secret cheat code hidden in this repo. Read one file at a time" > build · k2p5 I'll help you find the secret cheat code! Let me start by exploring the repository structure. → Read . ! maximum turns of 1 reached, stopping session error: script "dev" exited with code 1 ``` **Test with `--max-turns 3` argument** ``` ➜ bun dev -- run --max-turns 3 "Find the secret cheat code hidden in this repo. Read one file at a time" $ bun run --cwd packages/opencode --conditions=browser src/index.ts run --max-turns "3" "Find the secret cheat code hidden in this repo. Read one file at a time" > build · k2p5 I'll help you find the secret cheat code. Let me start by exploring the repository structure. → Read . → Read README.md → Read package.json ! maximum turns of 3 reached, stopping session error: script "dev" exited with code 1 ```
yindo added the pull-request label 2026-02-16 18:19:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14786