# How to: Game music loops

> A menu theme or level loop that repeats without a click or a gap, as an Ogg and a WAV in your repo.

## When to use it

Background music for a game, a menu screen or a product video, with or without lyrics. Code can synthesise a loop,
and in our test Claude Code's own numpy track looped perfectly, but it sounded like programmer synth music. A model
gives you a produced-sounding track; the loop step makes it repeat cleanly.

## What to ask your agent

> Make a 30-second cozy adventure loop for the menu screen: instrumental, warm acoustic guitar, flute, 100 bpm.

## What your agent sends

Claude Code calls [`vvgen_generate_music`](https://vincevangen.com/docs/tools.md#vvgen_generate_music). This is the prompt from our test, with
`bpm` and `loop` added (the loop option did not exist yet when we ran it):

```json
{
  "prompt": "cozy instrumental adventure game loop, warm acoustic guitar, pizzicato strings, soft flute melody, light hand percussion, gentle and hopeful, 100 bpm, C major",
  "instrumental": true,
  "duration": 30,
  "bpm": 100,
  "loop": true,
  "wait_seconds": 50
}
```

Music runs as a job. With `wait_seconds` a little longer than the track, the result usually comes back in the same
call; our 30-second track took about 20 seconds. Otherwise the agent polls [`vvgen_get_job`](https://vincevangen.com/docs/tools.md#vvgen_get_job).

`loop: true` cuts the track to whole bars (set `bpm` so the bars are exact), crossfades the end into the start and
keeps the peak under -1 dBTP at the same loudness. The words "seamless loop" in the prompt do nothing on their own.

## What comes back

The track as an MP3, plus `.loop.ogg` and `.loop.wav` beside it. Use the Ogg or the WAV in the game: an MP3 adds a
short silence at the start when it's encoded, which you hear on every repeat. The result carries the length and a
waveform picture, never the audio itself, so the agent can't listen: play it yourself before it ships.

The free checks measure what the loop step fixed. On the track above, before: the jump at the wrap was 28.4 times the
average step between samples, with 1.43 s of near-silence at the end. After: 0.07 times, no silent tail, peak -1.41
dBTP, loudness unchanged.

Tips from the playbook your agent carries:

- Draft at 30 seconds and pick by ear. The model ignores `seed`, so every take is a new piece and a take can't be
  re-rendered longer. Keep the one you like.
- Name the instruments, tempo and key. "Children's" tends to add a glockenspiel.
- If a track sounds thin, muddy or harsh, the agent repeats the same call with `"post": ["polish"]`. The cached track
  is reused and only the free processing runs.

## In Cursor and Codex

Same tool, same arguments: see the [Cursor](https://vincevangen.com/docs/quickstart/cursor.md) and [Codex](https://vincevangen.com/docs/quickstart/codex.md) quickstarts.

## Results

- As generated: 30 s, ACE-Step 1.5 XL, from our test run on 12 October 2026. It fades out over its last seconds, so played on repeat it dips and clicks at the wrap. Audio: https://vincevangen.com/how-to/music-raw.mp3
- The same track after the free loop step (run on 15 October 2026): 10 whole bars at 100 bpm, 24 s, the wrap crossfaded. The player repeats it, so listen across the join. Audio: https://vincevangen.com/how-to/music-loop.ogg

## Cost

- A 30-second track: 8 credits ($0.08)
- A one-minute track: 15 credits ($0.15)
- The loop step and its checks: 0 credits
