— We consider a distributed system modeled as a possibly large network of automata. Planning in this system consists in selecting and organizing actions in order to reach a goal state in an optimal manner, assuming actions have a cost. To cope with the complexity of the system, we propose a distributed/modular planning approach. In each automaton or component, an agent explores local action plans that reach the local goal. The agents have to coordinate their search in order to select local plans that 1/ can be assembled into a valid global plan and 2/ ensure the optimality of this global plan. The proposed solution takes the form of a message passing algorithm, of peer-to-peer nature: no coordinator is needed. We show that local plan selections can be performed by combining operations on weighted languages, and then propose a more practical implementation in terms of weighted automata calculus.