MCmidnight-coderlocal coding agent

Tokens and conversation state

Manage AI coding context

Keep long coding sessions useful by controlling the model context window, compaction, and persistent thread history.

AI context management decides which instructions, messages, files, and tool results fit into a model request. Midnight Coder makes the limit and compaction workflow explicit with commands such as /context and /compact.

What is a context window?

A context window is the maximum amount of tokenized input and output a model can consider in one inference cycle. Coding agents fill it with system instructions, conversation history, repository excerpts, tool calls, and tool results.

A larger window can retain more evidence, but capacity alone does not guarantee better answers. Irrelevant history can dilute the current task and local models may require substantially more RAM or VRAM at larger context sizes.

Midnight Coder context commands

/context
/smartcontext
/mini-model
/resume-type
/new
/clear
/compact
  • /context sets the maximum window before automatic compaction.
  • /smartcontext toggles model-aware Ollama context sizing.
  • /mini-model selects the model used for compaction.
  • /resume-type controls the compaction strategy.
  • /compact trims a long conversation deliberately.
  • /new opens another chat; /clear starts fresh.

Threads, turns, and items

ThreadA persistent conversation container
TurnOne agent run from input through output
ItemAn atomic message, tool event, or result
CompactionA shorter representation of older history

Persistent structure lets a client resume or fork work without treating the visible chat transcript as the only source of state.

Practical context strategy

  1. Start a new thread for a materially different objective.
  2. Keep the active request specific so retrieved files stay relevant.
  3. Compact after a completed milestone, not in the middle of unresolved debugging.
  4. Use smart context when Ollama should receive the active model's native window.
  5. Resume a saved thread only when its prior decisions still matter.

Learn related terminology in the AI coding glossary.

Primary source: Midnight Coder README.

Keep coding context explicit

Use Midnight Coder's context, compaction, resume, and thread controls.

Explore Midnight CoderAgent workflow