[FEATURE]: Add configurable spending limit / "Kill Switch" per session #3009

Open
opened 2026-02-16 17:38:14 -05:00 by yindo · 1 comment
Owner

Originally created by @mathe00 on GitHub (Nov 20, 2025).

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Is your feature request related to a problem? Please describe.
Currently, there is no built-in mechanism in opencode to stop the agent based on accrued costs. This poses a significant risk: if the agent enters a loop, hallucinates, or performs a very long task without supervision, it can rapidly drain API credits without the user noticing until it's too late.

Describe the solution you'd like
I would like to be able to set a hard monetary limit (e.g., "max cost per session").
This could be implemented via:

  1. Configuration: A key in .opencode.json (e.g., "max_session_cost": 2.0).
  2. Environment Variable: A standard variable like OPENCODE_MAX_COST=2.0 that sets a global cap for any session running in that environment.
  3. Behavior: If the session cost exceeds this limit, the agent should immediately pause or terminate execution and prompt the user for confirmation to proceed.

Additional context
This is a crucial safety feature for autonomous agents to prevent "runaway" billing.
Other tools (like Kilo Code) already offer similar cost-control mechanisms to protect users.

Originally created by @mathe00 on GitHub (Nov 20, 2025). ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request **Is your feature request related to a problem? Please describe.** Currently, there is no built-in mechanism in opencode to stop the agent based on accrued costs. This poses a significant risk: if the agent enters a loop, hallucinates, or performs a very long task without supervision, it can rapidly drain API credits without the user noticing until it's too late. **Describe the solution you'd like** I would like to be able to set a hard monetary limit (e.g., "max cost per session"). This could be implemented via: 1. Configuration: A key in .opencode.json (e.g., "max_session_cost": 2.0). 2. Environment Variable: A standard variable like OPENCODE_MAX_COST=2.0 that sets a global cap for any session running in that environment. 3. Behavior: If the session cost exceeds this limit, the agent should immediately pause or terminate execution and prompt the user for confirmation to proceed. **Additional context** This is a crucial safety feature for autonomous agents to prevent "runaway" billing. Other tools (like Kilo Code) already offer similar cost-control mechanisms to protect users.
yindo added the discussion label 2026-02-16 17:38:14 -05:00
Author
Owner

@rekram1-node commented on GitHub (Nov 20, 2025):

Yeah that makes sense

@rekram1-node commented on GitHub (Nov 20, 2025): Yeah that makes sense
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3009