### Run the applied agent from the shell
The whole hunk
from line 8, old and new numbered
/
lines
from line 8
88
99## Version-controlling API resources
1010
11You can use the CLI to version control API resources such as skills, agents, environments, or deployments as YAML files in your repository and keep them in sync with the Claude API.
11To keep agents, environments, and other Claude Managed Agents resources as files in your repository, see [Manage resources as code with ant apply](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/apply).
1212
13<Note>
14 For more information on these resources, see [Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview).
15</Note>
13### Run the applied agent from the shell
1614
17<Steps>
18 <Step title="Define your agent">
19 Write the agent definition to `summarizer.agent.yaml`:
15Once an agent and environment exist, you can drive a session from the shell:
2016
21 ```yaml summarizer.agent.yaml
22 name: Summarizer
23 model: claude-opus-5
24 system: |
25 You are a helpful assistant that writes concise summaries.
26 tools:
27 - type: agent_toolset_20260401
28 ```
29 </Step>
30
31 <Step title="Create the agent">
32 ```bash
33 ant beta:agents create < summarizer.agent.yaml
34 ```
35
36 ```json Output
37 {
38 "id": "agent_011CYm1BLqPXpQRk5khsSXrs",
39 "version": 1,
40 "name": "Summarizer",
41 "model": "claude-opus-5"
42 /* ... */
43 }
44 ```
45
46 Note the `id` from the response. You'll pass it to the session create command in a later step.
47
48 <Tip>
49 Check `summarizer.agent.yaml` into your repository and keep it in sync with the API in your CI pipeline. The update command needs the agent ID and current version as flags:
50
51 ```bash CLI
52 ant beta:agents update --agent-id agent_011CYm1BLqPXpQRk5khsSXrs --version 1 < summarizer.agent.yaml
53 ```
54 </Tip>
55 </Step>
56
57 <Step title="Define the environment">
58 A session runs in an [environment](https://platform.claude.com/docs/en/api/cli/beta/environments), which defines the sandbox it executes in. Write the environment definition to `summarizer.environment.yaml`:
59
60 ```yaml summarizer.environment.yaml
61 name: summarizer-env
62 config:
63 type: cloud
64 networking:
65 type: unrestricted
66 ```
67 </Step>
68
69 <Step title="Create the environment">
70 ```bash
71 ant beta:environments create < summarizer.environment.yaml
72 ```
73
74 ```json Output
75 {
76 "id": "env_01595EKxaaTTGwwY3kyXdtbs",
77 "name": "summarizer-env"
78 /* ... */
79 }
80 ```
81
82 Note the `id` from the response. You'll pass it to the session create command in a later step.
83
84 <Tip>
85 Check `summarizer.environment.yaml` into your repository and keep it in sync with the API in your CI pipeline. The update command needs the environment ID as a flag:
86
87 ```bash CLI
88 ant beta:environments update --environment-id env_01595EKxaaTTGwwY3kyXdtbs < summarizer.environment.yaml
89 ```
90 </Tip>
91 </Step>
92
17<Steps>
9318 <Step title="Start a session">
94 Paste the agent `id` and environment `id` from the previous outputs into the session create command:
19 Pass the agent and environment IDs to the session create command. After `ant apply`, read them from `claude-lock.json`: each entry under `resources` has an `id`, and for the project in [Manage resources as code with ant apply](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/apply) the entries are `./agents/summarizer.md` and `./environments/cloud.yaml`.
9520
9621 ```bash
9722 ant beta:sessions create \
from line 45
12045 </Step>
12146
12247 <Step title="Read the conversation">
123 `--transform` runs against each listed event, so this prints the text of every message in order. `--format auto` overrides the interactive explorer that list commands open by default in a terminal:
48 Once the agent has replied, list the events. `--transform` runs against each listed event, so this prints the text of every message in order. `--format auto` overrides the interactive explorer that list commands open by default in a terminal:
12449
12550 ```bash
12651 ant beta:sessions:events list \
12752 --session-id session_01JZCh78XvmxJjiXVy3oSi7K \
128 --transform 'content.0.text' --format auto --raw-output
53 --transform 'content.0.text' \
54 --raw-output \
55 --format auto
12956 ```
13057
13158 ```text Output wrap
from line 61
13461 ```
13562
13663 <Tip>
137 To watch a session as it runs, use `ant beta:sessions:events stream --session-id session_01JZCh78XvmxJjiXVy3oSi7K`. Events are written to stdout as they arrive.
64 To watch a session as it runs, use `ant beta:sessions:events stream --session-id session_01JZCh78XvmxJjiXVy3oSi7K --format jsonl`, which writes each event to stdout as it arrives. Without `--format`, a terminal opens the interactive explorer instead.
13865 </Tip>
13966 </Step>
14067</Steps>