This article follows the official documentation. We haven’t tested this tool for a hands-on review.
Laravel Forge manages servers and deploys web applications. A coding agent is software that runs shell commands to help with development or operations work. The agent can use Forge’s command-line interface, a tool you run in a terminal, to inspect servers and sites, read logs, and run remote commands.
Start with a low-risk task: ask the agent to list the sites on a selected server and report them. Forge CLI commands can also change remote infrastructure. For example, they can deploy code, update environment variables, or restart resources. Make clear which commands only inspect data and which make changes. Forge’s service overview describes its server and deployment features.
Install and authenticate
The machine running the agent needs a compatible PHP version. Install the Forge CLI as a global Composer package by running this command:
composer global require laravel/forge-cli
Create an API token in the Forge dashboard to authenticate the CLI. Run forge login and follow the prompts. For a CI environment, Forge also documents the FORGE_API_TOKEN environment variable. Set the token in the environment or a secrets manager before starting the agent. Do not put it in the agent prompt. Use forge logout to end the CLI session. The Forge CLI documentation covers installation and authentication.
Inspect an organization’s sites
Forge CLI commands use an active organization, meaning the organization currently selected in the CLI. Most server commands also use the active server. Before inspecting a site, have the agent confirm which organization and server are active. Replace <server-id> below with an ID returned by forge server:list; the angle-bracketed value is a placeholder, not a literal argument.
forge organization:list
forge organization:current
forge server:list
forge server:switch <server-id>
forge site:list
The first command lists organizations available to the authenticated account. The second shows which organization is active. forge server:list lists servers in that organization; after you switch to the intended server, forge site:list lists its sites. These commands read Forge data. They do not deploy code or change server configuration.
An agent can use this sequence to answer a concrete question such as, “Which sites belong to the staging server?” It should report the selected organization and server along with the site names, so the result is clear about its scope. Forge also provides organization:switch and server:current for changing or checking the active context. Switching organizations resets the active server, so check the server again after an organization change.
For example, a suitable prompt is: “Use the Forge CLI to list the sites on the staging server. Do not deploy, edit environment variables, restart resources, or run remote commands. Report the organization and server you selected, then list the sites.” The agent still needs the server ID to select the intended server; it should ask for clarification rather than guess if the target is ambiguous.
Read logs and check SSH
After selecting the right server, the agent can read site and deployment logs to investigate a reported issue. Forge CLI also has commands to check resource status and read logs. These commands read information from Forge or the server. Commands such as deploy, env:push, and resource restart change remote resources, so treat them as separate actions. The documented command set describes these operations.
The CLI uses SSH to connect to a server remotely. Forge requires the forge user to authenticate with an SSH key before the CLI can connect. See Forge’s SSH key authentication instructions. forge ssh:test checks the SSH configuration, and forge ssh:configure accepts --key and --name options to add a public key. Keep the private key out of the agent prompt and configure access outside the prompt.
The CLI documentation describes command-line use. It does not document a JSON output mode or promise that every command runs unattended. Do not assume --json exists or rely on undocumented output formats. Check each command’s documented syntax before automating it, and have the agent summarize the output it receives rather than inventing a result.