# Subagents on other accounts

> ccam agent runs part of a Claude Code task as another of your accounts and returns Claude's reply, so one long task uses the usage of several accounts.

Source: https://ccam.dev/en/features/agent/ · Updated 2026-12-04

Claude Code's own subagents run as the account of the session that starts them, so they spend that account's usage. `ccam agent "<task>"` runs a task with `claude -p` in the same folder as another of your accounts and prints Claude's last reply. Called from a Claude Code session, it works like a subagent that spends another account's usage, so one long task can go on after the session's own account would have run out.

## Usage

Claude Code runs it through its Bash tool. With the [ccam plugin](https://ccam.dev/en/docs/install.md#claude-code-plugin) installed, ask for it in plain words, for example "use my other accounts for the parts of this task", or put that in your CLAUDE.md. The plugin's skill tells Claude Code to start each agent in the background, to write a task that stands alone, and to give agents that edit files their own part or git worktree.

### Giving an agent a task

```sh
ccam agent "find why TestParse fails and fix it; reply with what you changed"
ccam agent --json < task.md
```

`ccam agent "<task>"` runs the task with `claude -p` in this folder as another account and waits until it finishes. The words after the options are joined into one task; when there are none, ccam reads the task from standard input, as in the second line. Claude's last reply goes to standard output, and the lines that start with `ccam:` go to standard error and name the account and the session:

```console
$ ccam agent "summarize what internal/usage does"
ccam: agent runs as work (12% of its 5 hours used); session 7f3c9a2e-5b1d-4c2a-9e8f-1a2b3c4d5e6f
internal/usage looks up the 5-hour and weekly usage of every account …
ccam: agent finished as work; follow up with: ccam agent --resume 7f3c9a2e-5b1d-4c2a-9e8f-1a2b3c4d5e6f "…"
```

`--json` prints `{account, session_id, result, is_error, accounts}` instead, where `accounts` lists every account the task ran as.

Exit codes: claude's own (`0` when the agent finished), `75` (`EX_TEMPFAIL`) when no account other than the caller has room, `1` for other errors such as an agent trying to start another.

**Team and Enterprise seats.** `ccam agent` chooses the account by itself. Within one Claude Team or Enterprise organization it runs the task on another seat, which may violate Anthropic's terms. Read the [FAQ](https://ccam.dev/en/docs/faq.md#am-i-allowed-to-use-several-claude-code-accounts) and check with your organization and Anthropic before you rely on it.

### Choosing the model

```sh
ccam agent --model opus -- "-v breaks the parser: find out why"
```

`--model` sets the model the agent runs with, and that model's weekly window then counts in the choice of account too. Without it, the agent uses the account's default model. Put the task after `--` when it starts with `-`, so ccam does not read it as an option.

### Following up

```sh
ccam agent --resume 7f3c9a2e-… "now add a test for it"
```

`--resume <id>` continues an earlier agent's conversation with a follow-up task. The id is the session named on the agent's first and last `ccam:` lines. ccam runs the follow-up in the folder the agent ran in, as the account that ran it when that one still has room, otherwise as another ([How it works](#how-it-works), step 5).

### Changing which account runs it

```sh
ccam agent --strategy expiring "…"
ccam agent --wait=1h "…"
```

`ccam agent` picks the account the way [`ccam pick`](https://ccam.dev/en/features/pick.md) does and takes the same options:

- `--max-usage <1-100>`: accounts below this usage come first. Without it, `auto_max_usage` applies, otherwise 100.
- `--strategy headroom|expiring|balance`: the [choice rule](https://ccam.dev/en/docs/account-selection.md#choosing-by-usage). Without it, `auto_strategy` applies, otherwise `headroom`.
- `--cross-org`: also run as accounts of other organizations. Without it, `cross_org` decides, and it is off unless you set it.
- `--wait[=<duration>]`: when no account has room, wait for the first one to reset instead of exiting with code 75, at most 5 hours or as long as you give after `=`, as in the second line.

### Previewing the choice

```sh
ccam --dry-run agent "…"
```

`--dry-run` prints the account ccam would choose and the command it would run, without running it.

### Running a whole plan on other accounts

The ccam plugin's skill `/ccam:agent-driven-development` runs an implementation plan the way superpowers' subagent-driven development does, with an implementer for each task, a review after each task and a broad review at the end, but starts every one of them with `ccam agent`, so the plan's usage is spread over your other accounts instead of the session's own. To fix what a review finds, it follows the same agent up with `--resume`, so the agent keeps its conversation. When no account has room (exit code 75), it does that one job with the session's own subagent instead. Install the plugin as described in [Claude Code plugin](https://ccam.dev/en/docs/install.md#claude-code-plugin), or run `/plugin update` if you already have it.

### Watching agents

```sh
ccam agent --list
ccam agent --list --session "$CLAUDE_CODE_SESSION_ID"
ccam agent --list --json
```

`ccam agent --list` shows the agents of the last 24 hours, and any that is still running however long ago it started, newest first: the account, the state, when it started and its task, which is the first line of the task you gave, cut to 80 characters.

```console
$ ccam agent --list
Account  State    Started  Task
work     running  3m ago   Task 4: add the --list flag to ccam agent
work     running  8m ago   Review task 3: spec compliance and code quality
side     moved    12m ago  Review task 3: spec compliance and code quality → work
side     done     42m ago  Task 3: record the title and the caller session
work     failed   1h ago   Task 2: print the agent state in a table
```

The states are:

- `running`: the agent is working.
- `waiting`: its account reached the usage limit and no other has room, so it waits for one to reset (`--wait`).
- `done`: it finished.
- `failed`: it ended with an error, or no account was left to go on as.
- `moved`: its account reached the usage limit and the conversation went on as another account. The task column ends in `→ <account>`, and the run that goes on is a row of its own, as the second `work` row above.
- `stopped`: the run was interrupted, or its `ccam agent` was killed.

`--session <id>` limits the list to the agents that Claude Code session started, however long ago, and can be given more than once; `$CLAUDE_CODE_SESSION_ID` is the id of the session that runs the command. It prints `No agents for this session.` when there are none, and without `--session`, `No agents in the last 24 hours.` `--json` prints a list of objects (`[]` when there are none) with the keys `session_id`, `account`, `caller`, `caller_session`, `title`, `cwd`, `state`, `moved_to`, `started_at` and `ended_at` (empty while the agent runs or waits, or when it was killed):

```json
[
  {
    "session_id": "7f3c9a2e-5b1d-4c2a-9e8f-1a2b3c4d5e6f",
    "account": "work",
    "caller": "main",
    "caller_session": "c0ffee00-1111-4222-8333-444455556666",
    "title": "Task 4: add the --list flag to ccam agent",
    "cwd": "/home/me/project",
    "state": "running",
    "moved_to": "",
    "started_at": "2026-12-05T00:27:10Z",
    "ended_at": ""
  }
]
```

Inside Claude Code, the `ccam-agents` plugin shows the same list for this session in a pane beside the conversation and the number of running agents in the status line; see [Agents pane](https://ccam.dev/en/docs/install.md#agents-pane).

## How it works

1. **The caller is left out.** The account `ccam agent` is called from (the one of the session ccam started, else the one whose folder `CLAUDE_CONFIG_DIR` names, else the one this folder starts) never runs the agent, nor does another folder logged in to the same Claude account, which shares its limits. The agent stays in the caller's [organization](https://ccam.dev/en/docs/account-selection.md#staying-in-one-organization) unless `--cross-org` says otherwise.
2. **It picks like `ccam pick`.** Usage is looked up the way [`ccam pick`](https://ccam.dev/en/features/pick.md) does, and agents started within 2 minutes of each other get different accounts while enough have room.
3. **It runs with the session's permissions, never more.** Nobody is there to allow a tool in `claude -p`, so the agent gets the permission mode and effort of the session that called it. Run from a terminal, Claude Code's default mode and your settings' permission rules apply. `ccam agent` has no option that grants more.
4. **At a usage limit, the conversation moves on.** When the agent's account reaches its limit, ccam records the limit as the [plugin hook](https://ccam.dev/en/features/usage.md#the-limit-record) would and continues the same conversation as the account with the most room: Claude Code copies it there (`--resume <file> --fork-session`), with the first message "Your usage limit was reached and ccam moved this conversation to another account. Continue the task you were working on when the limit was reached; do not repeat work that is already complete." Each account is tried once.
5. **Every agent conversation is recorded** in `~/.local/state/ccam/agent/<session id>.json` (30 days): the account, the folder, the task's title, the account and Claude Code session that called it, its state, and when it started and ended. While the agent runs, its `ccam agent` holds a lock file, `<session id>.lock`, next to the record; that is how `--list` tells a running agent from one that was killed, and it does not read the agent's output. `--resume <id>` continues the conversation in its folder, as the account that ran it when that one still has room, otherwise as another. [`ccam next --continue`](https://ccam.dev/en/features/next.md) leaves agent conversations out, so it keeps continuing yours.

## Safety and edge cases

- An agent cannot start agents of its own: ccam marks it with `CCAM_AGENT=1`, and `ccam agent` refuses to run there.
- Stopping `ccam agent` (Ctrl+C, a signal, or Claude Code interrupting the command) stops the agent too.
- The agent does not see the conversation that called it, only its task.
- Agents that edit the same files at once overwrite each other's work. Give each its own part of the task, or its own git worktree.
- When the calling session moves to another account ([`auto_switch`](https://ccam.dev/en/features/auto-switch.md)), the agents it started stop with it. Their conversations remain: `--resume <id>` continues them.
- `agent` is a command name, so no new account can be called `agent`; an existing one still starts with `ccam run agent`.

## Related

- [How ccam picks an account](https://ccam.dev/en/docs/account-selection.md)
- [Picking an account for scripts](https://ccam.dev/en/features/pick.md)
- [Continuing at the limit](https://ccam.dev/en/features/next.md)
- [Background sessions of every account](https://ccam.dev/en/features/agents.md)
